3

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.

4

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.

  • 1
    Thanks for the reply. Thankfully we have been able to restore from a timemachine backup server, we forgot we set it up ages ago, and that should hopefully fix the issue. If it doesn't I'll give your answer a try – Niuyoi Sep 28 '15 at 12:54
  • 1
    @Niuyoi I hope it's a recent backup... – klanomath Sep 28 '15 at 12:56
0

You might need a USB drive to fix this if you don't have a full system backup.

  1. Boot to recovery or internet recovery
  2. Use disk utility on recovery to partition the USB/prepare for OS X installation into the USB.
  3. Use recovery to install OS X onto the USB
  4. Boot from USB and then back up the files from the main drive you can't afford to lose.
  5. Download the OS installer for your broken system and run it to repair the system changes.
0

Recovery System

Your best option is to use OS X's Recovery System.

To start your computer from Recovery, restart your Mac and hold down the Command + R keys at startup:

OS X: About OS X Recovery

OS X Lion and later include OS X Recovery. This feature includes all of the tools you need to reinstall OS X, repair your disk, and even restore from a Time Machine backup.

Alternatively, Single User Mode or Target Disk Mode are possibilities.

Single User Mode

Trying booting into single user mode, How to start up your Mac in single-user or verbose mode.

Within single user mode find and remove the plist files that are telling launchd not to load these jobs.

klanomath's answer contains instructions for editing the persistent launchd state file /var/db/com.apple.xpc.launchd/disabled.plist.

Target Disk Mode

Another option is to use Target Disk Mode to access your Mac's files. In this mode, you will be able to find and remove the plist files that are telling launchd not to load these jobs.

  • Hi Graham, I just tried this and when I executed the command the screen went black then a message saying "there was an error and you need to restart your computer, press any key or wait" It's trying to boot up again but the loading bar still isn't going past half way – Niuyoi Sep 28 '15 at 10:12
  • I have added notes about OS X's recovery system. Alternatively, you can try target disk mode? – this will effectively turn the Mac into an external drive. Hope this helps! – Graham Miln Sep 28 '15 at 10:18
  • 1
    Installing OSX on top of the "broken system" via recovery is a viable one step solution. It is designed to preserve user accounts and data, but I prefer a two step process that allows a backup in case it's not up to date. – bmike Sep 28 '15 at 10:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .