From f56ab6462ff4743362be037266b1a7dc59b69c1c Mon Sep 17 00:00:00 2001 From: Ermine Jose Date: Thu, 26 Dec 2024 21:29:43 +0530 Subject: [PATCH] feat: add antctl reset service --- resources/ansible/roles/node/tasks/main.yml | 21 +++++ .../roles/node/templates/antctl_service.j2 | 39 +++++++++ .../node/templates/service-nodes-antctl.sh | 83 +++++++++++++++++++ resources/ansible/upgrade_antctl.yml | 2 +- resources/ansible/upgrade_nodes.yml | 17 +++- 5 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 resources/ansible/roles/node/templates/antctl_service.j2 create mode 100644 resources/ansible/roles/node/templates/service-nodes-antctl.sh diff --git a/resources/ansible/roles/node/tasks/main.yml b/resources/ansible/roles/node/tasks/main.yml index 36b6839..4813885 100644 --- a/resources/ansible/roles/node/tasks/main.yml +++ b/resources/ansible/roles/node/tasks/main.yml @@ -112,3 +112,24 @@ when: - start_services_result.rc is defined - start_services_result.rc != 0 + +- name: copy the service antctl script to /usr/local/bin + ansible.builtin.unarchive: + src: "service-nodes-antctl.sh" + dest: /usr/local/bin/service-nodes-antctl.sh + mode: '0744' + become: true + +- name: create systemd service file for antctl service + ansible.builtin.template: + src: antctl_service.j2 + dest: "/etc/systemd/system/antctl-reset.service" + mode: '0644' + become: true + +- name: start and enable antctl service for nodes + ansible.builtin.systemd: + name: "antctl-reset.service" + state: started + enabled: yes + become: true diff --git a/resources/ansible/roles/node/templates/antctl_service.j2 b/resources/ansible/roles/node/templates/antctl_service.j2 new file mode 100644 index 0000000..855d3d5 --- /dev/null +++ b/resources/ansible/roles/node/templates/antctl_service.j2 @@ -0,0 +1,39 @@ +[Unit] +Description=antctl reset service +After=network.target + +[Service] +# Extracted Variables +Environment="NODES_TO_ADD={{ nodes_to_add }}" +Environment="GENESIS_MULTIADDR={{ genesis_multiaddr }}" +Environment="NETWORK_CONTACTS_URL={{ network_contacts_url }}" +Environment="NETWORK_ID={{ network_id }}" +Environment="NODE_RPC_IP={{ node_rpc_ip }}" +Environment="REWARDS_ADDRESS={{ rewards_address }}" +Environment="MAX_ARCHIVED_LOG_FILES={{ max_archived_log_files }}" +Environment="MAX_LOG_FILES={{ max_log_files }}" +Environment="PRIVATE_IP_ETH1={{ private_ip_eth1.stdout }}" +Environment="MAKE_VM_PRIVATE={{ make_vm_private }}" +Environment="RPC_PORT={{ rpc_port }}" +Environment="USE_PORT_RANGE={{ use_port_range }}" +Environment="RPC_START_PORT={{ rpc_start_port }}" +Environment="RPC_END_PORT={{ rpc_end_port }}" +Environment="METRICS_PORT={{ metrics_port }}" +Environment="METRICS_START_PORT={{ metrics_start_port }}" +Environment="METRICS_END_PORT={{ metrics_end_port }}" +Environment="LOG_FORMAT={{ log_format }}" +Environment="ENV_VARIABLES={{ env_variables }}" +Environment="VERSION={{ version }}" +Environment="NODE_ARCHIVE_URL={{ node_archive_url }}" +Environment="EVM_NETWORK_TYPE={{ evm_network_type }}" +Environment="EVM_RPC_URL={{ evm_rpc_url }}" +Environment="EVM_PAYMENT_TOKEN_ADDRESS={{ evm_payment_token_address }}" +Environment="EVM_DATA_PAYMENTS_ADDRESS={{ evm_data_payments_address }}" +Enivronment="INTERVAL={{ interval }}" + +ExecStart=/usr/local/bin/service-nodes-antctl.sh +Restart=on-abnormal +WorkingDirectory=/usr/local/bin + +[Install] +WantedBy=multi-user.target diff --git a/resources/ansible/roles/node/templates/service-nodes-antctl.sh b/resources/ansible/roles/node/templates/service-nodes-antctl.sh new file mode 100644 index 0000000..ce69236 --- /dev/null +++ b/resources/ansible/roles/node/templates/service-nodes-antctl.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +ADD_ARGUMENTS="" + +ADD_ARGUMENTS+=" --data-dir-path=/mnt/antnode-storage/data" +ADD_ARGUMENTS+=" --log-dir-path=/mnt/antnode-storage/log" +ADD_ARGUMENTS+=" --count=${NODES_TO_ADD}" + +if [ -z "${GENESIS_MULTIADDR}"]; then + ADD_ARGUMENTS+=" --peer=${GENESIS_MULTIADDR}" +fi + +if [ -z "${NETWORK_CONTACTS_URL}"]; then + ADD_ARGUMENTS+=" --network-contacts-url=${NETWORK_CONTACTS_URL}" +fi + +if [ -z "${NETWORK_ID}"]; then + ADD_ARGUMENTS+=" --network-id=${NETWORK_ID}" +fi + +ADD_ARGUMENTS+=" --testnet" +ADD_ARGUMENTS+=" --rpc-address=${NODE_RPC_IP}" +ADD_ARGUMENTS+=" --rewards-address=${REWARDS_ADDRESS}" +ADD_ARGUMENTS+=" --max-archived-log-files=${MAX_ARCHIVED_LOG_FILES}" +ADD_ARGUMENTS+=" --max-log-files=${MAX_LOG_FILES}" + +if [ -z "${MAKE_VM_PRIVATE}"]; then + ADD_ARGUMENTS+=" --node-ip=${PRIVATE_IP_ETH1}" + ADD_ARGUMENTS+=" --home-network" +fi + +RPC_PORT="--rpc-port" +if [ ! -z "${USE_PORT_RANGE}"]; then + RPC_PORT+=" ${RPC_PORT}" +fi + +if [ -z "${USE_PORT_RANGE}"]; then + RPC_PORT+=" ${RPC_START_PORT}" + RPC_PORT+=" -" + RPC_PORT+=" ${RPC_END_PORT}" +fi + +ADD_ARGUMENTS+=" \`${RPC_PORT}\`" +if [ ! -z "${USE_PORT_RANGE}"]; then + ADD_ARGUMENTS+=" --metrics-port=${METRICS_PORT}" +fi + +if [ -z "${USE_PORT_RANGE}"]; then + ADD_ARGUMENTS+=" --metrics-port=\`${METRICS_START_PORT} - ${METRICS_END_PORT}\`" +fi + +if [ -z "${LOG_FORMAT}"]; then + ADD_ARGUMENTS+=" --log-format=${LOG_FORMAT}" +fi + +if [ -z "${ENV_VARIABLES}" ]; then + ADD_ARGUMENTS+=" --env=${ENV_VARIABLES}" +fi + +if [ -z "${VERSION}"]; then + ADD_ARGUMENTS+=" --version=${VERSION}" +fi + +if [ -z "${EVM_NETWORK_TYPE}"]; then + ADD_ARGUMENTS+=" ${EVM_NETWORK_TYPE}" +fi + +if [[ "${EVM_NETWORK_TYPE}" == "evm-custom" ]]; then + ADD_ARGUMENTS+=" --rpc-url=${EVM_RPC_URL}" + ADD_ARGUMENTS+=" --payment-token-address=${EVM_PAYMENT_TOKEN_ADDRESS}" + ADD_ARGUMENTS+=" --data-payments-address=${EVM_DATA_PAYMENTS_ADDRESS}" +fi + + +while true; do + # Your code here + sleep 30 + antctl reset + antctl -v add ${ADD_ARGUMENTS} + antctl -v start --interval ${INTERVAL} + date >> ~/test_date.txt + echo ${ADD_ARGUMENTS} >> ~/test_date.txt +done \ No newline at end of file diff --git a/resources/ansible/upgrade_antctl.yml b/resources/ansible/upgrade_antctl.yml index 34875cc..80927c9 100644 --- a/resources/ansible/upgrade_antctl.yml +++ b/resources/ansible/upgrade_antctl.yml @@ -17,4 +17,4 @@ ansible.builtin.unarchive: src: "/tmp/{{ antctl_archive_filename }}" dest: "/usr/local/bin" - remote_src: True \ No newline at end of file + remote_src: True diff --git a/resources/ansible/upgrade_nodes.yml b/resources/ansible/upgrade_nodes.yml index 162c2e3..527e511 100644 --- a/resources/ansible/upgrade_nodes.yml +++ b/resources/ansible/upgrade_nodes.yml @@ -1,4 +1,11 @@ --- +- name: stop and disable antctl service for nodes + ansible.builtin.systemd: + name: "antctl-reset.service" + state: stopped + enabled: no + become: true + - name: upgrade node binaries using antctl hosts: all tasks: @@ -21,4 +28,12 @@ {% endif %} eval "$cmd" args: - executable: /bin/bash \ No newline at end of file + executable: /bin/bash + +- name: start and enable antctl service for nodes + ansible.builtin.systemd: + name: "antctl-reset.service" + state: started + enabled: yes + become: true +