-
Notifications
You must be signed in to change notification settings - Fork 2
09 30 feat sparkles adds avalanche service #121
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
Open
skuznetsov-klika
wants to merge
11
commits into
main
Choose a base branch
from
09-30-feat_sparkles_adds_avalanche_service
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7b165e2
add avalanche
skuznetsov-klika 77faf1d
remove unnecessary logging
skuznetsov-klika 4511da9
add asserts
skuznetsov-klika e13e510
add asserts
skuznetsov-klika fd16772
clean code
skuznetsov-klika 18a94c8
update install avalanche
skuznetsov-klika ab23446
remove duplicated import
skuznetsov-klika 729a686
utilize Path.stem to derive the service name from the file name
skuznetsov-klika e7ade55
removed from readme installing pynetbox
skuznetsov-klika 7631908
Merge branch 'main' into 09-30-feat_sparkles_adds_avalanche_service
skuznetsov-klika ac1408f
changed place of the port avalanche
skuznetsov-klika File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ metrics_port: | |
| autonomi: 33002 | ||
| hychain: 33003 | ||
| storagechain: 33004 | ||
| avalanche: 33006 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # defaults/main.yml | ||
|
|
||
| # Command to execute (install, uninstall, etc.) | ||
| avalanche_cmd: "{{ depin_cmd | default('install') }}" | ||
|
|
||
| # AvalancheGo version to install | ||
| avalanche_version: "1.11.11" | ||
|
|
||
| # Determine the architecture (amd64 or arm64) | ||
| avalanche_arch: "{{ 'arm64' if ansible_facts['architecture'] == 'aarch64' else 'amd64' }}" | ||
|
|
||
| # Download URL for AvalancheGo binary | ||
| avalanche_download_url: "https://github.com/ava-labs/avalanchego/releases/download/v{{ avalanche_version }}/avalanchego-linux-{{ avalanche_arch }}-v{{ avalanche_version }}.tar.gz" | ||
|
|
||
| # Installation directory for AvalancheGo | ||
| avalanche_install_dir: '/opt/avalanche/{{ avalanche_version }}' | ||
|
|
||
| # Configuration directory for AvalancheGo | ||
| avalanche_config_dir: '/home/{{ ansible_user_id }}/.avalanchego' # Or another appropriate path | ||
|
|
||
| # User and group to run AvalancheGo service | ||
| avalanche_user: '{{ ansible_user_id }}' | ||
| avalanche_group: '{{ ansible_user_id }}' | ||
|
|
||
| # Network ID ('mainnet' or 'fuji' for testnet) | ||
| avalanche_network_id: 'mainnet' | ||
|
|
||
| # Additional necessary variables | ||
| avalanche_ip_mode: 'dynamic' # 'dynamic' or 'static' | ||
| avalanche_public_ip: '' # Automatically determined if empty and ip_mode == 'static' | ||
| avalanche_rpc_public: false # true or false | ||
| avalanche_admin_api_enabled: false # true or false | ||
| avalanche_index_enabled: false # true or false | ||
| avalanche_state_sync_enabled: true # true or false | ||
| avalanche_archival_mode: false # true or false | ||
| avalanche_db_dir: '' # Path to database directory if needed |
209 changes: 209 additions & 0 deletions
209
depin/services/roles/avalanche/tasks/commands/install.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| # tasks/commands/install.yml | ||
|
|
||
| --- | ||
|
|
||
| - name: Determine OS family | ||
| set_fact: | ||
| os_family: "{{ ansible_facts['os_family'] }}" | ||
|
|
||
| - name: Install required packages for AvalancheGo (Debian) | ||
| become: true | ||
| ansible.builtin.package: | ||
| name: | ||
| - curl | ||
| - wget | ||
| - dnsutils | ||
| state: present | ||
| when: os_family == 'Debian' | ||
|
|
||
| - name: Install required packages for AvalancheGo (RedHat) | ||
| become: true | ||
| ansible.builtin.package: | ||
| name: | ||
| - curl | ||
| - wget | ||
| - bind-utils | ||
| - policycoreutils-python-utils | ||
| - policycoreutils | ||
| state: present | ||
| when: os_family == 'RedHat' | ||
|
|
||
| - name: Set avalanche architecture | ||
| set_fact: | ||
| avalanche_arch: "{{ 'arm64' if ansible_facts['architecture'] == 'aarch64' else 'amd64' }}" | ||
|
|
||
| - name: Set download URL for AvalancheGo | ||
| set_fact: | ||
| avalanche_download_url: "https://github.com/ava-labs/avalanchego/releases/download/v{{ avalanche_version }}/avalanchego-linux-{{ avalanche_arch }}-v{{ avalanche_version }}.tar.gz" | ||
|
|
||
| - name: Get public IP address | ||
| ansible.builtin.uri: | ||
| url: https://api.ipify.org | ||
| return_content: yes | ||
| register: public_ip | ||
| when: | ||
| - avalanche_public_ip == '' | ||
| - avalanche_ip_mode == 'static' | ||
|
|
||
| - name: Set public IP address fact | ||
| set_fact: | ||
| avalanche_public_ip: "{{ public_ip.content | trim }}" | ||
| when: | ||
| - avalanche_public_ip == '' | ||
| - avalanche_ip_mode == 'static' | ||
|
|
||
| - name: Create program folder | ||
| become: true | ||
| ansible.builtin.file: | ||
| state: directory | ||
| owner: root | ||
| group: root | ||
| mode: '0755' | ||
| dest: "{{ avalanche_install_dir }}" | ||
|
|
||
| - name: Verify that the program folder was created | ||
| ansible.builtin.stat: | ||
| path: "{{ avalanche_install_dir }}" | ||
| register: avalanche_program_folder | ||
|
|
||
| - name: Assert that the program folder exists | ||
| ansible.builtin.assert: | ||
| that: | ||
| - avalanche_program_folder.stat.exists | ||
| - avalanche_program_folder.stat.isdir | ||
|
|
||
| - name: Download AvalancheGo | ||
| become: true | ||
| ansible.builtin.get_url: | ||
| url: "{{ avalanche_download_url }}" | ||
| dest: /tmp/avalanchego.tar.gz | ||
| mode: '0644' | ||
| register: download_result | ||
| retries: 3 | ||
| delay: 10 | ||
| until: download_result is succeeded | ||
|
|
||
| - name: Fail if AvalancheGo download failed | ||
| ansible.builtin.fail: | ||
| msg: "Failed to download AvalancheGo from {{ avalanche_download_url }}" | ||
| when: download_result is failed | ||
|
|
||
| - name: Extract AvalancheGo | ||
| become: true | ||
| ansible.builtin.unarchive: | ||
| src: /tmp/avalanchego.tar.gz | ||
| dest: "{{ avalanche_install_dir }}" | ||
| remote_src: yes | ||
| extra_opts: | ||
| - --strip-components=1 | ||
|
|
||
| - name: Ensure avalanchego binary is executable | ||
| become: true | ||
| ansible.builtin.file: | ||
| path: "{{ avalanche_install_dir }}/avalanchego" | ||
| mode: '0755' | ||
|
|
||
| - name: Verify that the AvalancheGo binary exists | ||
| ansible.builtin.stat: | ||
| path: "{{ avalanche_install_dir }}/avalanchego" | ||
| register: avalanchego_binary | ||
|
|
||
| - name: Assert that the AvalancheGo binary exists | ||
| ansible.builtin.assert: | ||
| that: | ||
| - avalanchego_binary.stat.exists | ||
| - (avalanchego_binary.stat.mode | int == 755) or (avalanchego_binary.stat.mode | int == 493) | ||
|
|
||
| - name: Adjust SELinux context for avalanchego binary | ||
| become: true | ||
| ansible.builtin.command: "semanage fcontext -a -t bin_t '{{ avalanche_install_dir }}/avalanchego' || semanage fcontext -m -t bin_t '{{ avalanche_install_dir }}/avalanchego'" | ||
| args: | ||
| warn: false | ||
| when: ansible_facts['os_family'] == 'RedHat' | ||
|
|
||
| - name: Restore SELinux context | ||
| become: true | ||
| ansible.builtin.command: "restorecon -Fv '{{ avalanche_install_dir }}/avalanchego'" | ||
| when: ansible_facts['os_family'] == 'RedHat' | ||
|
|
||
| - name: Symlink avalanchego binary | ||
| become: true | ||
| ansible.builtin.file: | ||
| src: "{{ avalanche_install_dir }}/avalanchego" | ||
| dest: /usr/local/bin/avalanchego | ||
| state: link | ||
| force: true | ||
|
|
||
| - name: Verify symlink for AvalancheGo binary | ||
| ansible.builtin.stat: | ||
| path: /usr/local/bin/avalanchego | ||
| follow: false | ||
| register: avalanchego_symlink | ||
|
|
||
| - name: Assert that the symlink exists and is correct | ||
| ansible.builtin.assert: | ||
| that: | ||
| - avalanchego_symlink.stat.islnk | ||
| - avalanchego_symlink.stat.lnk_source == "{{ avalanche_install_dir }}/avalanchego" | ||
|
|
||
| - name: Create configuration directories | ||
| become: true | ||
| ansible.builtin.file: | ||
| path: "{{ item }}" | ||
| state: directory | ||
| owner: "{{ avalanche_user }}" | ||
| group: "{{ avalanche_group }}" | ||
| mode: '0755' | ||
| loop: | ||
| - "{{ avalanche_config_dir }}/configs" | ||
| - "{{ avalanche_config_dir }}/configs/chains/C" | ||
|
|
||
| - name: Deploy node.json configuration | ||
| become: true | ||
| ansible.builtin.template: | ||
| src: node.json.j2 | ||
| dest: "{{ avalanche_config_dir }}/configs/node.json" | ||
| mode: '0644' | ||
| owner: "{{ avalanche_user }}" | ||
| group: "{{ avalanche_group }}" | ||
|
|
||
| - name: Deploy config.json configuration | ||
| become: true | ||
| ansible.builtin.template: | ||
| src: config.json.j2 | ||
| dest: "{{ avalanche_config_dir }}/configs/chains/C/config.json" | ||
| mode: '0644' | ||
| owner: "{{ avalanche_user }}" | ||
| group: "{{ avalanche_group }}" | ||
|
|
||
| - name: Create systemd service | ||
| become: true | ||
| ansible.builtin.template: | ||
| src: templates/systemd.service.j2 | ||
| dest: /etc/systemd/system/avalanchego.service | ||
| mode: '0644' | ||
|
|
||
| - name: Verify that the AvalancheGo service file exists | ||
| ansible.builtin.stat: | ||
| path: /etc/systemd/system/avalanchego.service | ||
| register: avalanchego_service_file | ||
|
|
||
| - name: Assert that the AvalancheGo service file exists | ||
| ansible.builtin.assert: | ||
| that: | ||
| - avalanchego_service_file.stat.exists | ||
|
|
||
| - name: Reload systemd daemon | ||
| become: true | ||
| ansible.builtin.systemd: | ||
| daemon_reload: yes | ||
|
|
||
| - name: Start Avalanche node | ||
| ansible.builtin.include_tasks: | ||
| file: commands/start.yml | ||
|
|
||
| - name: Install metrics | ||
| vars: | ||
| depin_cmd: install | ||
| ansible.builtin.include_tasks: | ||
| file: tasks/metrics.yml | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
|
|
||
| - name: Uninstall node | ||
| ansible.builtin.include_tasks: | ||
| file: commands/uninstall.yml | ||
|
|
||
| - name: Install node | ||
| ansible.builtin.include_tasks: | ||
| file: commands/install.yml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| --- | ||
|
|
||
| - name: Get current service info | ||
| become: true | ||
| ansible.builtin.systemd: | ||
| name: "avalanchego" | ||
| register: _avalanchego_before | ||
|
|
||
| - name: Set current PID | ||
| ansible.builtin.set_fact: | ||
| _avalanche_pid: "{{ _avalanchego_before['status']['ExecMainPID'] }}" | ||
|
|
||
| - name: Restart node | ||
| become: true | ||
| ansible.builtin.service: | ||
| name: avalanchego.service | ||
| state: restarted | ||
|
|
||
| - name: Assert | ||
| when: "'molecule' in groups" | ||
| block: | ||
| - name: Get new service info | ||
| become: true | ||
| ansible.builtin.systemd: | ||
| name: "avalanchego" | ||
| register: _avalanchego_after | ||
|
|
||
| - name: Debug new service status | ||
| debug: | ||
| msg: | ||
| - "Old PID: {{ _avalanche_pid }}" | ||
| - "New PID: {{ _avalanchego_after['status']['ExecMainPID'] }}" | ||
| - "Active State: {{ _avalanchego_after['status']['ActiveState'] }}" | ||
|
|
||
| - name: Check service | ||
| ansible.builtin.assert: | ||
| that: | ||
| - _avalanchego_after['status']['ActiveState'] == 'active' | ||
| - _avalanche_pid | int != _avalanchego_after['status']['ExecMainPID'] | int | ||
| quiet: true | ||
|
|
||
| - name: Update PID | ||
| ansible.builtin.set_fact: | ||
| _avalanche_pid: "{{ _avalanchego_after['status']['ExecMainPID'] }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # tasks/commands/start.yml | ||
|
|
||
| --- | ||
| - name: Start Avalanche node | ||
| become: true | ||
| ansible.builtin.service: | ||
| name: avalanchego.service | ||
| enabled: true | ||
| daemon_reload: true | ||
| state: started |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| --- | ||
| ## stop service | ||
|
|
||
| - name: Stop node | ||
| become: true | ||
| ansible.builtin.service: | ||
| name: avalanchego.service | ||
| enabled: false | ||
| state: stopped | ||
|
|
||
| - name: Assert | ||
| when: "'molecule' in groups" | ||
| block: | ||
| - name: Get service info | ||
| become: true | ||
| ansible.builtin.systemd: | ||
| name: "avalanchego" | ||
| register: _avalanchego | ||
|
|
||
| - name: Debug service status | ||
| debug: | ||
| var: _avalanchego.status | ||
|
|
||
| - name: Check service | ||
| ansible.builtin.assert: | ||
| that: | ||
| - _avalanchego['status']['ActiveState'] == 'inactive' | ||
| quiet: true |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The relative path in
include_tasksneeds to be adjusted to../metrics.ymlsince the task is being included from within thecommands/subdirectory. The current pathtasks/metrics.ymlwill fail to locate the metrics file.Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.