Wednesday, October 23, 2013

Mongodb won't start after OS X Mavericks update

Well, if you are in trouble like me, very likely you have my same problem.

After OS X Mavericks update, my mongodb is unable to start.
I found that _mongo user is missing.

Oct 23 11:17:11 mymacbookpro ManagedClient[1497]: FAILURE: Job is not loaded in launchd.

Oct 23 11:17:18 mymacbookpro sudo[1500]:     root : unknown user: _mongo

If you're are looking for a quick and dirty solution at this problem, you could just change the user configured to run mongodb into your current user.

Open Terminal and type:

$ sudo vi /Library/LaunchDaemons/org.macports.mongodb.plist

Change running user (_mongo) into your user:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"" >
<plist version='1.0'>

Then execute:

sudo chown -R freedev: /opt/local/var/db/mongodb/
sudo chown -R freedev: /opt/local/var/log/mongodb/
sudo port unload mongodb
sudo port load mongodb

If you are always unsatisfied by quick and dirty solution, a much cleaner way is create a new user for mongodb, here the steps I found:

Try using the following commands:

sudo dscl . -create /Users/_mongo
sudo dscl . -create /Users/_mongo UserShell /var/empty

You need to add _mongo to admin group, in order to let mongodb listen a network port:

sudo dscl . -append /Groups/admin GroupMembership _mongo

Now you must assign the new unique id to _mongo. I choose the unique id used by my last _mongo user:

sudo dscl . -create /Users/_mongo UniqueID 507

On the other hand _mongo group still exist on my mac so I reused the existing group:

sudo dscl . list /groups PrimaryGroupID  | grep mongo

_mongo                           504

Now we can assign _mongo. I have just reassigned the unique id that the :

sudo dscl . -create /Users/_mongo PrimaryGroupID 504

This just to be sure your filesystem permission are ok with _mongo:

sudo chown -R _mongo: /opt/local/var/db/mongodb/
sudo chown -R _mongo: /opt/local/var/log/mongodb/

Have fun!