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

feat: add antctl reset service #272

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 21 additions & 0 deletions resources/ansible/roles/node/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 39 additions & 0 deletions resources/ansible/roles/node/templates/antctl_service.j2
Original file line number Diff line number Diff line change
@@ -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
83 changes: 83 additions & 0 deletions resources/ansible/roles/node/templates/service-nodes-antctl.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion resources/ansible/upgrade_antctl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
ansible.builtin.unarchive:
src: "/tmp/{{ antctl_archive_filename }}"
dest: "/usr/local/bin"
remote_src: True
remote_src: True
17 changes: 16 additions & 1 deletion resources/ansible/upgrade_nodes.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -21,4 +28,12 @@
{% endif %}
eval "$cmd"
args:
executable: /bin/bash
executable: /bin/bash

- name: start and enable antctl service for nodes
ansible.builtin.systemd:
name: "antctl-reset.service"
state: started
enabled: yes
become: true

Loading