Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
start-stop-daemon service for ethminer binary
#!/bin/sh
### BEGIN INIT INFO
# Provides: ethminer
# Required-Start: $remote_fs $syslog $network $named
# Required-Stop: $remote_fs $syslog $network $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: ethminer start-stop-daemon init script
# Description: This allows you to start/stop ethminer as if it
# were a daemon
### END INIT INFO
# Author: Brady Shea <use@github-comments>
# Source: https://gist.github.com/bmatthewshea/9a062c092fd673318f8d208ce44f4f51
set -e
. /lib/lsb/init-functions
# Default Settings - Edit /etc/default/ethminer instead: https://gist.github.com/bmatthewshea/be95abefb0d535afeba7aa0cb680fa08
RUNAS="ubuntu"
DAEMON="/opt/miners/ethminer"
GPU="-U"
FARM_RECHECK="200"
WALLET="4e06e4080E6043dfF23c8b634712Aca2e1DE4347"
WORKER="myworkername"
SERVERS="us1.ethermine.org:4444"
FSERVERS="us2.ethermine.org:4444"
STRATUMCLIENT="1"
STRATUMPROTO="0"
LOGFILE="/var/log/miners/ethminer.log"
# pool, proxy, solo :
MINING_MODE="pool"
# For setting user defaults please use this file when possible. If it exists it can override anything above.
# -> https://gist.github.com/bmatthewshea/be95abefb0d535afeba7aa0cb680fa08 for an example.
if [ -r /etc/default/ethminer ]; then
. /etc/default/ethminer
fi
## DAEMON FLAGS/LINE OPTIONS - USER EDITABLE -> CAREFULLY - "-HWMON" (v13 dev version) can safely be removed if you get error ##
if [ "$MINING_MODE" = "pool" ]; then
# Running Stratum Pool connection (-S)
DAEMON_OPTS="$GPU -HWMON --farm-recheck $FARM_RECHECK -SC $STRATUMCLIENT -SP $STRATUMPROTO -S $SERVERS -FS $FSERVERS -O $WALLET.$WORKER"
else
# Running ETH-PROXY or SOLO mining - Set to farm mode (-F)
DAEMON_OPTS="$GPU -HWMON --farm-recheck $FARM_RECHECK -SC $STRATUMCLIENT -SP $STRATUMPROTO -F $SERVERS"
fi
## NO USER SETTINGS PAST HERE ##
DESC="ethminer start-stop-daemon init script"
NAME=ethminer
PIDFILE=/var/run/$NAME.pid
start() {
printf "Starting '$NAME'..."
start-stop-daemon --chuid $RUNAS --start --quiet --make-pidfile --pidfile $PIDFILE --background --startas /bin/bash -- -c "exec $DAEMON $DAEMON_OPTS > $LOGFILE 2>&1"
sleep 1
printf "Done."
}
stop () {
printf "Stopping '$NAME'..."
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
sleep 1
printf "Done."
}
status() {
# status_of_proc -p /var/run/$NAME.pid "" $NAME && exit 0 || exit $?
status_of_proc $DAEMON "$NAME"
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo "Usage: $NAME {start|stop|restart|status}" >&2
exit 1
;;
esac
exit 0
@bmatthewshea
Copy link
Author

bmatthewshea commented Oct 24, 2017

(Debian/Ubuntu Example)

  1. Copy this start script to /etc/init.d/ethminer (above) :
    https://gist.github.com/bmatthewshea/9a062c092fd673318f8d208ce44f4f51

  2. (optional, but recommended) Copy this script to /etc/default/ethminer and edit it (your settings).
    https://gist.github.com/bmatthewshea/be95abefb0d535afeba7aa0cb680fa08

  3. Update top portion of script or preferably update/the defaults file (#2).

  4. Execute:

# user you run this under - the log area needs to be owned by that user ('ubuntu' user example):
sudo mkdir /var/log/miners && sudo chown ubuntu:adm /var/log/miners

sudo chown root:root /etc/init.d/ethminer && sudo chown root:root /etc/default/ethminer
sudo chmod 755 /etc/init.d/ethminer && sudo chmod 644 /etc/default/ethminer
sudo update-rc.d  ethminer defaults
sudo update-rc.d  ethminer enable
sudo systemctl daemon-reload

And finally, start the miner:
sudo service start ethminer
or
sudo systemctl start ethminer.service

  1. Monitor:
    tail -f /var/log/miners/ethminer.log
    (You can check output..)
    Please see this: https://gist.github.com/bmatthewshea/6bad5242dbf270ef881c033918b947c0 for a way to monitor this service for inactivity.

  2. Stop/Start/Restart with:
    sudo service ethminer stop
    or
    sudo systemctl stop ethminer.service

Loading

@aptalca
Copy link

aptalca commented Dec 7, 2017

FYI, If one is not using the optional settings, one also has to set the "FSERVERs" variable in the start script, otherwise the ethminer script fails

Loading

@bmatthewshea
Copy link
Author

bmatthewshea commented Dec 9, 2017

@aptalca - Thanks. I re-added it. Typo. Better off using the '/etc/default/', file though..

Loading

@mrbrendanhamm
Copy link

mrbrendanhamm commented Apr 1, 2018

Right before step 5 you say use:
sudo service start ethminer
it should be
sudo service ethminer start

Otherwise, this is great! I did make some modification to my monitor such that it checks temps as well and stops if too hot and restarts if too cold. I found some random errors would not cause the miner to stop writing to the log file, even though it clearly stopped mining and the GPU would get cold.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment