joraff
joraff

Reputation: 1007

LaunchDaemon handling system shutdown - no SIGTERM?

I've written a small python script that I'm running as a LaunchDaemon to record startup/shutdown times to a remote database. When the script launches it records the startup time, then pauses and waits to catch SIGTERM to record the shutdown time. An almost identical workflow is being used as a LaunchAgent for login/logout times.

However, it appears that Apple's Sudden Termination mechanism is throwing a wrench into things. It appears that when the machine is shutdown or restarted, launchd is only sending a SIGKILL signal to the launchdaemons and launchagents, which cannot be handled. I may be wrong in the technicalities, but that's essentially what I'm experiencing..

Manually loading/unloading the daemon with launchctl triggers the SIGTERM handler. However, that same code is not triggered when real system shutdown occurs.

Does anyone have a recommendation on how to prevent a SIGKILL?

Upvotes: 2

Views: 2796

Answers (1)

Gordon Davisson
Gordon Davisson

Reputation: 125838

If I'm reading this right, it shouldn't use sudden termination on daemons unless you have <key>EnableTransactions</key><true/> in the launchd plist. But the docs are a little vague, so I'd also try adding <key>EnableTransactions</key><false/> to the plist, or if that doesn't work call vproc_transaction_begin from your program (I assume you can call it from python, but I don't know the mechanics).

Upvotes: 5

Related Questions