-1

I wrote a simple script to check if the deluge daemon is running and if not to restart it:

#!/bin/bash
if [[ $(pidof deluged | wc -1) -eq 0 ]]; then
    deluged
fi

I added it to scheduled job on cron to make it run every 5 minutes...everything works fine; if I kill the deluge daemon (deluged), my script restarts it correctly.

My problem is that:

I'm using deluge to download torrents, but sometimes it loses the connection with the localhost (127.0.0.1) and periodically I have to check if it still running.  How can I improve the above code to automatically reconnect to the host?

1
  • To answer this question, a lot would have to be known about the daemon's behavior when not connected to localhost. While in theory a check of netstat or /proc MIGHT reveal the symptoms, the daemon itself really needs to handle its error conditions better. I didn't give the downvote, but this question really needs to be improved as it is too vague in its requirements.
    – kmarsh
    Nov 5 '15 at 15:04
0

you can make this a lot simpler.

pidof deluged || deluged

For the second question, if it logs a message, you can probably read that in ?

0

Rather than restart the service continuously it might be useful to look for the root cause of the crashes and fix that.

Do you happen to run deluge on an ARM based device like a raspberry pi? A quick google search shows that these crashes are fairly common in that setup.

This blog has a workaround you could try.

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.