Skip to content

Instantly share code, notes, and snippets.

@gituser
Created May 24, 2016 16:05
Show Gist options
  • Save gituser/1f98bdd4ac0183f42b400ae48d1f8317 to your computer and use it in GitHub Desktop.
Save gituser/1f98bdd4ac0183f42b400ae48d1f8317 to your computer and use it in GitHub Desktop.
gethd for debian wheezy /etc/init.d/gethd
#! /bin/sh
### BEGIN INIT INFO
# Provides: gethd_product
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts ethereum-go geth in daemon mode
# Description: starts ethereum-go geth in daemon mode
### END INIT INFO
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Installation
# - Move this to /etc/init.d/gethd_product
# - chmod +x this
# - change PIDFILE and LOGFILE
#
# Starting and stopping
# - Start: `service gethd_product start` or `/etc/init.d/gethd_product start`
# - Stop: `service gethd_product stop` or `/etc/init.d/gethd_product stop`
PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=gethd_product
DESC="Daemon for ethereum"
PIDFILE="/var/run/${NAME}.pid"
DAEMON="/home/ethereum/geth"
DATADIR="/home/ethereum/.ethereum"
LOGFILE="/home/ethereum/.ethereum/production.log"
IPCPATH="/home/ethereum/.ethereum/geth.ipc"
#6 for verbose, 3 default
LOG_VERBOSITY=3
PORT=50099
RPCHOST="127.0.0.1"
RPCPORT=9966
RPCAPI="db,eth,net,web3,personal"
DAEMON_OPTS="--ipcpath $IPCPATH --datadir $DATADIR --port $PORT --rpc --rpcaddr $RPCHOST --rpcport $RPCPORT --rpcapi $RPCAPI --verbosity $LOG_VERBOSITY --logfile $LOGFILE"
CHUID="ethereum:ethereum"
if [ ! `id -u` -eq 0 ]; then
echo "you are not root";
exit 1;
fi
if [ ! -e "$LOGFILE" ]; then
touch $LOGFILE
chown $CHUID $LOGFILE
else
chown $CHUID $LOGFILE
fi
START_OPTS="--start --background --make-pidfile --pidfile ${PIDFILE} --chuid ${CHUID} --no-close --exec ${DAEMON} -- ${DAEMON_OPTS}"
STOP_OPTS="--stop --pidfile ${PIDFILE}"
test -x $DAEMON || exit 0
set -e
case "$1" in
start)
echo -n "Starting ${DESC}: "
# Close STDOUT file descriptor
start-stop-daemon $START_OPTS >>$LOGFILE 2>>$LOGFILE
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon $STOP_OPTS
echo "$NAME."
rm -f $PIDFILE
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon $STOP_OPTS
sleep 1
start-stop-daemon $START_OPTS >> $LOGFILE 2>>$LOGFILE
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment