From b9fc3fef3ab2862a0e24572d153d96ac1c427220 Mon Sep 17 00:00:00 2001 From: Alexey Gladky Date: Fri, 23 Aug 2024 14:11:06 +0200 Subject: [PATCH 01/11] feat: add hychain service --- depin/services/roles/hychain/README.md | 38 ++++++++++++++++ .../services/roles/hychain/defaults/main.yml | 5 +++ .../roles/hychain/files/hychain.service | 15 +++++++ .../roles/hychain/tasks/commands/install.yml | 43 ++++++++++++++++++ .../roles/hychain/tasks/commands/restart.yml | 5 +++ .../roles/hychain/tasks/commands/start.yml | 5 +++ .../roles/hychain/tasks/commands/stop.yml | 5 +++ .../hychain/tasks/commands/uninstall.yml | 20 +++++++++ .../roles/hychain/tasks/commands/update.yml | 44 +++++++++++++++++++ depin/services/roles/hychain/tasks/main.yml | 5 +++ molecule/default/vars/hychain.yml | 4 ++ 11 files changed, 189 insertions(+) create mode 100644 depin/services/roles/hychain/README.md create mode 100644 depin/services/roles/hychain/defaults/main.yml create mode 100644 depin/services/roles/hychain/files/hychain.service create mode 100644 depin/services/roles/hychain/tasks/commands/install.yml create mode 100644 depin/services/roles/hychain/tasks/commands/restart.yml create mode 100644 depin/services/roles/hychain/tasks/commands/start.yml create mode 100644 depin/services/roles/hychain/tasks/commands/stop.yml create mode 100644 depin/services/roles/hychain/tasks/commands/uninstall.yml create mode 100644 depin/services/roles/hychain/tasks/commands/update.yml create mode 100644 depin/services/roles/hychain/tasks/main.yml create mode 100644 molecule/default/vars/hychain.yml diff --git a/depin/services/roles/hychain/README.md b/depin/services/roles/hychain/README.md new file mode 100644 index 00000000..225dd44b --- /dev/null +++ b/depin/services/roles/hychain/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/depin/services/roles/hychain/defaults/main.yml b/depin/services/roles/hychain/defaults/main.yml new file mode 100644 index 00000000..225abd54 --- /dev/null +++ b/depin/services/roles/hychain/defaults/main.yml @@ -0,0 +1,5 @@ +--- +hychain_version: 0.0.1 +hychain_code: "{{ notdefined | mandatory }}" + +hychain_mode: install` diff --git a/depin/services/roles/hychain/files/hychain.service b/depin/services/roles/hychain/files/hychain.service new file mode 100644 index 00000000..9f668b52 --- /dev/null +++ b/depin/services/roles/hychain/files/hychain.service @@ -0,0 +1,15 @@ +[Unit] +Description=hychain service +After=network.target + +[Service] +User=root +Group=root +Type=simple +ExecStart=/bin/bash /home/hychain/cli/linux/hychain-start.sh +Restart=always +RestartSec=5 +PIDFile=/tmp/hychain.pid + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/commands/install.yml b/depin/services/roles/hychain/tasks/commands/install.yml new file mode 100644 index 00000000..9b8bce9a --- /dev/null +++ b/depin/services/roles/hychain/tasks/commands/install.yml @@ -0,0 +1,43 @@ +--- +- name: Update&Upgrade + ansible.builtin.apt: + name: aptitude + state: present + update_cache: true + +- name: Install dependencies + ansible.builtin.apt: + name: + - git + state: present + update_cache: true + +- name: Clone a repo with separate git directory + ansible.builtin.git: + repo: https://github.com/HYCHAIN/guardian-node-software.git + dest: /home/hychain + single_branch: yes + version: main + +- name: Copy start file + ansible.builtin.copy: + content: | + #!/bin/bash + cd /home/hychain/cli/linux/ + ./guardian-cli-linux guardian run {{ hychain_code }} --loop-interval-ms 3600000 + dest: /home/hychain/cli/linux/hychain-start.sh + +- name: Hychain service file + ansible.builtin.copy: + src: ../files/hychain.service + dest: /etc/systemd/system/hychain.service + +- name: Enable service hychain.service + ansible.builtin.service: + name: hychain.service + enabled: yes + +- name: Start service hychain.service, if not started + ansible.builtin.service: + name: hychain.service + state: started \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/commands/restart.yml b/depin/services/roles/hychain/tasks/commands/restart.yml new file mode 100644 index 00000000..c0e9527a --- /dev/null +++ b/depin/services/roles/hychain/tasks/commands/restart.yml @@ -0,0 +1,5 @@ +--- +- name: Restarted node + ansible.builtin.service: + name: hychain.service + state: restarted \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/commands/start.yml b/depin/services/roles/hychain/tasks/commands/start.yml new file mode 100644 index 00000000..8daeaf1d --- /dev/null +++ b/depin/services/roles/hychain/tasks/commands/start.yml @@ -0,0 +1,5 @@ +--- +- name: Start node + ansible.builtin.service: + name: hychain.service + state: started \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/commands/stop.yml b/depin/services/roles/hychain/tasks/commands/stop.yml new file mode 100644 index 00000000..e6b5fa93 --- /dev/null +++ b/depin/services/roles/hychain/tasks/commands/stop.yml @@ -0,0 +1,5 @@ +--- +- name: Stop node + ansible.builtin.service: + name: hychain.service + state: stopped \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/commands/uninstall.yml b/depin/services/roles/hychain/tasks/commands/uninstall.yml new file mode 100644 index 00000000..50094cbd --- /dev/null +++ b/depin/services/roles/hychain/tasks/commands/uninstall.yml @@ -0,0 +1,20 @@ +--- +- name: Stop service hychain.service + ansible.builtin.service: + name: hychain.service + state: stopped + +- name: Disable service hychain.service + ansible.builtin.service: + name: hychain.service + enabled: false + +- name: Delete content & directory + ansible.builtin.file: + state: absent + path: /home/hychain + +- name: Delete hychain.service + ansible.builtin.file: + state: absent + path: /etc/systemd/system/hychain.service \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/commands/update.yml b/depin/services/roles/hychain/tasks/commands/update.yml new file mode 100644 index 00000000..d77a437e --- /dev/null +++ b/depin/services/roles/hychain/tasks/commands/update.yml @@ -0,0 +1,44 @@ +--- +- name: Stop service hychain.service + ansible.builtin.service: + name: hychain.service + state: stopped + +- name: Delete content & directory + ansible.builtin.file: + state: absent + path: /home/hychain + +- name: Delete hychain.service + ansible.builtin.file: + state: absent + path: /etc/systemd/system/hychain.service + +- name: Clone a repo with separate git directory + ansible.builtin.git: + repo: https://github.com/HYCHAIN/guardian-node-software.git + dest: /home/hychain + single_branch: yes + version: main + +- name: Hychain service file + ansible.builtin.copy: + src: hychain.service + dest: /etc/systemd/system/hychain.service + +- name: Copy start file + ansible.builtin.copy: + content: | + #!/bin/bash + cd /home/hychain/cli/linux/ + ./guardian-cli-linux guardian run {{ hychain_code }} --loop-interval-ms 3600000 + dest: /home/hychain/cli/linux/hychain-start.sh + +- name: Just force systemd to reread configs (2.4 and above) + ansible.builtin.systemd_service: + daemon_reload: true + +- name: Start service hychain.service, if not started + ansible.builtin.service: + name: hychain.service + state: started \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/main.yml b/depin/services/roles/hychain/tasks/main.yml new file mode 100644 index 00000000..6e6ddc54 --- /dev/null +++ b/depin/services/roles/hychain/tasks/main.yml @@ -0,0 +1,5 @@ +--- +- name: Hychain {{ hychain_mode }} + ansible.builtin.include_tasks: + file: commands/{{ hychain_mode }}.yml + diff --git a/molecule/default/vars/hychain.yml b/molecule/default/vars/hychain.yml new file mode 100644 index 00000000..0d1119da --- /dev/null +++ b/molecule/default/vars/hychain.yml @@ -0,0 +1,4 @@ +test_role: depin.services.hychain + +# override role variables +hychain_code: 0x64c077bf4de3b020f874e8a9384cbdd98dafeb49cc9e78f0996771f86c0c48e2 From 3e3241c7589d0f46bc1c3d18487b434982a5678d Mon Sep 17 00:00:00 2001 From: Alexey Gladky Date: Mon, 9 Sep 2024 16:53:26 +0200 Subject: [PATCH 02/11] Updates with hychain service --- .../services/roles/hychain/defaults/main.yml | 7 +- .../roles/hychain/files/hychain.service | 15 ---- .../services/roles/hychain/handlers/main.yml | 2 + .../roles/hychain/tasks/commands/install.yml | 90 +++++++++++++------ .../roles/hychain/tasks/commands/reset.yml | 9 ++ .../roles/hychain/tasks/commands/restart.yml | 1 + .../roles/hychain/tasks/commands/start.yml | 1 + .../roles/hychain/tasks/commands/stop.yml | 1 + .../hychain/tasks/commands/uninstall.yml | 19 ++-- .../roles/hychain/tasks/commands/update.yml | 48 ++-------- depin/services/roles/hychain/tasks/main.yml | 1 - .../hychain/templates/systemd.service.j2 | 12 +++ depin/services/roles/hychain/vars/main.yml | 9 ++ 13 files changed, 114 insertions(+), 101 deletions(-) delete mode 100644 depin/services/roles/hychain/files/hychain.service create mode 100644 depin/services/roles/hychain/handlers/main.yml create mode 100644 depin/services/roles/hychain/tasks/commands/reset.yml create mode 100644 depin/services/roles/hychain/templates/systemd.service.j2 create mode 100644 depin/services/roles/hychain/vars/main.yml diff --git a/depin/services/roles/hychain/defaults/main.yml b/depin/services/roles/hychain/defaults/main.yml index 225abd54..a883c9bb 100644 --- a/depin/services/roles/hychain/defaults/main.yml +++ b/depin/services/roles/hychain/defaults/main.yml @@ -1,5 +1,6 @@ --- +# defaults file for hychain hychain_version: 0.0.1 -hychain_code: "{{ notdefined | mandatory }}" - -hychain_mode: install` +hychain_private_key: "{{ notdefined | mandatory }}" +hychain_download_url: "https://github.com/HYCHAIN/guardian-node-software/archive/refs/heads/main.zip" +hychain_mode: install diff --git a/depin/services/roles/hychain/files/hychain.service b/depin/services/roles/hychain/files/hychain.service deleted file mode 100644 index 9f668b52..00000000 --- a/depin/services/roles/hychain/files/hychain.service +++ /dev/null @@ -1,15 +0,0 @@ -[Unit] -Description=hychain service -After=network.target - -[Service] -User=root -Group=root -Type=simple -ExecStart=/bin/bash /home/hychain/cli/linux/hychain-start.sh -Restart=always -RestartSec=5 -PIDFile=/tmp/hychain.pid - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/depin/services/roles/hychain/handlers/main.yml b/depin/services/roles/hychain/handlers/main.yml new file mode 100644 index 00000000..61e51c3d --- /dev/null +++ b/depin/services/roles/hychain/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for skeleton diff --git a/depin/services/roles/hychain/tasks/commands/install.yml b/depin/services/roles/hychain/tasks/commands/install.yml index 9b8bce9a..5d1b84d4 100644 --- a/depin/services/roles/hychain/tasks/commands/install.yml +++ b/depin/services/roles/hychain/tasks/commands/install.yml @@ -1,43 +1,79 @@ --- -- name: Update&Upgrade - ansible.builtin.apt: - name: aptitude - state: present - update_cache: true - +## install dependencies and start service +--- - name: Install dependencies ansible.builtin.apt: name: - - git + - zip state: present update_cache: true -- name: Clone a repo with separate git directory - ansible.builtin.git: - repo: https://github.com/HYCHAIN/guardian-node-software.git - dest: /home/hychain - single_branch: yes - version: main +- name: Create program folder + become: true + ansible.builtin.file: + state: directory + owner: root + group: root + mode: '0755' + dest: /opt/hychain/{{ hychain_version }} + +- name: Download binary to tmp + ansible.builtin.get_url: + url: "{{ hychain_download_url }}" + dest: /tmp/hychain_service_{{ hychain_version }}.zip + + +- name: Find binary + become: true + ansible.builtin.find: + paths: + - /tmp + - "{{ hychain_download_path | default('/tmp') }}" + patterns: 'hychain_service_{{ hychain_version }}.zip$' + use_regex: true + get_checksum: true + recurse: true + register: _download + +- name: Extract binary + become: true + ansible.builtin.unarchive: + src: /tmp/hychain_service_{{ hychain_version }}.zip + dest: /opt/hychain/{{ hychain_version }} + remote_src: yes - name: Copy start file ansible.builtin.copy: content: | #!/bin/bash - cd /home/hychain/cli/linux/ - ./guardian-cli-linux guardian run {{ hychain_code }} --loop-interval-ms 3600000 - dest: /home/hychain/cli/linux/hychain-start.sh + cd /opt/hychain/{{ hychain_version }}/guardian-node-software-main/cli/linux/ + ./guardian-cli-linux guardian run {{ hychain_private_key }} + dest: /opt/hychain/{{ hychain_version }}/guardian-node-software-main/cli/linux/hychain-start.sh -- name: Hychain service file +- name: Create systemd file ansible.builtin.copy: - src: ../files/hychain.service + content: | + [Unit] + Description=hychain service + After=network.target + + [Service] + User=root + Group=root + Type=simple + ExecStart=/bin/bash /opt/hychain/{{ hychain_version }}/guardian-node-software-main/cli/linux/hychain-start.sh + Restart=always + RestartSec=5 + RuntimeMaxSec=6h + PIDFile=/tmp/hychain.pid + + [Install] + WantedBy=multi-user.target dest: /etc/systemd/system/hychain.service - -- name: Enable service hychain.service - ansible.builtin.service: - name: hychain.service - enabled: yes - + - name: Start service hychain.service, if not started - ansible.builtin.service: - name: hychain.service - state: started \ No newline at end of file + ansible.builtin.systemd_service: + name: hychain + state: started + enabled: true + daemon_reload: true \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/commands/reset.yml b/depin/services/roles/hychain/tasks/commands/reset.yml new file mode 100644 index 00000000..b7af2305 --- /dev/null +++ b/depin/services/roles/hychain/tasks/commands/reset.yml @@ -0,0 +1,9 @@ +--- +## uninstall and install service +- name: Uninstall node + ansible.builtin.include_tasks: + file: commands/uninstall.yml + +- name: Install node + ansible.builtin.include_tasks: + file: commands/install.yml \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/commands/restart.yml b/depin/services/roles/hychain/tasks/commands/restart.yml index c0e9527a..c63271f0 100644 --- a/depin/services/roles/hychain/tasks/commands/restart.yml +++ b/depin/services/roles/hychain/tasks/commands/restart.yml @@ -1,4 +1,5 @@ --- +## stop and start service - name: Restarted node ansible.builtin.service: name: hychain.service diff --git a/depin/services/roles/hychain/tasks/commands/start.yml b/depin/services/roles/hychain/tasks/commands/start.yml index 8daeaf1d..aa11aaca 100644 --- a/depin/services/roles/hychain/tasks/commands/start.yml +++ b/depin/services/roles/hychain/tasks/commands/start.yml @@ -1,4 +1,5 @@ --- +## start service - name: Start node ansible.builtin.service: name: hychain.service diff --git a/depin/services/roles/hychain/tasks/commands/stop.yml b/depin/services/roles/hychain/tasks/commands/stop.yml index e6b5fa93..3fc753d1 100644 --- a/depin/services/roles/hychain/tasks/commands/stop.yml +++ b/depin/services/roles/hychain/tasks/commands/stop.yml @@ -1,4 +1,5 @@ --- +## stop service - name: Stop node ansible.builtin.service: name: hychain.service diff --git a/depin/services/roles/hychain/tasks/commands/uninstall.yml b/depin/services/roles/hychain/tasks/commands/uninstall.yml index 50094cbd..67ede722 100644 --- a/depin/services/roles/hychain/tasks/commands/uninstall.yml +++ b/depin/services/roles/hychain/tasks/commands/uninstall.yml @@ -1,20 +1,13 @@ --- -- name: Stop service hychain.service - ansible.builtin.service: - name: hychain.service +## stop and uninstall service (remove all associated files) +- name: Start service hychain.service, if not started + ansible.builtin.systemd_service: + name: hychain state: stopped - -- name: Disable service hychain.service - ansible.builtin.service: - name: hychain.service enabled: false + daemon_reload: true - name: Delete content & directory ansible.builtin.file: state: absent - path: /home/hychain - -- name: Delete hychain.service - ansible.builtin.file: - state: absent - path: /etc/systemd/system/hychain.service \ No newline at end of file + path: /opt/hychain \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/commands/update.yml b/depin/services/roles/hychain/tasks/commands/update.yml index d77a437e..50d55047 100644 --- a/depin/services/roles/hychain/tasks/commands/update.yml +++ b/depin/services/roles/hychain/tasks/commands/update.yml @@ -1,44 +1,8 @@ --- -- name: Stop service hychain.service - ansible.builtin.service: - name: hychain.service - state: stopped +- name: Uninstall node + ansible.builtin.include_tasks: + file: commands/uninstall.yml -- name: Delete content & directory - ansible.builtin.file: - state: absent - path: /home/hychain - -- name: Delete hychain.service - ansible.builtin.file: - state: absent - path: /etc/systemd/system/hychain.service - -- name: Clone a repo with separate git directory - ansible.builtin.git: - repo: https://github.com/HYCHAIN/guardian-node-software.git - dest: /home/hychain - single_branch: yes - version: main - -- name: Hychain service file - ansible.builtin.copy: - src: hychain.service - dest: /etc/systemd/system/hychain.service - -- name: Copy start file - ansible.builtin.copy: - content: | - #!/bin/bash - cd /home/hychain/cli/linux/ - ./guardian-cli-linux guardian run {{ hychain_code }} --loop-interval-ms 3600000 - dest: /home/hychain/cli/linux/hychain-start.sh - -- name: Just force systemd to reread configs (2.4 and above) - ansible.builtin.systemd_service: - daemon_reload: true - -- name: Start service hychain.service, if not started - ansible.builtin.service: - name: hychain.service - state: started \ No newline at end of file +- name: Install node + ansible.builtin.include_tasks: + file: commands/install.yml \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/main.yml b/depin/services/roles/hychain/tasks/main.yml index 6e6ddc54..8304a017 100644 --- a/depin/services/roles/hychain/tasks/main.yml +++ b/depin/services/roles/hychain/tasks/main.yml @@ -2,4 +2,3 @@ - name: Hychain {{ hychain_mode }} ansible.builtin.include_tasks: file: commands/{{ hychain_mode }}.yml - diff --git a/depin/services/roles/hychain/templates/systemd.service.j2 b/depin/services/roles/hychain/templates/systemd.service.j2 new file mode 100644 index 00000000..06649ceb --- /dev/null +++ b/depin/services/roles/hychain/templates/systemd.service.j2 @@ -0,0 +1,12 @@ +[Unit] +Description= +After=network-online.target +Wants=network.target + +[Service] +Type=simple +ExecStart= +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/depin/services/roles/hychain/vars/main.yml b/depin/services/roles/hychain/vars/main.yml new file mode 100644 index 00000000..131b70bb --- /dev/null +++ b/depin/services/roles/hychain/vars/main.yml @@ -0,0 +1,9 @@ +--- +deb_architecture: { # noqa var-naming[no-role-prefix] + "aarch64": "arm64", + "x86_64": "amd64", + "arm": "arm", + "i386": "386" +} + +system_architecture: "{{ [ansible_architecture] | map('extract', deb_architecture) | first }}" # noqa var-naming[no-role-prefix] From f732952e72bbd0aed8ab61fa7dcde850440a7ccd Mon Sep 17 00:00:00 2001 From: alex-klikatech <125446221+alex-klikatech@users.noreply.github.com> Date: Wed, 11 Sep 2024 12:41:07 +0200 Subject: [PATCH 03/11] Update install.yml --- depin/services/roles/hychain/tasks/commands/install.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/depin/services/roles/hychain/tasks/commands/install.yml b/depin/services/roles/hychain/tasks/commands/install.yml index 8d00caac..b3e95a62 100644 --- a/depin/services/roles/hychain/tasks/commands/install.yml +++ b/depin/services/roles/hychain/tasks/commands/install.yml @@ -1,6 +1,5 @@ --- ## install dependencies and start service ---- - name: Install dependencies ansible.builtin.apt: name: @@ -86,4 +85,4 @@ ansible.builtin.include_tasks: file: tasks/asserts_install.yml - # unique asserts go here \ No newline at end of file + # unique asserts go here From dc8c781507b4bc0bf7b2e34269889a8649babc97 Mon Sep 17 00:00:00 2001 From: Alexey Gladky Date: Wed, 11 Sep 2024 16:13:35 +0200 Subject: [PATCH 04/11] Update hychain service with molecule integration --- .../services/roles/hychain/defaults/main.yml | 2 +- .../roles/hychain/tasks/commands/install.yml | 21 +++++++------------ .../roles/hychain/tasks/commands/restart.yml | 1 + .../roles/hychain/tasks/commands/start.yml | 21 ++++++++++++++++++- .../roles/hychain/tasks/commands/stop.yml | 18 +++++++++++++++- .../hychain/tasks/commands/uninstall.yml | 4 +++- 6 files changed, 49 insertions(+), 18 deletions(-) diff --git a/depin/services/roles/hychain/defaults/main.yml b/depin/services/roles/hychain/defaults/main.yml index 155a4e23..898b1747 100644 --- a/depin/services/roles/hychain/defaults/main.yml +++ b/depin/services/roles/hychain/defaults/main.yml @@ -2,6 +2,6 @@ # defaults file for hychain hychain_cmd: install hychain_version: 0.0.1 -hychain_private_key: "{{ notdefined | mandatory }}" +hychain_private_key: "0x64c077bf4de3b020f874e8a9384cbdd98dafeb49cc9e78f0996771f86c0c48e2" hychain_download_url: "https://github.com/HYCHAIN/guardian-node-software/archive/refs/heads/main.zip" diff --git a/depin/services/roles/hychain/tasks/commands/install.yml b/depin/services/roles/hychain/tasks/commands/install.yml index 8d00caac..3e63acab 100644 --- a/depin/services/roles/hychain/tasks/commands/install.yml +++ b/depin/services/roles/hychain/tasks/commands/install.yml @@ -1,7 +1,7 @@ --- ## install dependencies and start service ---- - name: Install dependencies + become: true ansible.builtin.apt: name: - zip @@ -43,6 +43,7 @@ remote_src: yes - name: Copy start file + become: true ansible.builtin.copy: content: | #!/bin/bash @@ -51,6 +52,7 @@ dest: /opt/hychain/{{ hychain_version }}/guardian-node-software-main/cli/linux/hychain-start.sh - name: Create systemd file + become: true ansible.builtin.copy: content: | [Unit] @@ -71,19 +73,10 @@ WantedBy=multi-user.target dest: /etc/systemd/system/hychain.service -- name: Start service hychain.service, if not started - ansible.builtin.systemd_service: - name: hychain - state: started - enabled: true - daemon_reload: true - +- name: Start node + ansible.builtin.include_tasks: + file: commands/start.yml + # relative to playbook (molecule - default) -- name: Assert Install - when: "'molecule' in groups" - block: - - name: Common install asserts - ansible.builtin.include_tasks: - file: tasks/asserts_install.yml # unique asserts go here \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/commands/restart.yml b/depin/services/roles/hychain/tasks/commands/restart.yml index c63271f0..416fa528 100644 --- a/depin/services/roles/hychain/tasks/commands/restart.yml +++ b/depin/services/roles/hychain/tasks/commands/restart.yml @@ -1,6 +1,7 @@ --- ## stop and start service - name: Restarted node + become: true ansible.builtin.service: name: hychain.service state: restarted \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/commands/start.yml b/depin/services/roles/hychain/tasks/commands/start.yml index aa11aaca..fe93052c 100644 --- a/depin/services/roles/hychain/tasks/commands/start.yml +++ b/depin/services/roles/hychain/tasks/commands/start.yml @@ -1,6 +1,25 @@ --- ## start service - name: Start node + become: true ansible.builtin.service: name: hychain.service - state: started \ No newline at end of file + state: started + +- name: Assert + when: "'molecule' in groups" + block: + - name: Get service info + become: true + ansible.builtin.systemd: + name: "hychain" + register: _hychain + + - debug: + var: _hychain.status.ActiveState + + - name: Check service + ansible.builtin.assert: + that: + - _hychain['status']['ActiveState']=='active' + quiet: true \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/commands/stop.yml b/depin/services/roles/hychain/tasks/commands/stop.yml index 3fc753d1..e2a86154 100644 --- a/depin/services/roles/hychain/tasks/commands/stop.yml +++ b/depin/services/roles/hychain/tasks/commands/stop.yml @@ -1,6 +1,22 @@ --- ## stop service - name: Stop node + become: true ansible.builtin.service: name: hychain.service - state: stopped \ No newline at end of file + state: stopped + +- name: Assert + when: "'molecule' in groups" + block: + - name: Get service info + become: true + ansible.builtin.systemd: + name: "hychain" + register: _hychain + + - name: Check service + ansible.builtin.assert: + that: + - _hychain['status']['ActiveState']=='inactive' + quiet: true \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/commands/uninstall.yml b/depin/services/roles/hychain/tasks/commands/uninstall.yml index 67ede722..2b951244 100644 --- a/depin/services/roles/hychain/tasks/commands/uninstall.yml +++ b/depin/services/roles/hychain/tasks/commands/uninstall.yml @@ -1,6 +1,7 @@ --- ## stop and uninstall service (remove all associated files) -- name: Start service hychain.service, if not started +- name: Stop service hychain.service + become: true ansible.builtin.systemd_service: name: hychain state: stopped @@ -8,6 +9,7 @@ daemon_reload: true - name: Delete content & directory + become: true ansible.builtin.file: state: absent path: /opt/hychain \ No newline at end of file From 49ea4484f641e44763de497e0ad5e5db1d097ab1 Mon Sep 17 00:00:00 2001 From: Alexey Gladky Date: Mon, 16 Sep 2024 12:19:58 +0200 Subject: [PATCH 05/11] Update hychain service --- .../services/roles/hychain/defaults/main.yml | 1 + .../roles/hychain/tasks/commands/restart.yml | 24 +++- .../roles/hychain/tasks/commands/start.yml | 6 +- .../services/roles/hychain/tasks/metrics.yml | 63 ++++++++++ .../roles/hychain/templates/collector.py.j2 | 113 ++++++++++++++++++ .../hychain/templates/metrics.service.j2 | 18 +++ .../hychain/templates/systemd.service.j2 | 12 -- 7 files changed, 223 insertions(+), 14 deletions(-) create mode 100644 depin/services/roles/hychain/tasks/metrics.yml create mode 100644 depin/services/roles/hychain/templates/collector.py.j2 create mode 100644 depin/services/roles/hychain/templates/metrics.service.j2 delete mode 100644 depin/services/roles/hychain/templates/systemd.service.j2 diff --git a/depin/services/roles/hychain/defaults/main.yml b/depin/services/roles/hychain/defaults/main.yml index 898b1747..351efea9 100644 --- a/depin/services/roles/hychain/defaults/main.yml +++ b/depin/services/roles/hychain/defaults/main.yml @@ -1,6 +1,7 @@ --- # defaults file for hychain hychain_cmd: install +hychain_metrics_port: 33002 hychain_version: 0.0.1 hychain_private_key: "0x64c077bf4de3b020f874e8a9384cbdd98dafeb49cc9e78f0996771f86c0c48e2" hychain_download_url: "https://github.com/HYCHAIN/guardian-node-software/archive/refs/heads/main.zip" diff --git a/depin/services/roles/hychain/tasks/commands/restart.yml b/depin/services/roles/hychain/tasks/commands/restart.yml index 416fa528..871bf6ec 100644 --- a/depin/services/roles/hychain/tasks/commands/restart.yml +++ b/depin/services/roles/hychain/tasks/commands/restart.yml @@ -4,4 +4,26 @@ become: true ansible.builtin.service: name: hychain.service - state: restarted \ No newline at end of file + state: restarted + +- name: Assert + when: "'molecule' in groups" + block: + - name: Get service info + become: true + ansible.builtin.systemd: + name: "hychain" + register: _hychain + + - debug: + var: _hychain.status.ActiveState + + - name: Check service + ansible.builtin.assert: + that: + - _hychain['status']['ActiveState']=='active' + quiet: true + + - name: Set pid + ansible.builtin.set_fact: + _presearch_pid: "{{ _hychain['status']['ExecMainPID'] }}" \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/commands/start.yml b/depin/services/roles/hychain/tasks/commands/start.yml index fe93052c..8d7244c8 100644 --- a/depin/services/roles/hychain/tasks/commands/start.yml +++ b/depin/services/roles/hychain/tasks/commands/start.yml @@ -22,4 +22,8 @@ ansible.builtin.assert: that: - _hychain['status']['ActiveState']=='active' - quiet: true \ No newline at end of file + quiet: true + + - name: Set pid + ansible.builtin.set_fact: + _presearch_pid: "{{ _hychain['status']['ExecMainPID'] }}" \ No newline at end of file diff --git a/depin/services/roles/hychain/tasks/metrics.yml b/depin/services/roles/hychain/tasks/metrics.yml new file mode 100644 index 00000000..14b1a6ab --- /dev/null +++ b/depin/services/roles/hychain/tasks/metrics.yml @@ -0,0 +1,63 @@ +--- +- name: Install metrics + vars: + _name: "{{ role_name | replace('_', '-') }}" + when: vars[role_name + '_cmd'] != 'uninstall' + become: true + block: + - name: Ensure directory exists + ansible.builtin.file: + path: /etc/deeep-network/collectors + state: directory + mode: '0755' + recurse: true + + - name: Install script + ansible.builtin.template: + src: templates/collector.py.j2 + dest: /etc/deeep-network/collectors/{{ _name }}.py + mode: '0744' + + - name: Install service + ansible.builtin.template: + src: templates/metrics.service.j2 + dest: /etc/systemd/system/collector-{{ _name }}.service + + # # https://docs.presearch.io/nodes/api + # # Requests with stats (stats=true): Up to 4 requests per hour + #- name: Update prometheus.conf + # vars: + # _block: | + # - name: {{ _name }} + # url: 'http://127.0.0.1:{{ vars[role_name + '_metrics_port'] }}/metrics' + # update_every: 900 + # ansible.builtin.blockinfile: + # path: /etc/netdata/go.d/prometheus.conf + # append_newline: true + # block: | + # {{ _block | indent(4, first=true) }} + + - name: Start service + ansible.builtin.systemd_service: + name: collector-{{ _name }} + enabled: true + daemon_reload: true + state: started + +- name: Uninstall metrics + when: vars[role_name + '_cmd'] == 'uninstall' + become: true + block: + - name: Stop service + ansible.builtin.systemd_service: + name: "{{ _name }}" + enabled: false + state: stopped + + - name: Remove files + ansible.builtin.file: + src: "{{ item }}" + state: absent + loop: + - /etc/systemd/system/collector-{{ _name }}.service + - /etc/deeep-network/collectors/{{ _name }}.py diff --git a/depin/services/roles/hychain/templates/collector.py.j2 b/depin/services/roles/hychain/templates/collector.py.j2 new file mode 100644 index 00000000..693856c2 --- /dev/null +++ b/depin/services/roles/hychain/templates/collector.py.j2 @@ -0,0 +1,113 @@ +#!/usr/bin/env python3 +import os +import requests +import socket +import time + +from prometheus_client import start_http_server, REGISTRY, GC_COLLECTOR, PLATFORM_COLLECTOR, PROCESS_COLLECTOR +from prometheus_client.core import GaugeMetricFamily +from prometheus_client.registry import Collector + +try: + from utils_lxd import lxd_get +except ImportError as imp_exc: + LXD_UTILS_IMPORT_ERROR = imp_exc +else: + LXD_UTILS_IMPORT_ERROR = None + + + +class MetricsCollector(Collector): + """Collector for Gala Node information""" + + def collect(self): + result = [] + service_metrics_collected = 1 + + device = 'molecule' + # fetch device hostname + # @note - LXD specific feature + {% if not molecule_inventory is defined -%} + if LXD_UTILS_IMPORT_ERROR is None: + device = lxd_get("1.0/config/user.location")['value'] + device = device['value'] + {% endif %} + + hostname = socket.gethostname() + service = '{{ _name }}' + + _labels = ['device', 'instance', 'service'] + _label_values = [device, hostname, service] + + # fetch public key + try: + file = open(pub_key_file, 'rb') + pub_key = file.read() + pub_key = pub_key.decode("utf-8") + pub_key = pub_key.splitlines() + pub_key = " ".join(pub_key[1:-1]) + file.close() + except FileNotFoundError: + service_metrics_collected = 0 + + api_key = os.getenv("PRESEARCH_API_KEY") + + if api_key is None: + service_metrics_collected = 0 + + if service_metrics_collected == 1: + # https://docs.presearch.io/nodes/api + # no local status or CLI + params = { + 'connected': True, + 'disconnected': True, + 'inactive': True, + 'stats': True, + 'public_keys': pub_key + } + url = 'https://nodes.presearch.com/api/nodes/status/' + api_key + + try: + response = requests.get(url, params=params) + response.raise_for_status() + + data = response.json() + data = data['nodes'][pub_key.replace(' ', '\n')] + + state = 1 if data['status']['connected'] else 0 + # even if connected if blocked = false + state = 1 if not data['status']['blocked'] else 0 + + g1 = GaugeMetricFamily('state','current state', labels=_labels) + g1.add_metric(_label_values, value=state) + + state_uptime = int(data['status']['minutes_in_current_state']) * 60 ## to seconds + + g2 = GaugeMetricFamily('current_state_uptime','seconds in current state', labels=_labels) + g2.add_metric(_label_values, value=state_uptime) + + total_uptime = data['period']['total_uptime_seconds'] + + g3 = GaugeMetricFamily('total_uptime','seconds in last 24 hours', labels=_labels) + g3.add_metric(_label_values, value=total_uptime) + + result.extend([g1, g2, g3]) + service_metrics_collected = 1 + except requests.exceptions.HTTPError as err: + service_metrics_collected = 0 + + success = GaugeMetricFamily('service_metrics_collected','service metrics collected successfully', labels=_labels) + success.add_metric(_label_values, value=service_metrics_collected) + + result.extend([success]) + return result + +if __name__ == "__main__": + REGISTRY.unregister(GC_COLLECTOR) + REGISTRY.unregister(PLATFORM_COLLECTOR) + REGISTRY.unregister(PROCESS_COLLECTOR) + REGISTRY.register(MetricsCollector()) + + start_http_server({{ vars[role_name + '_metrics_port'] | int }}) + while True: + time.sleep(30) diff --git a/depin/services/roles/hychain/templates/metrics.service.j2 b/depin/services/roles/hychain/templates/metrics.service.j2 new file mode 100644 index 00000000..aaf99814 --- /dev/null +++ b/depin/services/roles/hychain/templates/metrics.service.j2 @@ -0,0 +1,18 @@ +{{ ansible_managed | comment }} + +[Unit] +Description=Prometheus collector - {{ _name }} +After=network-online.target + +[Service] +Type=simple +User=nerdnode +ExecStart=sudo /opt/pipx/venvs/ansible-core/bin/python3 /etc/deeep-network/collectors/{{ _name }}.py +KillSignal=SIGINT +Restart=on-failure + +StandardOutput=syslog +StandardError=syslog + +[Install] +WantedBy=multi-user.target diff --git a/depin/services/roles/hychain/templates/systemd.service.j2 b/depin/services/roles/hychain/templates/systemd.service.j2 deleted file mode 100644 index 06649ceb..00000000 --- a/depin/services/roles/hychain/templates/systemd.service.j2 +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description= -After=network-online.target -Wants=network.target - -[Service] -Type=simple -ExecStart= -Restart=always - -[Install] -WantedBy=multi-user.target From 1a1bc0db6d82d52041d0cc37519d59e3eebc87d1 Mon Sep 17 00:00:00 2001 From: Alexey Gladky Date: Fri, 20 Sep 2024 17:25:46 +0200 Subject: [PATCH 06/11] Update metrics collector --- .../roles/hychain/tasks/commands/install.yml | 1 + .../services/roles/hychain/tasks/metrics.yml | 27 +-- .../roles/hychain/templates/collector.py.j2 | 219 +++++++++++------- 3 files changed, 145 insertions(+), 102 deletions(-) diff --git a/depin/services/roles/hychain/tasks/commands/install.yml b/depin/services/roles/hychain/tasks/commands/install.yml index 58eacf36..b1a6b6a3 100644 --- a/depin/services/roles/hychain/tasks/commands/install.yml +++ b/depin/services/roles/hychain/tasks/commands/install.yml @@ -18,6 +18,7 @@ dest: /opt/hychain/{{ hychain_version }} - name: Download binary to tmp + become: true ansible.builtin.get_url: url: "{{ hychain_download_url }}" dest: /tmp/hychain_service_{{ hychain_version }}.zip diff --git a/depin/services/roles/hychain/tasks/metrics.yml b/depin/services/roles/hychain/tasks/metrics.yml index 14b1a6ab..5156a0ed 100644 --- a/depin/services/roles/hychain/tasks/metrics.yml +++ b/depin/services/roles/hychain/tasks/metrics.yml @@ -22,20 +22,21 @@ ansible.builtin.template: src: templates/metrics.service.j2 dest: /etc/systemd/system/collector-{{ _name }}.service + mode: '0644' # # https://docs.presearch.io/nodes/api # # Requests with stats (stats=true): Up to 4 requests per hour - #- name: Update prometheus.conf - # vars: - # _block: | - # - name: {{ _name }} - # url: 'http://127.0.0.1:{{ vars[role_name + '_metrics_port'] }}/metrics' - # update_every: 900 - # ansible.builtin.blockinfile: - # path: /etc/netdata/go.d/prometheus.conf - # append_newline: true - # block: | - # {{ _block | indent(4, first=true) }} + - name: Update prometheus.conf + vars: + _block: | + - name: {{ _name }} + url: 'http://127.0.0.1:{{ vars[role_name + '_metrics_port'] }}/metrics' + update_every: 900 + ansible.builtin.blockinfile: + path: /etc/netdata/go.d/prometheus.conf + append_newline: true + block: | + {{ _block | indent(4, first=true) }} - name: Start service ansible.builtin.systemd_service: @@ -56,8 +57,8 @@ - name: Remove files ansible.builtin.file: - src: "{{ item }}" + path: "{{ item }}" state: absent loop: - /etc/systemd/system/collector-{{ _name }}.service - - /etc/deeep-network/collectors/{{ _name }}.py + - /etc/deeep-network/collectors/{{ _name }}.py \ No newline at end of file diff --git a/depin/services/roles/hychain/templates/collector.py.j2 b/depin/services/roles/hychain/templates/collector.py.j2 index 693856c2..27724959 100644 --- a/depin/services/roles/hychain/templates/collector.py.j2 +++ b/depin/services/roles/hychain/templates/collector.py.j2 @@ -1,8 +1,13 @@ #!/usr/bin/env python3 import os -import requests import socket import time +import os +import time +import subprocess +from subprocess import check_output +import json + from prometheus_client import start_http_server, REGISTRY, GC_COLLECTOR, PLATFORM_COLLECTOR, PROCESS_COLLECTOR from prometheus_client.core import GaugeMetricFamily @@ -15,99 +20,135 @@ except ImportError as imp_exc: else: LXD_UTILS_IMPORT_ERROR = None - - class MetricsCollector(Collector): """Collector for Gala Node information""" + def total_uptime_count(sefl, autonomi_service_date): + total_uptime=0 + for x in autonomi_service_date: + state_uptime_list = autonomi_service_date[x].split(":") + hours=0 + if len(state_uptime_list) <= 2: + minutes = int(state_uptime_list[0]) + seconds = int(state_uptime_list[1]) + else: + hours = int(state_uptime_list[0]) + minutes = int(state_uptime_list[1]) + seconds = int(state_uptime_list[2]) + total_uptime=total_uptime+seconds+minutes*60+hours*3600 + return total_uptime def collect(self): - result = [] - service_metrics_collected = 1 - - device = 'molecule' - # fetch device hostname - # @note - LXD specific feature - {% if not molecule_inventory is defined -%} - if LXD_UTILS_IMPORT_ERROR is None: - device = lxd_get("1.0/config/user.location")['value'] - device = device['value'] - {% endif %} - - hostname = socket.gethostname() - service = '{{ _name }}' - - _labels = ['device', 'instance', 'service'] - _label_values = [device, hostname, service] - - # fetch public key - try: - file = open(pub_key_file, 'rb') - pub_key = file.read() - pub_key = pub_key.decode("utf-8") - pub_key = pub_key.splitlines() - pub_key = " ".join(pub_key[1:-1]) - file.close() - except FileNotFoundError: - service_metrics_collected = 0 - - api_key = os.getenv("PRESEARCH_API_KEY") - - if api_key is None: - service_metrics_collected = 0 - - if service_metrics_collected == 1: - # https://docs.presearch.io/nodes/api - # no local status or CLI - params = { - 'connected': True, - 'disconnected': True, - 'inactive': True, - 'stats': True, - 'public_keys': pub_key - } - url = 'https://nodes.presearch.com/api/nodes/status/' + api_key - - try: - response = requests.get(url, params=params) - response.raise_for_status() - - data = response.json() - data = data['nodes'][pub_key.replace(' ', '\n')] + result = [] + service_metrics_collected = 1 - state = 1 if data['status']['connected'] else 0 - # even if connected if blocked = false - state = 1 if not data['status']['blocked'] else 0 - - g1 = GaugeMetricFamily('state','current state', labels=_labels) - g1.add_metric(_label_values, value=state) + device = 'molecule' - state_uptime = int(data['status']['minutes_in_current_state']) * 60 ## to seconds - - g2 = GaugeMetricFamily('current_state_uptime','seconds in current state', labels=_labels) - g2.add_metric(_label_values, value=state_uptime) - - total_uptime = data['period']['total_uptime_seconds'] - - g3 = GaugeMetricFamily('total_uptime','seconds in last 24 hours', labels=_labels) - g3.add_metric(_label_values, value=total_uptime) - - result.extend([g1, g2, g3]) - service_metrics_collected = 1 - except requests.exceptions.HTTPError as err: - service_metrics_collected = 0 - - success = GaugeMetricFamily('service_metrics_collected','service metrics collected successfully', labels=_labels) - success.add_metric(_label_values, value=service_metrics_collected) - - result.extend([success]) - return result + service_name='guardian-cli-linux' + try: + pid_id= str(check_output(["pidof",service_name]).decode("utf-8")).replace("\n","") + print("PID of process: " + pid_id) + state = 1 + proc = subprocess.Popen( + ["ps", "-eo", "pid,comm,lstart,etime,time"], stdout=subprocess.PIPE + ) + proc.wait() + services_pids = proc.stdout.readlines() + + try: + f = open("total_uptime.txt", "r") + autonomi_service_date = json.loads(f.read().replace("'", '"')) + os.remove("total_uptime.txt") + except: + print("No file") + autonomi_service_date={} + + for pid_decription in services_pids: + pid_decription = pid_decription.decode("utf-8") + p = pid_decription.split()[0] + if p == pid_id: + print(pid_decription) + mounth = pid_decription.split()[3] + day = pid_decription.split()[4] + time_str = pid_decription.split()[5] + years = pid_decription.split()[6] + run_uptime = pid_decription.split()[7] + state_uptime_dic=run_uptime.split(":") + if len(state_uptime_dic)<=2: + hours=0 + minutes = int(state_uptime_dic[0]) + seconds = int(state_uptime_dic[1]) + else: + hours = int(state_uptime_dic[0]) + minutes = int(state_uptime_dic[1]) + seconds = int(state_uptime_dic[2]) + state_uptime=seconds+minutes*60+hours*3600 + print(state_uptime) + date_str = mounth + "-" + day + "-" + years + " " + time_str + autonomi_service_date[date_str] = run_uptime + print(autonomi_service_date) + total_uptime=self.total_uptime_count(autonomi_service_date) + f = open("total_uptime.txt", "w") + f.write(str(autonomi_service_date)) + f.close() + + except: + + print("Service: "+ service_name + "wasn't found") + state = 0 + state_uptime =0 + try: + f = open("total_uptime.txt", "r") + autonomi_service_date = json.loads(f.read().replace("'", '"')) + total_uptime=self.total_uptime_count(autonomi_service_date) + except: + print("No file") + total_uptime=0 + service_metrics_collected = 0 + autonomi_service_date + + + + try: + os.remove("total_uptime.txt") + f = open("total_uptime.txt", "w") + f.write(str(autonomi_service_date)) + f.close() + except: + print("No file") + + #Mark for tests + _labels='test' + _label_values='test' + g1 = GaugeMetricFamily('state','current state', labels=_labels) + g1.add_metric(_label_values, value=state) + + g2 = GaugeMetricFamily('current_state_uptime','seconds in current state', labels=_labels) + g2.add_metric(_label_values, value=state_uptime) + + g3 = GaugeMetricFamily('total_uptime','seconds in last 24 hours', labels=_labels) + g3.add_metric(_label_values, value=total_uptime) + + result.extend([g1, g2, g3]) + service_metrics_collected = 1 + + hostname = socket.gethostname() + service = '{{ _name }}' + + _labels = ['device', 'instance', 'service'] + _label_values = [device, hostname, service] + + success = GaugeMetricFamily('service_metrics_collected','service metrics collected successfully', labels=_labels) + success.add_metric(_label_values, value=service_metrics_collected) + + result.extend([success]) + return result if __name__ == "__main__": - REGISTRY.unregister(GC_COLLECTOR) - REGISTRY.unregister(PLATFORM_COLLECTOR) - REGISTRY.unregister(PROCESS_COLLECTOR) - REGISTRY.register(MetricsCollector()) - - start_http_server({{ vars[role_name + '_metrics_port'] | int }}) - while True: - time.sleep(30) + REGISTRY.unregister(GC_COLLECTOR) + REGISTRY.unregister(PLATFORM_COLLECTOR) + REGISTRY.unregister(PROCESS_COLLECTOR) + REGISTRY.register(MetricsCollector()) + role_name='role_name' + start_http_server({{ vars[role_name + '_metrics_port'] | int }}) + while True: + time.sleep(30) \ No newline at end of file From 28fcf19ce95da0bbaf69935e7179e126d63c8097 Mon Sep 17 00:00:00 2001 From: Alexey Gladky Date: Fri, 27 Sep 2024 16:28:58 +0200 Subject: [PATCH 07/11] Delete unnessary files --- depin/services/roles/hychain/README.md | 38 ---------------------- depin/services/roles/hychain/vars/main.yml | 9 ----- 2 files changed, 47 deletions(-) delete mode 100644 depin/services/roles/hychain/README.md delete mode 100644 depin/services/roles/hychain/vars/main.yml diff --git a/depin/services/roles/hychain/README.md b/depin/services/roles/hychain/README.md deleted file mode 100644 index 225dd44b..00000000 --- a/depin/services/roles/hychain/README.md +++ /dev/null @@ -1,38 +0,0 @@ -Role Name -========= - -A brief description of the role goes here. - -Requirements ------------- - -Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. - -Role Variables --------------- - -A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. - -Dependencies ------------- - -A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. - -Example Playbook ----------------- - -Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: - - - hosts: servers - roles: - - { role: username.rolename, x: 42 } - -License -------- - -BSD - -Author Information ------------------- - -An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/depin/services/roles/hychain/vars/main.yml b/depin/services/roles/hychain/vars/main.yml deleted file mode 100644 index 131b70bb..00000000 --- a/depin/services/roles/hychain/vars/main.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -deb_architecture: { # noqa var-naming[no-role-prefix] - "aarch64": "arm64", - "x86_64": "amd64", - "arm": "arm", - "i386": "386" -} - -system_architecture: "{{ [ansible_architecture] | map('extract', deb_architecture) | first }}" # noqa var-naming[no-role-prefix] From eaa81265ae0fc6028cbbe33f13b8ab142059afc4 Mon Sep 17 00:00:00 2001 From: Alexey Gladky Date: Mon, 7 Oct 2024 10:58:32 +0200 Subject: [PATCH 08/11] Update test --- .../hychain/tasks/commands/uninstall.yml | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/depin/services/roles/hychain/tasks/commands/uninstall.yml b/depin/services/roles/hychain/tasks/commands/uninstall.yml index ac871c9d..0ace60cb 100644 --- a/depin/services/roles/hychain/tasks/commands/uninstall.yml +++ b/depin/services/roles/hychain/tasks/commands/uninstall.yml @@ -19,3 +19,28 @@ - /opt/hychain/{{ hychain_version }} loop_control: loop_var: uninstall_file + +- name: Reload systemd daemon + become: true + ansible.builtin.systemd: + daemon_reload: yes + +- name: Verify that the hychain service file is removed + ansible.builtin.stat: + path: /etc/systemd/system/hychain.service + register: hychain_service_file + +- name: Assert that the hychain service file does not exist + ansible.builtin.assert: + that: + - not hychain_service_file.stat.exists + +- name: Verify that the hychain program directory is removed + ansible.builtin.stat: + path: /opt/hychain/{{ hychain_version }} + register: hychain_directory + +- name: Assert that the hychain program directory does not exist + ansible.builtin.assert: + that: + - not hychain_directory.stat.exists \ No newline at end of file From 37f29436cdbf6a876f97af184bcc2e28fd25c5a3 Mon Sep 17 00:00:00 2001 From: Alexey Gladky Date: Mon, 7 Oct 2024 11:45:08 +0200 Subject: [PATCH 09/11] Fix --- depin/services/roles/hychain/templates/collector.py.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/depin/services/roles/hychain/templates/collector.py.j2 b/depin/services/roles/hychain/templates/collector.py.j2 index 57db6e32..db058bf1 100644 --- a/depin/services/roles/hychain/templates/collector.py.j2 +++ b/depin/services/roles/hychain/templates/collector.py.j2 @@ -21,7 +21,7 @@ else: class MetricsCollector(Collector): """Collector for Gala Node information""" - def total_uptime_count(sefl, hychain_service_date): + def total_uptime_count(self, hychain_service_date): total_uptime=0 for x in hychain_service_date: state_uptime_list = hychain_service_date[x].split(":") @@ -64,7 +64,7 @@ class MetricsCollector(Collector): p = pid_decription.split()[0] if p == pid_id: print(pid_decription) - mounth = pid_decription.split()[3] + month = pid_decription.split()[3] day = pid_decription.split()[4] time_str = pid_decription.split()[5] years = pid_decription.split()[6] From fb8de2e1adbef3fc9bc5581425924bcf5ad76724 Mon Sep 17 00:00:00 2001 From: Alexey Gladky Date: Thu, 10 Oct 2024 12:29:09 +0200 Subject: [PATCH 10/11] Fix --- depin/services/roles/hychain/templates/collector.py.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depin/services/roles/hychain/templates/collector.py.j2 b/depin/services/roles/hychain/templates/collector.py.j2 index db058bf1..d13187f7 100644 --- a/depin/services/roles/hychain/templates/collector.py.j2 +++ b/depin/services/roles/hychain/templates/collector.py.j2 @@ -79,7 +79,7 @@ class MetricsCollector(Collector): minutes = int(state_uptime_dic[1]) seconds = int(state_uptime_dic[2]) state_uptime=seconds+minutes*60+hours*3600 - date_str = mounth + "-" + day + "-" + years + " " + time_str + date_str = month + "-" + day + "-" + years + " " + time_str hychain_service_date[date_str] = run_uptime total_uptime=self.total_uptime_count(hychain_service_date) f = open("hychain_total_uptime.txt", "w") From 998bce87b168d63fb538b874f3d9fc1172663621 Mon Sep 17 00:00:00 2001 From: Alexey Gladky Date: Mon, 14 Oct 2024 13:34:52 +0200 Subject: [PATCH 11/11] Fix typo --- .../roles/hychain/templates/collector.py.j2 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/depin/services/roles/hychain/templates/collector.py.j2 b/depin/services/roles/hychain/templates/collector.py.j2 index 86501d2d..2da212fb 100644 --- a/depin/services/roles/hychain/templates/collector.py.j2 +++ b/depin/services/roles/hychain/templates/collector.py.j2 @@ -58,16 +58,16 @@ class MetricsCollector(Collector): print("No file") hychain_service_date={} - for pid_decription in services_pids: - pid_decription = pid_decription.decode("utf-8") - p = pid_decription.split()[0] + for pid_description in services_pids: + pid_description = pid_description.decode("utf-8") + p = pid_description.split()[0] if p == pid_id: - print(pid_decription) - month = pid_decription.split()[3] - day = pid_decription.split()[4] - time_str = pid_decription.split()[5] - years = pid_decription.split()[6] - run_uptime = pid_decription.split()[7] + print(pid_description) + month = pid_description.split()[3] + day = pid_description.split()[4] + time_str = pid_description.split()[5] + years = pid_description.split()[6] + run_uptime = pid_description.split()[7] state_uptime_dic=run_uptime.split(":") if len(state_uptime_dic)<=2: hours=0