Problem with startup `rc.local` script

Solution 1:

I was using those commands for VirtualBox in rc.local, and I ran into the same problem. I don't if this is the right way to do this, but it works for me.

I created /Library/LaunchDaemons/local.localhost.startup.plist containing the code below. It runs the rc.local script once at start up.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>             <string>local.localhost.startup</string>
    <key>Disabled</key>          <false/>
    <key>RunAtLoad</key>         <true/>
    <key>KeepAlive</key>         <false/>
    <key>LaunchOnlyOnce</key>    <true/>
    <key>ProgramArguments</key>
        <array>
            <string>/etc/rc.local</string>
        </array>
</dict>
</plist>

Solution 2:

That plist isn't quite right, so try the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>local.localhost.startup</string>
    <key>Disabled</key>
    <false/>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
    <key>LaunchOnlyOnce</key>
    <true/>
    <key>Program</key>
    <string>/bin/bash</string>
    <key>ProgramArguments</key>
        <array>
            <string>/etc/rc.local</string>
        </array>
</dict>
</plist>

Solution 3:

Also make sure that rc.local has the permission to execute, via a sudo chmod 755 /etc/rc.local

The LaunchDaemon does not explicitly report an error, so I was bitten by this until I changed permissions.

Solution 4:

Since Mac OS X 10.4, startup items such as /etc/rc.local file or /Library/StartupItems folder are deprecated in favour of launchd daemons and agents.source

Check Creating Launch Daemons and Agents documentation page for further details.

For example, here is the example which launches a daemon named hello, passing world as a single argument and instructs launchd to keep the job running:

<?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>com.example.hello</string>
    <key>ProgramArguments</key>
    <array>
        <string>hello</string>
        <string>world</string>
    </array>
</dict>
</plist>

There are two keys in the top level dictionary:

  • Label - uniquely identifies the job,
  • ProgramArguments - a value of an array of strings which represent the tokenized arguments and the program to run.

Here is the practical example to increase system resources.


The locations for startup daemons are /System/Library/LaunchDaemons and /Library/LaunchDaemons.

The location for startup agents are /System/Library/LaunchAgents, /Library/LaunchAgents and user’s individual Library/LaunchAgents folder.