I haven't seen a comprehensive post on how to create your own OSX global StartupItems, so I decided to write a guide:
I use StartupItems for two purposes:
- autossh tunnel, as a portable security prevention method
- synergy+ remote control for my MacMini media center
A few things have changed since earlier versions of OSX, but lets just go over the whole process of setting it up, using autossh as an example (replace autossh with the name of your service)
- You'll need root access to create items in /Library/StartupItems - so be sure you have administrative privileges, and open up a Terminal window.
- Under /Library/StartupItems you'll create a structure like this:
drwxr-xr-x 4 root wheel 136 Mar 7 09:59 autossh
$ cd autossh/
$ ls -la
-rw-r--r-- 1 root wheel 563 Mar 6 23:29 StartupParameters.plist
-rwxr-xr-x 1 root wheel 156 Mar 7 09:59 autossh - StartupParameters.plist looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>Description</key>
<string>AutoSSH Tunnel</string>
<key>Messages</key>
<dict>
<key>start</key>
<string>Starting AutoSSH Tunnel</string>
<key>stop</key>
<string>Stopping AutoSSH Tunel</string>
</dict>
<key>OrderPreference</key>
<string>Last</string>
<key>Provides</key>
<array>
<string>autossh</string>
</array>
<key>Uses</key>
<array>
<string>Network</string>
</array>
</dict>
</plist> - autossh itself (as referenced in StartupParameters.plist) contains the code to execute. In my example it is:
#!/bin/sh
. /etc/rc.common
ConsoleMessage "Starting ssh tunnel"
/opt/local/bin/autossh -f -M 6661 -N -R 8823:localhost:22 -D 8080 username@hostname - Two very important steps remain. chown -R root:wheel /Library/StartupItems and running this command for each item under /Library/StartupItems:
sudo xattr -r -d com.apple.quarantine /Library/StartupItems/autossh
Your item will now not be quarantined on reboot. Enjoy!