From c40afac26168795a4b18a4e0a809239c5daf3679 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 7 Feb 2024 18:50:34 +0200 Subject: radicle_node: restore backup, make connections persistent Signed-off-by: Lars Wirzenius Sponsored-by: author --- roles/radicle_node/tasks/main.yml | 103 +++++++++++++++++++++++++++++++------- 1 file changed, 85 insertions(+), 18 deletions(-) diff --git a/roles/radicle_node/tasks/main.yml b/roles/radicle_node/tasks/main.yml index 5adaf18..7752060 100644 --- a/roles/radicle_node/tasks/main.yml +++ b/roles/radicle_node/tasks/main.yml @@ -27,6 +27,41 @@ # Rsync for backups. - rsync +- name: "stop Radicle node if running" + shell: | + systemctl stop radicle-node || true + +- name: "create directory for Radicle" + file: + state: directory + path: /home/_rad/.radicle + owner: _rad + group: _rad + mode: 0755 + +- name: "create directory for Radicle backup" + file: + state: directory + path: radicle-backup + owner: debian + group: debian + mode: 0755 + +- name: "restore .radicle directory from backup (step 1 or 2)" + when: radicle_node_backup is defined + synchronize: + src: "{{ radicle_node_backup }}/." + dest: radicle-backup/. + group: no + owner: no + +- name: "restore .radicle directory from backup (step 2 or 2)" + when: radicle_node_backup is defined + shell: | + rm radicle-backup/node/control.sock + rsync -a --del radicle-backup/. /home/_rad/.radicle/. + chown -R _rad:_rad /home/_rad/.radicle/. + - name: "create directory for Radicle keys" file: state: directory @@ -73,7 +108,7 @@ ExecStart=/home/_rad/.radicle/bin/radicle-node --listen 0.0.0.0:8776 Environment=RAD_HOME=/home/_rad/.radicle KillMode=process - Restart=never + Restart=on-failure RestartSec=1 User=_rad Group=_rad @@ -82,21 +117,46 @@ WantedBy=default.target dest: /lib/systemd/system/radicle-node.service -- name: "start systemd unit for Radicle node" - systemd: - name: radicle-node - state: restarted - masked: no - enabled: yes - daemon_reload: yes - -# Ansible does not seem to always actually start the unit, so do -# it manually. This seems to only happen on the first run on a -# freshly created host. -- name: "actually start node" - shell: | - systemctl restart radicle-node - systemctl status radicle-node +# # Ansible does not seem to always actually start the unit, so do +# # it manually. This seems to only happen on the first run on a +# # freshly created host. +# - name: "actually start node" +# shell: | +# systemctl restart radicle-node +# if [ "$(systemctl is-active radicle-node)" != active ]; then +# systemctl status radicle-node +# false +# fi + +- name: "install script to add nodes to connect to the Radicle config file" + when: radicle_node_connections is defined + copy: + content: | + #!/usr/bin/python3 + + import json, os, subprocess, sys + + p = subprocess.run(["rad", "config", "show"], check=True, capture_output=True) + if p.returncode != 0: + sys.exit("rad config show failed") + config = json.loads(p.stdout.decode()) + nodes = config["node"]["connect"] + for new in sys.argv[1:]: + if new not in nodes: + nodes.append(new) + + p = subprocess.run(["rad", "self", "--home"], check=True, capture_output=True) + if p.returncode != 0: + sys.exit("rad self --home failed") + + home = p.stdout.decode().strip() + filename = os.path.join(home, "config.json") + if os.path.exists(filename): + os.rename(filename, filename + ".bak") + with open(filename, "w") as f: + f.write(json.dumps(config, indent=4)) + dest: radicle-perma-connect + mode: 0755 - name: "connect to other Radicle nodes" when: radicle_node_connections is defined @@ -104,11 +164,18 @@ shell: | cat <<'EOF' > connect.sh export PATH="$HOME/.radicle/bin:$PATH" - rad node status - rad node connect "{{ item.nid }}@{{ item.host }}:{{ item.port }}" + ./radicle-perma-connect "{{ item.nid }}@{{ item.host }}:{{ item.port }}" EOF sudo -u _rad bash -ex connect.sh +- name: "(re)start systemd unit for Radicle node" + systemd: + name: radicle-node + state: restarted + masked: no + enabled: yes + daemon_reload: yes + - name: "seed Radicle repositories" when: radicle_node_repositories is defined with_items: "{{ radicle_node_repositories }}" -- cgit v1.2.1