Skip to content

Instantly share code, notes, and snippets.

@BenMorganIO
Created June 4, 2017 21:10
Show Gist options
  • Save BenMorganIO/9293fc731c45d363813432f4ede6a4b3 to your computer and use it in GitHub Desktop.
Save BenMorganIO/9293fc731c45d363813432f4ede6a4b3 to your computer and use it in GitHub Desktop.
Geth init.d script
#! /bin/sh
### BEGIN INIT INFO
# Provides: geth
# Required-Start: $local_fs $remote_fs
# Required-Stop:
# X-Start-Before: rmnologin
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Ethereum Mining
### END INIT INFO
NAME="geth"
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
set -e
. /lib/lsb/init-functions
start() {
printf "Starting '$NAME'... "
geth --etherbase '0x123456789' --mine >> /var/log/geth.log 2>&1 &
printf "done\n"
}
stop() {
printf "Stopping '$NAME'... "
[ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || \
while test -d /proc/$(cat /var/run/$NAME.pid); do
killtree $(cat /var/run/$NAME.pid) 15
sleep 0.5
done
[ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || rm /var/run/$NAME.pid
printf "done\n"
}
status() {
status_of_proc -p /var/run/$NAME.pid "" $NAME && exit 0 || exit $?
}
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment