Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question
    
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. My guess is that files there will be run at shutdown. –  Harald Hanche-Olsen Feb 25 '12 at 10:44
    
just please put this comment in ur answer, I will accept it. –  rubixibuc Feb 25 '12 at 10:53
1  
Your wish is my ⌘. –  Harald Hanche-Olsen Feb 25 '12 at 14:43
add comment

1 Answer

up vote 2 down vote accepted

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>
share|improve this answer
    
That's really cool :-). +1. I'm really looking for info on those files though, because I'm trying to get a better understanding of what happened to those files and if they still work. Some people use rc.shutdown.local, and it's in a lot of tutorials and I want to know if I can still apply those to lion. –  rubixibuc Feb 25 '12 at 10:35
    
I'm going to accept ur answer just put the comment in the answer :-) –  rubixibuc Feb 25 '12 at 10:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.