在MacOSX用launchctl来管理mongodb

创建org.mongo.mongod.plist文件

/Library/LaunchDaemons/org.mongo.mongod.plist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?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.mongo.mongod</string>
  <key>RunAtLoad</key>
  <true/>
  <key>ProgramArguments</key>
  <array>
      <string>/usr/local/bin/mongod</string>
      <string>--dbpath</string>
      <string>/var/lib/mongodb/</string>
      <string>--logpath</string>
      <string>/var/log/mongodb.log</string>
  </array>
</dict>
</plist>

接下来我们来创建data与log路径

Terminal
1
2
sudo touch /var/log/mongodb.log
sudo mkdir /var/lib/mongodb
Terminal
1
2
3
sudo chown root:wheel /Library/LaunchDaemons/org.mongo.mongod.plist
sudo launchctl load /Library/LaunchDaemons/org.mongo.mongod.plist
sudo launchctl start org.mongo.mongod

参考 MongoDB Startup Item for Mac OS X Snow Leopard

原文地址:http://dlj.bz/F1PTNG

Comments