Here’s a quick post for anyone having issues with DDClient silently crashing when running as a daemon. I had this issue the other day, and only noticed it when my IP address had changed and all my sites disappeared.
Thankfully, cloudflare was able to keep most of my content online, but it raised the issue that if DDClient stops running, your server’s going to be very difficult to find should your IP change.
As it’s an intermittent issue, I can’t be sure if it’s a bug in DDClient itself, the version of Perl on my server, or the Cloudflare patch that’s the culprit. As it only happens once every couple of months at the moment, it’s not a huge priority. If I’m at home, where the OP-EZY server is hosted, I can just log in and start DDClient back up, but when I’m out, the only way to get things going would be to scan the IP range of my ISP for the server – slow, time consuming, and noisy (could be mistaken for a malicious attack). So, just to make things a little simpler, I’ve written this little bash script that will check if DDClient is running, and restart it if it isn’t:
pgrep ddclient > /dev/null
if [[ $rc != 0 ]] ; then
echo "DDClient doesn't appear to be running, attempting to restart it"
/usr/sbin/ddclient -daemon 300
For those interested, here’s a breakdown of the script:
- Line 1 just tells the system that this script should be run using bash.
- Line 3 checks for any program currently running with “ddclient” in the name (a bug in this script means you must not use a name like “ddclientcheck.sh” as it will give a false positive). Pgrep usually dumps the process number out to the terminal when it finds a matching process, to keep this silent, the output is forwarded to /dev/null.
- Line 4 saves the exit code of the previous command as a variable.
- The if statments on lines 5 to 8 checks if the exit code is anything but 0 (0 meaning everything’s ok), and if so, attempt to restart DDClient.
- Finally, line 9 makes the script finish with the same exit code that pgrep outputted.
I currently have this set to run every half hour with root privileges using Cron. The script is designed with Cron in mind, this means if DDClient is in fact running, the script will keep schtum so your inbox won’t get spammed with needless updates. The exit code is forwarded in case someone does want to modify it to show a message if things are ok, and use tools like Cronic to only let Cron email on error.
Hope this helps anyone with the same issue. Feel free to modify/improve this script to suit your needs. I’ll be interested to hear your comments.