Set Daemon For Geth
As sometimes , geth process will be killed by VPS system ,so we need to set daemon for geth processed.It's easy and suitable to set daemon in Linux OS, you may use [supervisor](http://supervisord.org)
We assume the source code go-etherzero is in directory /root amd geth is running by root user.
Write daemon.sh
CAUTION: you must replace the words 'your address' to your own rewards address.
cat << EOF > /root/daemon.sh
#!/bin/bash
source /etc/profile
source ~/.bashrc
jspid="ps aux | grep maxpeers | grep -v grep | awk '{print $2}'"
echo $jspid
if [ -z "\$jspid" ] ; then
echo $jspid
nohup ~/go-etherzero/build/bin/geth --maxpeers 50 --syncmode fast --masternode --etherbase "your address" > output.log 2>&1 &
else
echo "run normaly"
fi
EOF
Generating the miner.sh
echo -e " ~/go-etherzero/build/bin/geth attach --exec 'miner.start()' " > /root/miner.sh && chmod +x /root/miner.sh
set daemon.sh and miner.sh for execute miner start each minute
( crontab -l | { cat; echo "*/1 * * * * /bin/bash /root/daemon.sh & "; } ) | crontab - && ( crontab -l | { cat; echo "*/1 * * * * /bin/bash /root/miner.sh & "; } ) | crontab -
As the crontab is running by every minute ,so we need to set another shell script for each seconds to monitor the process,
Generating the second.sh.
#!/bin/bash
step=1 #time step for damon.sh
for ((i=0;i<60;i=(i+step)));do
/usr/bin/bash /root/damon.sh &
sleep $step
done
exit 0
Add second.sh instead of daemon.sh, to monitor geth process every one second
( crontab -l | { cat; echo "*/1 * * * * /bin/bash /root/second.sh & "; } ) | crontab - && chmod +x /root/second.sh
Last updated
Was this helpful?