[launchd-dev] Why no key to "Run once on restart"

Jerry Krinock jerry at ieee.org
Mon May 23 15:15:04 PDT 2011


It seems that a fairly popular trigger would be a job that runs once, when the computer is restarted or user logs in.  But I don't see a key for this in launch.plist(5).

To get that effect, I'm using the two keys StartOnMount + LaunchOnlyOnce.  The former does the job because a filesystem must be mounted when a computer restarts, and the latter keeps it from starting multiple times in case another filesystem is mounted before it exits.  This works, but is indirect and kludgey.

Is there a better way to do this?

The reason I want to do this is to restart a syncing task which may take a minute or so and thus could be interrupted by system shutdown.  When my task begins, it loads this new "standby" StartOnMount+LaunchOnlyOnce agent to re-run the same task when the system starts up.  But when my task ends normally, it unloads this agent.  Therefore it only ever spawns if my task was interrupted.

Thank you,

Jerry Krinock



More information about the launchd-dev mailing list