7

A Mac OS X Lion 10.7.5 server running Open Directory hung. SSH was still possible but the sudo reboot command didn't restart the server within 15 minutes. That is why a power cycle was issued. After the power cycle Open Directory would no longer start and the System log is filled with a new message every 10 seconds:

com.apple.launchd[1] (org.openldap.slapd[1153]): Exited with code: 1
com.apple.launchd[1] (org.openldap.slapd): Throttling respawn: Will start in 10 seconds

Repairing disk permission, neither another reboot doesn't solve the issue.

Slapd in Tool mode outputs:

$ sudo /usr/libexec/slapd -Tt
bdb(dc=nl2,dc=probackup,dc=nl): unable to allocate memory for mutex; resize mutex region
bdb_db_open: database "dc=nl2,dc=probackup,dc=nl" cannot be opened, err 12. Restore from backup!
backend_startup_one (type=bdb, suffix="dc=nl2,dc=probackup,dc=nl"): bi_db_open failed! (12)
slap_startup failed (test would succeed using the -u switch)

How to fix this?

4 Answers 4

14

Check if the OD database is the problem

$ sudo /usr/libexec/slapd -Tt

No further action is needed if the output tells something like:

...
bdb_db_open: database "dc=hostname,dc=domainname,dc=tldname": recovery skipped in read-only mode. Run manual recovery if errors are encountered.
...

Try repair

To repair the Open Directory authdata database:

$ sudo launchctl unload /System/Library/LaunchDaemons/org.openldap.slapd.plist

Now start the database recovery using the command below that matches your OS version.

$ sudo db_recover -h /var/db/openldap/authdata/ # Mac OS X 10.7
$ sudo db_recover -h /var/db/openldap/openldap-data/ # Mac OS X 10.6

Now slapd in tool mode outputs:

$ sudo /usr/libexec/slapd -Tt
bdb_db_open: database "dc=nl2,dc=probackup,dc=nl": unclean shutdown detected; attempting recovery.
bdb_db_open: database "dc=nl2,dc=probackup,dc=nl": recovery skipped in read-only mode. Run manual recovery if errors are encountered.
bdb_monitor_db_open: monitoring disabled; configure monitor database to enable
config file testing succeeded

Now turn back on Open Directory:

$ sudo launchctl load /System/Library/LaunchDaemons/org.openldap.slapd.plist

And issue another restart to be better safe than sorry:

$ sudo reboot

Open Directory should now be up and running again. In case it isn't running, try below.

Try Time Machine restore

First have a look at the available back-upped versions:

$ ls /Volumes/Time\ Machine/Backups.backupdb/*/

Pick the most recent version when Open Directory was still running correctly, for example 2018-07-22-091106.

Start again with unloading the daemon.

$ sudo launchctl unload /System/Library/LaunchDaemons/org.openldap.slapd.plist

Then remove (or rename) the database directory (when it is available Time Machine won't restore correctly) and start restore:

$ sudo rm -rf /var/db/openldap/ && sudo tmutil restore -v /Volumes/Time\ Machine/Backups.backupdb/*/2018-07-22-091106/Macintosh\ HD/var/db/openldap/ /var/db/

Force repair the database:

$ sudo db_recover -cv -h /var/db/openldap/openldap-data/

Repair permissions and reboot:

$ sudo diskutil repairPermissions / && sudo reboot
2
  • 2
    This approach didn't exactly do the trick for me, but it set me on the right track. I don't really know what I'm doing with LDAP administration, so YMMV, but after running this command, I was able to restart slapd and my data hadn't been lost: sudo db_recover -h /var/db/openldap/openldap-data/. It seems like a different BDB database structure associated with LDAP had been corrupted in my particular case, so may be worth investigating if the above doesn't work for you. Good luck! Apr 30, 2015 at 14:47
  • /var/db/openldap/authdata may also need to be recovered.
    – not2savvy
    Dec 13, 2021 at 10:44
6

This is how I usually repair a broken LDAP/OD

1. check if this is the problem

sudo /usr/libexec/slapd -Tt*

You might get: bdb_db_open: database "cn=authdata": db_open(/var/db/openldap/authdata/id2entry.bdb) failed: Invalid argument (22).

2. Stop LDAP on OD Master

sudo launchctl unload /System/Library/LaunchDaemons/org.openldap.slapd.plist

3. Repair Permissions

diskutil repairPermissions /

4. backup openldap db

sudo cp /var/db/openldap/authdata/id2entry.bdb /var/db/openldap/authdata/id2entry.bdb.backup

5. repair

sudo db_recover -cv -h /var/db/openldap/openldap-data/

6. run repair again to check

sudo db_recover -cv -h /var/db/openldap/openldap-data/

7. do it one more time so things are repaired correctly

sudo /usr/libexec/slapd -Tt

8. restart the service

sudo launchctl load /System/Library/LaunchDaemons/org.openldap.slapd.plist

9. If the above does not work, try:

sudo db_recover -cv -h /var/db/openldap/authdata/

then I restart the service with step 8.

sudo launchctl load /System/Library/LaunchDaemons/org.openldap.slapd.plist

This usually fixes the problem... but in some cases you need to restore like llange explaines in his post.

1
  • In my situation, using catastrophic recovery was key. It makes sense to try the normal recovery mode first, but it helps to understand what -c provides.
    – tim.rohrer
    Aug 30, 2017 at 18:02
1

First best is to check the disk you may do so either using the recovery partition or single user (cmd - S at startup) then type :

fsck -fy

QWERTY keyboard the dash is 2 key left from backspace.

To re-import a corrupted database from a backup you should backup and replace the following files/ folders :

  • var/db/openldap/
  • usr/bin/db_recover

Not sure it's necessary but if you have removed the LDAPv3 entry in the System keychain :

  • Library/Keychains/System.keychain

The try a recovery…

Then you should repair disk permissions from a terminal (not single user) :

diskutil repairPermissions /

If after the recovery you experience problem connecting to services check the configuration under "Services" tab in Directory Utility.

0

Repair as proposed in the accepted answer was not able to fix my problems. However, restoring the database from a Time Machine backup was successful:

  1. Unload OpenDirectory to be safe: sudo launchctl unload /System/Library/LaunchDaemons/org.openldap.slapd.plist
  2. Open a finder window, then select Go > Go to folder /var/db
  3. Rename /var/db/openldap to something like /var/db/openldap.corrupt
  4. Enter Time Machine
  5. Go back in time to when you know OpenDirectory worked
  6. Restore /var/db/openldap
  7. Run a recover on the restored data:
sudo db_recover -cv -h /var/db/openldap/openldap-data/
sudo db_recover -cv -h /var/db/openldap/authdata/
  1. Restart Open Directory: sudo launchctl unload /System/Library/LaunchDaemons/org.openldap.slapd.plist

Once macOS Server has restarted, OpenDirectory should be up and running.

You must log in to answer this question.

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