[launchd-dev] KeepAlive / NetworkState

Keith Mountin mountin at mac.com
Sat Mar 28 04:48:49 PDT 2009


I am working on a launchd script to keep VNC alive.  We are having  
difficulty using the KeepAlive key with NetworkState.

According to the man pages:

KeepAlive <boolean or dictionary of stuff>

This optional key is used to control whether your job is to be kept
continuously running or to let demand and conditions
control the invocation. The default is false and therefore only demand
will start the job. The value may be set to true to
unconditionally keep the job alive. Alternatively, a dictionary of
conditions may be specified to selectively control
whether launchd keeps a job alive or not. If multiple keys are provided,
launchd ORs them, thus providing maximum flexibil-
ity to the job to refine the logic and stall if necessary. If launchd
finds no reason to restart the job, it falls back on
demand based invocation. Jobs that exit quickly and frequently when
configured to be kept alive will be throttled to con-
verve system resources.

SuccessfulExit <boolean>

If true, the job will be restarted as long as the program exits and with
an exit status of zero. If false, the job
will be restarted in the inverse condition. This key implies that
"RunAtLoad" is set to true, since the job needs to
run at least once before we can get an exit status.

NetworkState <boolean>

If true, the job will be kept alive as long as the network is up, where
up is defined as at least one non-loopback
interface being up and having IPv4 or IPv6 addresses assigned to them.
If false, the job will be kept alive in the
inverse condition.

But if I use

	<key>KeepAlive</key>
	<dict>
		<key>NetworkState</key>
		<true/>
	</dict>

I get

   "Unknown key for boolean: NetworkState"

Does launchd actually support

	<key>KeepAlive</key>
	<dict>
		<key>NetworkState</key>
		<true/>
	</dict>

Thank you,

Keith



More information about the launchd-dev mailing list