Posted on 12-10-2015 09:10 AM
I'm curious if there is a generic method [or generally recommended method] of installing a launch daemon onto a Mac, using Casper. (Specifically I need to use a daemon to launch a command at specific times/dates as root.)
Since the launch daemon is essentially a PLIST file, I think it's a bit overkill to create a package that just has the PLIST in it, upload it to Casper and deliver that with a policy.
I was thinking that a script within Casper could write the PLIST on demand (clever scripting could accept variables to have a generic "write basic launchd" script), but I was curious to know if anyone else has had to deal with pushing out launchd (or launch agents for that matter).
Posted on 12-10-2015 09:26 AM
Generally I package up the LaunchDaemon and deploy it, along with a postinstall script that activates the launchd job. The latter piece is easy for LaunchDaemons since root can enable the Daemon. Its a bit tougher when talking about LaunchAgents, since those have to be activated by a logged in user.
If you don't want to package it up, then yes, its possible to write out a LaunchDaemon, complete with variable information for some of the strings or other data in it. Search around here and you will find examples on how some folks are doing it.
If you can't locate anything after searching, you can take a look at one of my scripts here to see how I'm doing it. It starts at line 137 to save you the trouble of finding it.
Since I wrote this, I found there are slightly better methods of writing the plist out, but the way I've done it there does work well enough.
Posted on 12-10-2015 11:40 AM
I've done both.
But a pkg with a post install to load it is great for "set & forget".
Posted on 12-10-2015 11:51 AM
LaunchDaemon usually includes whatever it is going to call as well, such as an associated script, for me most of the time it's just simpler to package and deploy.
Posted on 12-10-2015 11:56 AM
Actually @Look has made a good point. If the ProgramArgument in the launchd plist will be calling a separate script local on the machine, that needs to be deployed as well. It would be easier in this case to package them both up along with the post install activation, than try writing out both the LaunchDaemon and the script from another script. Its not impossible, but can overly complicate things unless the script and/or Daemon must be custom created for each Mac. In that case, it might make more sense.
Posted on 12-10-2015 04:05 PM
I always package the dameon and the script up with a post install to activate the daemon for the first time.
Posted on 12-14-2015 07:57 AM
Thanks for the responses.
I appreciate that if you have a script, then it makes sense to package the script and the plist. I was thinking about commands that didn't need a script (command and argument), but I guess it's best to package them up too.
Posted on 12-14-2015 08:03 AM
Well, if its only a LaunchDaemon with an embedded ProgramArgument in it, and no external script dependency, then you can certainly write it out to disk from a script. You do need to make sure to set the permissions and ownership correctly on the file. It should be set correctly in most cases when its done via a Casper Suite policy, but for good measure I would have chown and chmod commands follow the creation of the plist to make sure its set correctly, and then load it.
Additionally, I would first create the plist using something like LaunchControl or Lingon and test it to make sure it does what you want, then just copy the plist contents into your script that will create it so the syntax is all correct.