StartupItems
The second mechanism, though now legacy, is still responsible for starting many system and network daemons. During system startup, the SystemStarter application scans and runs special scripts kept in /Library/StartupItems/. If you’ve installed a daemon yourself and wish to have it launch at startup and be owned by the root user (so that it is running when the first user logs in, and continues to run until the machine is shut down or it’s explicitly killed), add another item to this collection of startup items or copy or modify an existing one, if applicable. (More startup scripts are in /System/Library/StartupItems/, but, like everything else in the /System/ folder, are not meant to be messed with.)
Each object under StartupItems is a folder named after its function. Inside it are two important files: a parameter list of options in StartupParameters.plist and the script itself, which must have the same name as the folder.
Example 11-1 shows a simplified version of the contents of the Apache startup item (/System/Library/StartupItems/Apache /Apache).
[1]#!/bin/sh ## # Apache HTTP Server ##[2]/etc/rc.common[4]StartService () { if [ "${WEBSERVER:=-NO-}" = "-YES-" ]; then echo "Starting Apache web server" if [ ! -e /etc/httpd/httpd.conf ] ; then cp -p /etc/httpd/httpd.conf.default /etc/httpd/httpd.conf fi apachectl start fi }[5]StopService () { echo "Stopping Apache web server" apachectl stop }[6]RestartService () ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access