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 com.apple.ManagedClient.enrollagent 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"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
<plist version='1.0'>
<dict>
<key>Label</key><string>org.macports.mongodb</string>
<key>ProgramArguments</key>
<array>
<string>/opt/local/bin/daemondo</string>
<string>--label=mongodb</string>
<string>--start-cmd</string>
<string>sudo</string>
<string>-u</string>
<string>_mongo</string>
<string>/opt/local/bin/mongod</string>
<string>--dbpath</string>
<string>/opt/local/var/db/mongodb</string>
<string>--logpath</string>
<string>/opt/local/var/log/mongodb/mongodb.log</string>
<string>--logappend</string>
<string>;</string>
<string>--pid=exec</string>
</array>
<key>Debug</key><true/>
<key>Disabled</key><true/>
<key>KeepAlive</key><true/>
</dict>
</plist>


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!

3 comments:

Mauro Foti said...

Moreover don't try to rebuild it!

https://jira.mongodb.org/browse/SERVER-10644

Anonymous said...

Worked perfect. Thanks for posting this.

Out of curiosity, do you know why this happened in the first place?

Vincenzo D'Amore said...

Hi Mauro,

sorry I read your comment only now. May be you don't know but just few days after, on Oct 27, was released a patch to fix mongodb server rebuild.

wget --no-check-certificate https://jira.mongodb.org/secure/attachment/33042/patch-mavericks.diff