Are rc.shutdown and rc.shutdown.local still usable on OS X Lion?

Are either of rc.shutdown or rc.shutdown.local still being use in OS X, or have they been replaced with something else?

I realize that launchd is replacing most of this, but I thought you could still use rc.shutdown.local to run a script.

I couldn't even find rc.shutdown anywhere on my system.


I have no idea, really. There is a mention of /etc/rc.shutdown.local in /System/Library/LaunchDaemons/com.apple.SystemStarter.plist, but I am not at all sure what it means. The manual page for SystemStarter is not a great help, beyond informing us that it is deprecated. The program is running on my system, though. Oh, and the string /etc/rc.shutdown.local is found inside the SystemStarter binary as well. My guess is that files there will be run at shutdown.

But if I may answer your implicit question of how to run something at shutdown: Here is what I have done. First, I wrote and compiled this little C program. What it does is simply to sleep until it receives a SIGTERM, at which point it exec's its arguments:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

char **args;

void sigterm(int s) {
  execvp(args[1],args+1);
  fprintf(stderr, "%s: exec failed: ", args[0]);
  perror(args[1]);
  exit(1);
}

int main(int argc, char *argv[]) {
  args=argv;
  signal(SIGTERM,sigterm);
  for (;;) sleep(0x7FFFFFFF);
}

I have a launch daemon set up to run this program at startup. Come shutdown time, launchd will send the SIGTERM that causes the program to do its thing. Of course, it has to do so fairly quickly, or launchd will apply a bigger sledgehammer.

Here is my launchctl plist, named no.ntnu.math.hanche.quietboot.plist and placed in /Library/LaunchDaemons/. Its sole purpose is to run `nvram SystemAdioVolume=%01' at shutdown, so I can reboot without the chime.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>no.ntnu.math.hanche.quietboot</string>
    <key>ProgramArguments</key>
    <array>
        <string>/local/bin/atshutdown</string>
        <string>/usr/sbin/nvram</string>
        <string>SystemAudioVolume=%01</string>
    </array>
    <key>Disabled</key>
    <false/>
    <key>KeepAlive</key>
    <false/>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>