Restoring Yosemite server after unloading launch daemons

So, while trying to fix a corrupt open directory I came across a fix that said to enter this command...

sudo launchctl unload -w /System/Library/LaunchDaemons/

org.openldap.slapd.plist

From the formatting I thought these were two separate commands but in fact they were one. As you can imagine after I typed in the "first command" my Mac Mini server shut down and restarted but the loading bar won't get past half way when it tries to boot.

Is there any way to restore the launch daemons after unloading them all? Any and all help is appreciated.


The command sudo launchctl unload -w /System/Library/LaunchDaemons/ disables all launch daemons residing in /System/Library/LaunchDaemons/ by adding a key with the name of the launch daemon followed by true in the file /var/db/com.apple.xpc.launchd/disabled.plist. Even if the launch daemon had an entry set to false (like com.apple.emond in the examples below) in the file previously, it will be set to true. The disabled.plist overrides all settings in the individual plist files. The single launch daemon plist files in /System/Library/LaunchDaemons/ won't be altered.

Example before the above command was issued:

<?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>com.apple.AppleFileServer</key>
    <true/>
    <key>com.apple.hdiejectd</key>
    <false/>
    <key>com.apple.emond</key>
    <false/>

Example after the above command was issued:

<?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>com.apple.AppleFileServer</key>
    <true/>
    <key>com.apple.afpfs_checkafp</key>
    <true/>
    <key>com.apple.AirPlayXPCHelper</key>
    <true/>
    <key>com.apple.applessdstatistics</key>
    <true/>
    <key>com.apple.auditd</key>
    <true/>
    ...
    <key>com.apple.emond</key>
    <true/>
    ...

So essentially you have to remove /var/db/com.apple.xpc.launchd/disabled.plist on your main volume or replace it by a backup copy:

  • Replacing the file by a backup copy is preferred because it may already have some non-default entries for some launch daemons set to true or false.
  • If you don't have a backup copy of the file boot to Recovery or Internet Recovery Mode
  • Open Terminal
  • mount your main volume if it's not already mounted
  • enter cd /Volumes/[Name_Of_Your_Main_Volume]/var/db/com.apple.xpc.launchd/ to change to your main volume
  • enter pwd to be sure about your working directory
  • remove disabled.plist with rm disabled.plist
  • To rebuild the (hopefully) standard disabled.plist write or copy and paste the following using nano or vi into a new document at the same place after executing touch disabled.plist:

    <?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>com.apple.emond</key>
        <false/>
        <key>org.postfix.master</key>
        <true/>
        <key>com.apple.ftpd</key>
        <true/>
        <key>com.apple.usbmuxd</key>
        <false/>
        <key>com.apple.emlog</key>
        <false/>
        <key>com.apple.mrt</key>
        <false/>
        <key>com.apple.stackshot</key>
        <false/>
        <key>org.apache.httpd</key>
        <true/>
    </dict>
    </plist>
    

    You may do this later also, after rebooting to your main volume with:

    sudo nano /var/db/com.apple.xpc.launchd/disabled.plist
    

    After the reboot the file should have been rebuilt automatically (but almost empty) and you don't have to create it first.

  • Enter exit
  • Reboot to your main volume

This worked for me (explicitly not executing the command launchctl load -w /System/Library/LaunchDaemons/ as proposed by Graham). So your mileage may vary, because you executed the command earlier.