0

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

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

  1. 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
  2. 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? – user3160302 Mar 24 '14 at 19:33
  • After typing "deluged" Does your terminal block? If the answer is yes, then you are safe doing this. – Hello World Mar 24 '14 at 19:53
  • no it is not. i understood your approach. i will search a command that runs deluge without exiting the loop. thanks. – user3160302 Mar 24 '14 at 19:59
0

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. – user3160302 Mar 24 '14 at 19:38
  • What error ? I tested it on a debian machine and it worked – Lawrence Mar 25 '14 at 1:14
  • it says checkdeluge.sh: 2: checkdeluge.sh: [[: not found – user3160302 Mar 25 '14 at 14:23
  • What shell are you running ? and what Distro ? – Lawrence Mar 26 '14 at 2:44
  • i am using terminal of os X and debian as distro – user3160302 Mar 26 '14 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.