Converting a (ddclient) startup command to launchdaemon plist

Configuration: Mac Mini 10.9 with Server.app.


My server has an internet connection with dynamic IP, and I am updating DDNS server with ddclient.

Currently I have the following line appended to /etc/rc.common so it boots up and updates every 300 seconds.


/usr/sbin/ddclient/ddclient -daemon=300 -verbose -noquiet

This command needs to run as root.


I understand this is not the best practice but I have no idea how to convert this to a launchdaemon plist, can anyone shed some light on this for me?


Thanks!

Mac mini, OS X Mavericks (10.9), with Server.app

Posted on Nov 7, 2013 3:25 PM

Reply
6 replies

Nov 7, 2013 7:15 PM in response to burnduck

ddclient looks like it wants to be a continuously running daemon that handles its own periodic checks, so all you need launchd to do is launch it at startup and keep it running. So I think you want the following plist saved in /Library/LaunchDaemons/user.ddclient.updater.plist (the file name is a convention, not a necessity).


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>Label</key>

<string>user.ddclient.updater</string>

<key>ProgramArguments</key>

<array>

<string>/usr/sbin/ddclient/ddclient</string>

<string>-daemon=300</string>

<string>-verbose</string>

<string>-noquiet</string>

</array>

<key>KeepAlive</key>

<dict>

<key>NetworkState</key>

<true/>

</dict>

</dict>

</plist>


when the plist is loaded into launchd it will keep ddclient running as long as the network is up.


If I've misread the ddclient options and you need to get launchd to run ddclient periodically that's easy enough; let me know.

Nov 8, 2013 3:01 AM in response to twtwtw

Thanks for the prompt reply, it worked beautifully but I have one quick follow up question.


I tried putting the plist in /Library/LaunchDaemons, also chown'd it to root:wheel.


When I restart the machine I can't seem to find the process in (ps aux | grep "ddclient")?


However launchctl says this plist is already loaded,


mms:LaunchDaemons edmondsiu$ sudo launchctl load org.ddclient.cloudflare.updater.plist

Password:

user.ddclient.updater: Already loaded


I can see it doing something in syslog, which is the only way for me to tell it's loaded.


I am just wondering if there's a proper way to check whether it's actually running? (Which also applied to other launchdaemons which might not syslog as frequently?)


Thanks again!


Message was edited by: burnduck

Nov 8, 2013 4:15 AM in response to burnduck

Well, I don't normally use ps; if I want info on a process I use Activity Monitor.app. But I'll point out that you seem to be using outdated syntax. See man ps, particularly the section at the bottom called Legacy Description.


If you run sudo launchctl list | grep ddclient you should see output like xxxx x ddclient if the job is loaded properly. The first field is the pid of the running process, or a hyphen if the process is not running. The second field is the exit code of the process' last run.

Nov 8, 2013 9:20 AM in response to twtwtw

I have just noticed one thing regarding running ddclient this way, launchctl seem to be restarting the process as soon as it's exited. Currently it's being throttled to 10 seconds by the system, it doesn't seem to obey the -daemon=300 flag?


I have had a look at KeepAlive and took out the NetworkState key but doesn't seem to have made a difference. 😕


Any tips on this?



mms:LaunchDaemons edmondsiu$ sudo launchctl list | grep ddclient

- 0 org.ddclient.cloudflare.updater

Nov 8, 2013 9:57 AM in response to burnduck

I have made some changes to plist, as ddclient seem to try and act as daemon by itself which (i guess) might have clashed with launchd's keepalive. (please correct me if i'm wrong).


I am currently settling with the following plist, which I believe launchd will run every 5 minutes.

Kind of a trial and error, please let me know if there's anything I can do to further optimise it. 🙂


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>Label</key>

<string>org.ddclient.cloudflare.updater</string>

<key>ProgramArguments</key>

<array>

<string>/usr/sbin/ddclient/ddclient</string>

<string>-verbose</string>

<string>-noquiet</string>

</array>

<key>StartInterval</key>

<integer>300</integer>

</dict>

</plist>

Nov 8, 2013 11:12 AM in response to burnduck

that's the way I would do it if I didn't want it to run as daemon (allowing launchd to run it on a time schedule). If you do want to run it as a daemon you could try this (removes the KeepAlive key and adds a RunAtLoad key, on the theory that simpler is better):


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>Label</key>

<string>user.ddclient.updater</string>

<key>ProgramArguments</key>

<array>

<string>/usr/sbin/ddclient/ddclient</string>

<string>-daemon=300</string>

<string>-verbose</string>

<string>-noquiet</string>

</array>

<key>RunAtLoad</key>

<true/>

</dict>

</plist>


If what you have works, though, then there's no real need to mess with it.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Converting a (ddclient) startup command to launchdaemon plist

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.