Can't start mongodb by launchctl on OS X Yosemite (10.10.2)

I've installed mongodb 2.4 via homebrew:

brew install homebrew/versions/mongodb24

Then I've made a simlink to the config provided by homebrew:

ln -sfv /usr/local/opt/mongodb24/homebrew.mxcl.mongodb24.plist ~/Library/LaunchAgents

This file contains the following:

<?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>homebrew.mxcl.mongodb24</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/opt/mongodb24/bin/mongod</string>
    <string>--config</string>
    <string>/usr/local/etc/mongod.conf</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <false/>
  <key>WorkingDirectory</key>
  <string>/usr/local</string>
  <key>StandardErrorPath</key>
  <string>/usr/local/var/log/mongodb/output.log</string>
  <key>StandardOutPath</key>
  <string>/usr/local/var/log/mongodb/output.log</string>
  <key>HardResourceLimits</key>
  <dict>
    <key>NumberOfFiles</key>
    <integer>1024</integer>
  </dict>
  <key>SoftResourceLimits</key>
  <dict>
    <key>NumberOfFiles</key>
    <integer>1024</integer>
  </dict>
</dict>
</plist>

And now I'm trying to start it and get error:

$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb24.plist
/usr/local/Cellar/mongodb24/2.4.12/homebrew.mxcl.mongodb24.plist: Operation not permitted

Seems like there is some problem with permissions. But I'm not sure. How can I fix that?


I've solved that problem by using brew services. Remove symlink first:

$ rm ~/Library/LaunchAgents/homebrew.mxcl.mongodb24.plist

Install brew services:

$ brew tap gapple/services

Start mongodb:

$ brew services start mongodb24
==> Successfully started `mongodb24` (label: homebrew.mxcl.mongodb24)

That's it!

UPDATE:

Actually, this happens because of tmux. When you do this inside of a tmux session:

$ brew services start redis
/Users/schfkt/Library/LaunchAgents/homebrew.mxcl.redis.plist: Operation not permitted
==> Successfully started `redis` (label: homebrew.mxcl.redis)

$ brew services list
Warning: No user-space services controlled by `brew services` running...

You get the same result: "Operation not permitted". And redis of course is not started.

But everything works fine when you run the same commands not inside of a tmux session:

$ brew services start redis
==> Successfully started `redis` (label: homebrew.mxcl.redis)

$ brew services list
redis      started    82912 /Users/schfkt/Library/LaunchAgents/homebrew.mxcl.redis.plist