We were also talking about a similar program on the bitcointalk thread here:
https://bitcointalk.org/index.php?topic=421615.105600
It you want to use the process id, instead of the dash.pid file. Replace the if statement with this.
if [ -z `pidof dashd` ]; then
I like your idea of the dash.pid. With the process id it would change if it needed to restart, so your way should allow multiple restarts.
I think with your way you would need to leave your terminal window open for this to work. So I suggested using the screen command to run in the background. UdjinM6 suggested using a crontab. Details from bitcointalk:
Copy code below and paste into mn_watch.sh file. Type nano mn_watch.sh, paste with right click, and control x, y, enter to save. Change dashuser to your user name.
Code:
#!/bin/bash
#run with: screen -dm /mn_watch.sh
#stop with: screen -ls to find number and screen -X -S 11111 kill
while true; do
if [ -z `pidof dashd` ]; then
echo Dashd is not running trying to start
/home/dashuser/dashd
sleep 600
else
echo Dashd is Running
sleep 600
fi
done
type:
chmod +x mn_watch.sh
You can test it by running:
./mn_watch.sh
It will stop working as soon as you logout though, so we need to install screen to have it run in the background. Run this to install screen. (Assuming you are running Ubuntu.)
apt-get install screen
to start with screen type:
screen -dm /mn_watch.sh
This will run forever, so if you want it to stop type
screen -ls and get the number replace that with the 11111 below.
screen -X -S 11111 kill