-
-
Save imylomylo/495fb2877e7762933ba841c4eb2991ff to your computer and use it in GitHub Desktop.
Zcash ansible script
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
--- | |
- hosts: [miner_zcash, tag_Name_zmine, zmine*] | |
become_method: sudo | |
become_user: root | |
become: true | |
strategy: free | |
vars: | |
stratum_uri: zec-eu.suprnova.cc:2142 | |
stratum_user: rick3_.user | |
stratum_password: password | |
nheqminer_supervisor: | | |
[program:nheqminer] | |
command=/usr/bin/nheqminer -l {{ stratum_uri }} -u {{ stratum_user }} -p {{ stratum_password }} -t {{ ansible_processor_vcpus }} | |
process_name=%(program_name)s | |
numprocs=1 | |
autostart=true | |
autorestart=true | |
startsecs=5 | |
startretries=3 | |
stdout_logfile=/var/log/nheqminer.log | |
redirect_stderr=true | |
script_stat_mining: | | |
#!/bin/bash | |
CPU=`cat /proc/cpuinfo | grep "model name" | cut -d: -f 2 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | tail -n1` | |
CPU_SPEED=`cat /proc/cpuinfo | grep "cpu MHz" | cut -d: -f 2 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | tail -n1` | |
CPU_CORE=`cat /proc/cpuinfo | grep "model name" | wc -l` | |
DATE=`date +%Y-%m-%d_%H:%M:%S_%Z` | |
SOL=`cat /var/log/nheqminer.log | grep "Sol/s" | cut -d, -f 2 | tail -n1 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'` | |
echo "$HOSTNAME, $DATE, $CPU, ${CPU_SPEED}MHz, ${CPU_CORE} core, $SOL" | |
tasks: | |
- name: Install pre-request packages | |
apt: name={{item}} state=present update_cache=yes cache_valid_time=3600 | |
with_items: | |
- libboost-all-dev | |
- vim | |
- build-essential | |
- cmake | |
- htop | |
- git | |
- supervisor | |
- name: Enable and start supervisor | |
service: name=supervisor enabled=yes state=started | |
- name: Clone kost nheqminer | |
git: repo=https://github.com/kost/nheqminer | |
dest=/opt/nheqminer | |
recursive=yes | |
register: gitclone | |
- name: Create build directory | |
file: path=/opt/nheqminer/nheqminer/build state=directory | |
- name: get cpu flags | |
command: > | |
awk -F: '/^flags/ {print $2; exit}' /proc/cpuinfo | |
register: cpu_flags_cmd | |
- name: set cpu flags fact | |
set_fact: | |
cpu_flags: "{{ cpu_flags_cmd.stdout.split() }}" | |
- name: set cpu flags avx2 | |
set_fact: | |
flag_avx2: "{{ 'avx2' in cpu_flags }}" | |
- name: set cpu flags avx | |
set_fact: | |
flag_avx: "{{ 'avx' in cpu_flags }}" | |
- name: Cmake with AVX2 flag | |
command: cmake -DXENON=2 ../ chdir=/opt/nheqminer/nheqminer/build | |
when: flag_avx2 | |
- name: Cmake with AVX flag | |
command: cmake -DXENON=1 ../ chdir=/opt/nheqminer/nheqminer/build | |
when: flag_avx and not flag_avx2 | |
- name: Cmake with default flags | |
command: cmake ../ chdir=/opt/nheqminer/nheqminer/build | |
when: not flag_avx and not flag_avx2 | |
- stat: path=/opt/nheqminer/nheqminer/build/nheqminer | |
register: st_nheqminer | |
- name: Building | |
command: "{{item}} chdir=/opt/nheqminer/nheqminer/build" | |
with_items: | |
- rm -f /usr/bin/nheqminer | |
- make clean | |
- make -j{{ansible_processor_vcpus}} chdir=/opt/nheqminer/nheqminer/build | |
when: gitclone.changed or not st_nheqminer.stat.exists | |
- name: Copy supervisor file | |
copy: | |
content: "{{ nheqminer_supervisor }}" | |
dest: /etc/supervisor/conf.d/nheqminer.conf | |
notify: | |
- reload supervisor config | |
- name: Install zcash_stat.sh scripts | |
copy: | |
content: "{{ script_stat_mining }}" | |
dest: /usr/bin/zcash_stat.sh | |
mode: 0755 | |
notify: | |
- reload supervisor config | |
- name: Copy binary | |
copy: remote_src=True mode=0755 src=/opt/nheqminer/nheqminer/build/nheqminer dest=/usr/bin/nheqminer | |
notify: | |
- restart nheqminer | |
handlers: | |
- name: restart supervisor | |
service: name=supervisor state=restarted | |
- name: reload supervisor config | |
command: "{{item}}" | |
with_items: | |
- supervisorctl reload | |
- name: restart nheqminer | |
supervisorctl: name=nheqminer state=restarted | |
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
--- | |
- hosts: [miner_zcash] | |
become_method: sudo | |
become_user: root | |
become: true | |
tasks: | |
- name: Stopping nheqminer | |
supervisorctl: name=nheqminer state=stopped | |
- name: Removing files | |
file: | |
state: absent | |
path: "{{ item }}" | |
with_items: | |
- /opt/nheqminer | |
- /usr/bin/nheqminer | |
- /etc/supervisor/conf.d/nheqminer.conf | |
notify: | |
- reload supervisor config | |
handlers: | |
- name: reload supervisor config | |
command: "{{item}}" | |
with_items: | |
- supervisorctl reread | |
- supervisorctl update |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment