From 1984be7db8dde5c1e623fe0b9485445788053efc Mon Sep 17 00:00:00 2001
From: phahulin
Date: Mon, 8 Jan 2018 21:39:55 +0300
Subject: [PATCH] Add role to do HF on spec changes
---
group_vars/all.example | 4 ++++
hosts.example | 3 +++
roles/hf-spec-change/tasks/main.yml | 23 +++++++++++++++++++++++
site.yml | 9 +++++++++
4 files changed, 39 insertions(+)
create mode 100644 roles/hf-spec-change/tasks/main.yml
diff --git a/group_vars/all.example b/group_vars/all.example
index 4208a08..5842d72 100644
--- a/group_vars/all.example
+++ b/group_vars/all.example
@@ -6,3 +6,7 @@ access_key: "KEY_NAME"
secret_key: "KEY_SECRET"
s3_bucket: "BUCKET_NAME"
+
+#For HFs
+MAIN_REPO_FETCH: "poanetwork"
+GENESIS_BRANCH: "sokol"
diff --git a/hosts.example b/hosts.example
index 487d9dc..ed04adf 100644
--- a/hosts.example
+++ b/hosts.example
@@ -1,2 +1,5 @@
[backup]
INSERT_HERE_SERVERS_HOSTNAME_OR_IPs
+
+[hf-spec-change]
+INSERT_HERE_SERVERS_HOSTNAME_OR_IPs
diff --git a/roles/hf-spec-change/tasks/main.yml b/roles/hf-spec-change/tasks/main.yml
new file mode 100644
index 0000000..2d04449
--- /dev/null
+++ b/roles/hf-spec-change/tasks/main.yml
@@ -0,0 +1,23 @@
+---
+- name: Shutdown poa-netstats service
+ service: name=poa-netstats state=stopped
+
+- name: Shutdown poa-parity service
+ service: name=poa-parity state=stopped
+
+- name: Create directory for spec backups
+ file: path={{ home }}/spec-hfs state=directory
+
+- name: Create previous spec backup
+ command: cp {{ home }}/spec.json {{ home }}/spec-hfs/spec-hf-{{ date }}.json
+
+- name: Download new spec
+ get_url: url={{ item }} dest={{ home }}/ mode=0644
+ with_items:
+ - "https://raw.githubusercontent.com/{{ MAIN_REPO_FETCH }}/poa-chain-spec/{{ GENESIS_BRANCH }}/spec.json"
+
+- name: Launch poa-parity service
+ service: name=poa-parity state=started
+
+- name: Launch poa-netstats service
+ service: name=poa-netstats state=started
diff --git a/site.yml b/site.yml
index 17ee158..6d481c0 100644
--- a/site.yml
+++ b/site.yml
@@ -5,3 +5,12 @@
roles:
- backup-parity
tags: backup
+
+- hosts: hf-spec-change
+ vars:
+ date: "{{ lookup('pipe', 'date -u +%Y%m%d-%H%M%S') }}"
+ home: "/home/{{ poa_role }}"
+ user: root
+ roles:
+ - hf-spec-change
+ tags: hf-spec