I want monit to restart geth on crashes and send me alerts by email.
Here is what I'm trying to do.
My monit config at /etc/monit/conf.d/geth.cfg
# GETH
CHECK PROCESS geth with pidfile "/home/username/monit/geth.pid"
start program = "/bin/bash -c '/home/username/monit/geth.sh start'" as uid username as gid username
stop program = "/bin/bash -c '/home/username/monit/geth.sh stop'" as uid username as gid username
if not exist then alert
if not exist then restart
And the start/stop script /home/username/monit/geth.sh
#!/bin/bash
PID='/home/username/monit/geth.pid'
LOGS='/home/username/monit/geth.log'
KEYS='\--fast --rpc --rpcport 8545 --rpccorsdomain localhost --ipcpath /home/username/.ethereum/geth.ipc --cache=16'
case $1 in
start)
setsid geth "$KEYS" &> "$LOGS" &
echo $! > "$PID"
;;
stop)
cat "$PID"
kill -SIGINT `cat "$PID"`
rm "$PID"
;;
*)
echo "usage: geth.sh {start|stop}" ;;
esac
exit 0
I can run geth with sudo monit start geth, but monit cannot see geth's pid right. So it will not restart geth on crashes. The problems in my script:
- Cannot define geth's pid right. The geth.pid receives a process number which is higher by 2-4 numbers (e.g. 4678 instead of 4674).
- Cannot kill geth with -SIGINT, have to send -HUP signal instead.
I understand this is more like a Linux question, then Ethereum's, but I believe it may be very useful.
The closest howto's I found on geth monitoring are: