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.
2 Answers
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.)
Script explanation
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
/home/pi/run_forever.sh
- 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:
/home/pi/run_forever.sh
-
it says deluge-gtk: not found. i use deluged command to open deluge. will this cause a problem while it is a infinite loop? Mar 24, 2014 at 19:33
-
After typing "deluged" Does your terminal block? If the answer is yes, then you are safe doing this. Mar 24, 2014 at 19:53
-
no it is not. i understood your approach. i will search a command that runs deluge without exiting the loop. thanks. Mar 24, 2014 at 19:59
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
Update
An alternative could be as simple as putting this into the crontab -
* * * * * pidof deluge > /dev/null || deluge
-
i think double parenthesis "[[" causes an error. however i tried one parenthesis and if condition being executed always whether deluge is on run or not. Mar 24, 2014 at 19:38
-
-
-
-