Deluge torrent client crashes randomly. And i could not find the core reason. So are there any script that reopen a program when it is crashed. Or it can check is it working and if not runs that program.
I personally use this bash script:
while : do deluge-gtk #or whatever program you wish to run. sleep 2 done
Note: This does NOT work for non-blocking programs, instead it would launch them an infinite amount of time. (Deluge is fine.)
This is an infinite loop. Inside the loop the program runs, if the program crashes, the script will sleep for 2 seconds and then jump to the beginning of the program, hence restarting Deluge. The 2 second sleep is a fail-safe so that in case the program is crashing upon startup, your CPU doesn't get overloaded.
setting up the script in Raspberry Pi
- Copy the script above into a text editor such as leafpad and save it. In this example we will save it as
- execute the following in a terminal:
cd /home/pi chmod +x run_forever.sh
Your script is ready. to run it, type this in a terminal:
Alternatively do a check to see if the program is running before you run it
Save this file in
/opt/scripts/ as checkdeluge.sh for example.
#!/bin/bash if [[ $(pidof deluge | wc -l) -eq 0 ]]; then deluge # or whatever program here fi
Make the script executable -
chmod 755 /opt/scripts/checkdeluge.sh
Then add a cronjob to run this every minute with
crontab using the following line
* * * * * /opt/scripts/checkdeluge.sh
An alternative could be as simple as putting this into the crontab -
* * * * * pidof deluge > /dev/null || deluge