Skip to content

Instantly share code, notes, and snippets.

@bmatthewshea
Last active May 9, 2021 21:38
Show Gist options
  • Save bmatthewshea/9a062c092fd673318f8d208ce44f4f51 to your computer and use it in GitHub Desktop.
Save bmatthewshea/9a062c092fd673318f8d208ce44f4f51 to your computer and use it in GitHub Desktop.
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
@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

@bmatthewshea
Copy link
Author

bmatthewshea commented Dec 9, 2017

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

@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.

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