Instantly share code, notes, and snippets.

Embed
What would you like to do?
Setting up the skypool nimiq client via ansible, monitoring via systemd and ruby & cron
# used in
# -
---
- hosts: "{{ target }}"
become: yes
become_user: root
become_method: sudo
tasks:
- name: install dependencies
package:
name: "{{ item }}"
state: present
with_items:
- unzip
- ruby-dev
- name: install ruby gems
shell: '/usr/bin/gem install httparty'
args:
creates: '/usr/local/bin/httparty'
- name: create nimiq user
user:
name: nimiq
- name: create programm directory
file:
path: /opt/nimiq
recurse: yes
state: directory
owner: nimiq
group: nimiq
- name: get and unzip release
unarchive:
remote_src: yes
src: https://github.com/skypool-org/skypool-nimiq-miner/releases/download/{{ nimiq_release_version_number }}/{{ nimiq_release_version }}.zip
dest: /opt/nimiq
creates: /opt/nimiq/{{ nimiq_release_version }}
owner: nimiq
group: nimiq
ignore_errors: yes
notify:
- restart nimiq
- name: create nimiq config file
template:
src: nimiq_config.txt.j2
dest: /opt/nimiq/{{ nimiq_release_version }}/config.txt
notify:
- restart nimiq
- name: create nimiq systemd file
template:
src: systemd_nimiq.j2
dest: /etc/systemd/system/nimiq.service
register: systemd_unit_file
notify:
- restart nimiq
- name: reload systemd daemon
shell: systemctl daemon-reload
when: systemd_unit_file.changed
- name: enable nimiq on reboot
service:
name: nimiq
enabled: yes
- name: create status checker
template:
src: nimiq_status_checker.rb.j2
dest: /root/nimiq_status_checker.rb
- name: setup cron tab for status checker
cron:
name: "nimiq status checker"
minute: "*/10"
job: "/usr/bin/ruby /root/nimiq_status_checker.rb"
handlers:
- name: restart nimiq
service:
name: nimiq
state: restarted
...
{
"address": "{{ nimiq_address }}",
"name": "{{ ansible_host }}",
"thread": "{{ nimiq_threads }}",
"percent": "{{ nimiq_load_percentage }}",
"server": "auto"
}
require 'httparty'
url = 'https://api.nimiq.skypool.xyz/api/v1/pool/profile?address={{ nimiq_address }} }'
data = HTTParty.get(url).parsed_response
this_worker = data['data']['workers'].find {|worker| worker['name'] == "{{ ansible_host }}" }
if this_worker['status'] == 'offline'
puts 'Worker appears to be offline, initiate restart...'
res = system('systemctl restart nimiq.service')
puts 'Worker restarted successfully' if res
end
[Unit]
Description=nimiq miner {{ nimiq_release_version_number }}
[Service]
User=nimiq
Group=nimiq
WorkingDirectory=/opt/nimiq/{{ nimiq_release_version }}
ExecStart=/opt/nimiq/{{ nimiq_release_version }}/skypool-node-client
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
# github release file base name, i.e.:
# skypool-nimiq-v1.1.3-linux-x64-compat
# skypool-nimiq-v1.1.3-linux-x64-extreme
# skypool-nimiq-v1.1.3-linux-x64-fast
# skypool-nimiq-v1.1.3-linux-x64-normal
# skypool-nimiq-v1.1.3-mac-x64-fast
nimiq_release_version: <PUT_BASE_NAME_HERE>
# github tag release i.e. v1.1.2
nimiq_release_version_number: <PUT_RELEASE_TAG_HERE>
nimiq_address: <PUT_YOUR_WALLET_ADDRESS_HERE>
nimiq_threads: <PUT_AMOUNT_OF_PARALLEL_THREADS_HERE>
nimiq_load_percentage: <PUT_MAX_LOAD_HERE> # min 50, max 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment