Add your own boot command script to Mac OS X
If you have some things you want to start when your mac boots, here is how to do it. I use mine to start up an SSH keychain, start a mysql server and a memcached.
First, you’ll need to be root:
sudo tcsh
Now, make a directory for your stuff. Suppose your name is “Buffy.”
mkdir /Library/StartupItems/buffy
chown root /Library/StartupItems/buffy
chmod 755 /Library/StartupItems/buffy
You need to put two files in this directory. The first one is called StartupParameters.plist and should look like this:
{
Description = "buffy";
Provides = ("buffy");
Requires = ("Network");
OrderPreference = "Late";
Messages = {
start = "Starting buffy";
stop = "Stopping buffy";
};
}
If you were some of Darwin super guru, you could set all kinds of other options in here, but let’s pretend for now that you just want to save yourself remembering to type extra stuff after you reboot your mac.
OK, now you need to write the actual script to start things. name that file buffy
Here is an example:
#!/bin/sh
##
# buffy local stuff
##
. /etc/rc.common
StartService ()
{
ConsoleMessage "buffy startup"
# start postfix mail server
postfix start
# this is some weird stuff that only i'm interested in
# but I'm sure you have similar weird stuff
/r9/mysql1/bin/r9mysqld start
export EVENT_NOKQUEUE=1
# note the 'su' things so these process run as the 'buffy' user
su buffy -c '/usr/local/bin/memcached -d -m 128 -p 11211'
su buffy -c 'sh /Users/billo/bin/keychain'
}
StopService ()
{
ConsoleMessage "buffy shutdown"
/r9/mysql1/bin/r9mysqld stop
}
RestartService ()
{
StopService
StartService
}
RunService "$1"
Make sure the files you create are owned by ‘root’ otherwise OS X will ignore them.
March 26th, 2008 at 10:04 pm
You can use launchd to start a daemon at boot time in leopard. Browse the plist files in /System/Library/LaunchDaemons. Instead of a directory and several files, one need only write a single plist file to get the daemon started. ‘man launchd.plist’ for documentation.
June 22nd, 2008 at 10:25 pm
[...] A bit of investigation later and I came up with a solution, drawn from an excellent blog post on adding your own osx boot launch scripts, an archive script on launching cruise on unix init, and the tacit information in the MySQLCOM [...]