Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more checks #2

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions roles/vega_core/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
vega_core_run_network: false

vega_core_with_unsafe_reset_all: false

vega_core_chain_id: ""
vega_core_external_endpoint: ""
# vega version used only once for genesis version in the vegavisor and for the maintenance stuff (/usr/local/bin/vega)
Expand Down
7 changes: 7 additions & 0 deletions roles/vega_core/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---
- name: Stop services
ansible.builtin.import_tasks: stop-services.yaml

- name: Prepare system
ansible.builtin.import_tasks: prepare-system.yaml

Expand All @@ -11,5 +14,9 @@
- name: Prepare node configuration
ansible.builtin.import_tasks: configuration.yaml

- name: Unsafe reset all
ansible.builtin.import_tasks: unsafe-reset-all.yaml
when: vega_core_with_unsafe_reset_all

- name: Start network
ansible.builtin.import_tasks: start_network.yaml
13 changes: 12 additions & 1 deletion roles/vega_core/tasks/start_network.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
---
# this step will run only once after the flag `vega_core_run_network` is flipped. Next restarts must be done manually
- name: Create passphrase file
- name: Decide whether restart node(when the vega_core_run_network flag changed)
ansible.builtin.copy:
dest: "/home/vega/.restart_flag"
content: "{{- vega_core_run_network -}}"
owner: vega
group: vega
mode: "0644"
register: visor_state
notify:
- "Restart vegavisor"

- name: Decide whether restart explorer(when the vega_core_run_network flag changed)
ansible.builtin.copy:
dest: "/home/vega/.restart_flag"
content: "{{- vega_core_run_network -}}"
owner: vega
group: vega
mode: "0644"
when: visor_state.changed and vega_core_with_block_explorer
notify:
- "Restart block-explorer"
17 changes: 17 additions & 0 deletions roles/vega_core/tasks/stop-services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
# This pipeline can be destructive for the network. Run it with an increased attention
- name: Check local services
ansible.builtin.service_facts:

- name: Stop vegavisor service if needed
when:
- "'vegavisor.service' in services" # don't stop if the service does not exist
block:
- name: Stop vegavisor service
ansible.builtin.systemd:
name: vegavisor
state: stopped

- name: Sleep after stopping vegavisor
ansible.builtin.wait_for:
timeout: 10 # seconds
47 changes: 47 additions & 0 deletions roles/vega_core/tasks/unsafe-reset-all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
- name: Unsafe reset all for the vega-core & tendermint
changed_when: true # always impact the node
become: true
become_user: vega
ansible.builtin.shell: |
set -o pipefail
/home/vega/vegavisor_home/current/vega unsafe_reset_all --home /home/vega/vega_home
/home/vega/vegavisor_home/current/vega tm unsafe_reset_all --home /home/vega/tendermint_home
args:
executable: /bin/bash

- name: Unsafe reset all for data node
changed_when: true # always impact the node
become: true
become_user: vega
ansible.builtin.shell: |
set -o pipefail

/home/vega/vegavisor_home/current/vega datanode unsafe_reset_all --home /home/vega/vega_home
args:
executable: /bin/bash
when: vega_core_with_data_node

- name: Delete postgresql databases for vega and
become: true
become_user: postgres
when: vega_core_with_data_node
community.postgresql.postgresql_db:
name: "{{ item }}"
port: "5432"
state: absent
with_items:
- vega
- tendermint

- name: Recreate postgresql databases for vega and
become: true
become_user: postgres
when: vega_core_with_data_node
community.postgresql.postgresql_db:
name: "{{ item }}"
port: "5432"
state: present
with_items:
- vega
- tendermint
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ indexer = "{{'psql' if vega_core_with_block_explorer else 'kv'}}" # TODO(think a
# The PostgreSQL connection configuration, the connection format:
# postgresql://<user>:<password>@<host>:<port>/<db>?<opts>
{% if vega_core_with_block_explorer %}
psql-conn = "postgresql://tendermint:tendermitn@127.0.0.1:5432/tendermint?sslmode=disable"
psql-conn = "postgresql://tendermint:tendermint@127.0.0.1:5432/tendermint?sslmode=disable"
{% else %}
psql-conn = ""
{% endif %}
Expand Down
5 changes: 2 additions & 3 deletions roles/vega_postgresql/tasks/configure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

- name: Configure | Check if data already migrated
ansible.builtin.stat:
path: '/.vega_postgresql_data_directory_migrated'
path: "{{- vega_postgresql_external_data_directory -}}/main"
register: directory_data_migrated

- name: Configure | Migrate previous home
Expand All @@ -55,9 +55,8 @@
chown -R postgres:postgres "{{- vega_postgresql_external_data_directory -}}";
find "{{- vega_postgresql_external_data_directory -}}" -type d ! -perm 0750 -exec chmod 0750 {} \;
find "{{- vega_postgresql_external_data_directory -}}" -type f ! -perm 0640 -exec chmod 0640 {} \;
touch "/.vega_postgresql_data_directory_migrated";
args:
creates: "/.vega_postgresql_data_directory_migrated"
creates: "{{- vega_postgresql_external_data_directory -}}/main"
executable: /bin/bash
register: migrate_psql_home
notify: "Restart postgresql"
Expand Down