d
d
doc
Search…
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.
1
cat << EOF > /root/daemon.sh
2
#!/bin/bash
3
source /etc/profile
4
source ~/.bashrc
5
jspid="ps aux | grep maxpeers | grep -v grep | awk '{print $2}'"
6
echo $jspid
7
if [ -z "\$jspid" ] ; then
8
echo $jspid
9
nohup ~/go-etherzero/build/bin/geth --maxpeers 50 --syncmode fast --masternode --etherbase "your address" > output.log 2>&1 &
10
else
11
echo "run normaly"
12
fi
13
EOF
Copied!
    Generating the miner.sh
1
echo -e " ~/go-etherzero/build/bin/geth attach --exec 'miner.start()' " > /root/miner.sh && chmod +x /root/miner.sh
Copied!
    set daemon.sh and miner.sh for execute miner start each minute
1
( crontab -l | { cat; echo "*/1 * * * * /bin/bash /root/daemon.sh & "; } ) | crontab - && ( crontab -l | { cat; echo "*/1 * * * * /bin/bash /root/miner.sh & "; } ) | crontab -
Copied!
    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.
1
#!/bin/bash
2
step=1 #time step for damon.sh
3
for ((i=0;i<60;i=(i+step)));do
4
/usr/bin/bash /root/damon.sh &
5
sleep $step
6
done
7
exit 0
Copied!
    Add second.sh instead of daemon.sh, to monitor geth process every one second
1
( crontab -l | { cat; echo "*/1 * * * * /bin/bash /root/second.sh & "; } ) | crontab - && chmod +x /root/second.sh
Copied!
Last modified 2yr ago
Copy link