Since startup items and rc
commands are both deprecated (and in many cases not working at all) on OS X in favour of launchd
, I'd like to find out what the correct way would be to setup a shell script that runs on logout/shutdown.
For a startup item it was possible to create a shell script that looked something like:
#!/bin/sh
StartService() {
echo "Started."
}
StopService() {
echo "Stopped."
}
RunService "$1"
But the RunService
command isn't supported when running a script from launchd
, and I'm not sure it's meant to be used anymore anyway.
If possible, I'd like to create a shell script that will be provided to launchd
as an on-demand service that will be started near to shutdown and somehow informed that the system is shutting down.
Alternatively, I may need a shell script that is opened on login/system start and remains running (or rather, asleep) until a SIGTERM
or other kill signal is received, so that it can run some commands before closing.