Skip to content

Commit

Permalink
add support_sync_snapshot playbook
Browse files Browse the repository at this point in the history
  • Loading branch information
PolkachuIntern committed Jun 28, 2023
1 parent e18b8f0 commit 2d66274
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ ansible-playbook main.yml -e "target=HOST_NAME"
| `support_tenderduty.yml` | Install Tenderduty |
| `support_price_feeder.yml` | Install price feeders for selected networks (such Umee, Kujira, etc) |
| `support_scripts.yml` | Install scripts to make node operations easier |
| `support_sync_snapshot.yml` | Sync node from a snapshot |
| `support_remove_node.yml` | Remove a node and clean up |

### Selected playbook Usage Example

Expand Down
3 changes: 3 additions & 0 deletions group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ go_version: '1.20.3'

# cosmovisor
cosmovisor_version: 'v1.0.0'

# Snapshot base URL
snapshot_base_url: 'https://polkachu.com/api/v1/chains'
13 changes: 13 additions & 0 deletions roles/support_remove_node/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: placeholder
debug:
msg: 'hello world'
# wget -O aura_1530150.tar.lz4 https://snapshots.polkachu.com/snapshots/aura/aura_1530150.tar.lz4 --inet4-only

# sudo service aura stop

# aurad tendermint unsafe-reset-all --home $HOME/.aura --keep-addr-book

# lz4 -c -d aura_1530150.tar.lz4 | tar -x -C $HOME/.aura

# sudo service aura start
56 changes: 56 additions & 0 deletions roles/support_sync_snapshot/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
- name: Stop node process
become: true
systemd:
name: '{{ network }}'
state: stopped
daemon_reload: yes
enabled: yes

- name: Move priv_validator_state.json to a safe location
command: 'mv {{ user_dir }}/{{ folder }}/data/priv_validator_state.json {{ user_dir }}/{{ folder }}'

- name: Get the latest snapshot url
uri:
url: '{{ snapshot_base_url }}/{{ network }}/snapshot'
headers:
x-polkachu: '{{ snapshot_secret }}'
register: snapshot

- name: Download snapshot to home folder
get_url:
url: '{{ snapshot.json.snapshot.url }}'
dest: '{{ user_dir }}/{{ snapshot.json.snapshot.name }}'
mode: '0644'

- name: Unsafe reset
shell: '{{ user_dir }}/go/bin/{{ daemon }} tendermint unsafe-reset-all --home $HOME/{{ folder }} --keep-addr-book'

- name: Extract snapshot
shell: 'lz4 -c -d $HOME/{{ snapshot.json.snapshot.name }} | tar -x -C $HOME/{{ folder }}'

- name: Move priv_validator_state.json back
command: 'mv {{ user_dir }}/{{ folder }}/priv_validator_state.json {{ user_dir }}/{{ folder }}/data/'

- name: Delete the downloaded snapshot file
file:
path: '{{ user_dir }}/{{ snapshot.json.snapshot.name }}'
state: absent

- name: start node process
become: true
systemd:
name: '{{ network }}'
state: started
daemon_reload: yes
enabled: yes

- name: Pause for 5 seconds
pause:
seconds: 5

- name: Ensure it is running
uri:
url: 'http://localhost:{{ custom_port_prefix }}61'
method: GET
status_code: 200
8 changes: 8 additions & 0 deletions support_remove_node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Remove a node and clean up
hosts: '{{ target }}'
gather_facts: false
vars_files:
- '{{ var_file }}'
roles:
- support_remove_node
8 changes: 8 additions & 0 deletions support_sync_snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Sync node from a snapshot
hosts: '{{ target }}'
gather_facts: false
vars_files:
- '{{ var_file }}'
roles:
- support_sync_snapshot

0 comments on commit 2d66274

Please sign in to comment.