我试图在OS山狮中配置MongoDB。我已经安装了Homebrew;我已经学习了很多教程,但是我有一个问题我还没能解决。
这个问题与launchctl unload和launchctl load命令有关。我的homebrew.mxcl.mongodb.plist位于/usr/local/Cellar/mongodb/2.4.6/,它包含以下代码:
<?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.mongodb</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/Cellar/mongodb/2.4.6/mongod</string>
<string>run</string>
<string>--config</string>
<string>/usr/local/Cellar/mongodb/2.4.6/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/Cellar/mongodb/2.4.6/data/log/mongod.log</string>
<key>StandardOutPath</key>
<string>/usr/local/Cellar/mongodb/2.4.6/data/log/mongod.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>如果我执行sudo launchctl load -w /usr/local/Cellar/mongodb/2.4.6/homebrew.mxcl.mongodb.plist,http://localhost:28017/中将显示MongoDB的http diagnostic access信息。但是,如果我执行sudo launchctl unload -w /usr/local/Cellar/mongodb/2.4.6/homebrew.mxcl.mongodb.plist,则不会断开连接,并在http://localhost:28017/ url中显示相同的内容。
要关闭Mongo,我需要以下命令:
use admin
db.shutdownServer()如何使用launchctl unload命令自动关闭Mongo?
发布于 2013-10-22 17:10:41
我对此进行了测试,首先使用brew安装了MongoDB 2.4.6,然后使用launchctl加载和卸载。在我的测试中,它将发送一个SIGTERM到mongod进程,然后按预期关闭。下面是我使用的命令以及mongod进程的日志:
命令:
launchctl load -w /usr/local/Cellar/mongodb/2.4.6/homebrew.mxcl.mongodb.plist
launchctl unload -w /usr/local/Cellar/mongodb/2.4.6/homebrew.mxcl.mongodb.plist日志:
tail -f /usr/local/var/log/mongodb/mongo.log
Tue Oct 22 17:33:32.774 [initandlisten] MongoDB starting : pid=13192 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=adamc-mbp.local
Tue Oct 22 17:33:32.774 [initandlisten] db version v2.4.6
Tue Oct 22 17:33:32.774 [initandlisten] git version: nogitversion
Tue Oct 22 17:33:32.774 [initandlisten] build info: Darwin minimountain.local 12.4.0 Darwin Kernel Version 12.4.0: Wed May 1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Tue Oct 22 17:33:32.774 [initandlisten] allocator: tcmalloc
Tue Oct 22 17:33:32.774 [initandlisten] options: { bind_ip: "127.0.0.1", command: [ "run" ], config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb", logappend: "true", logpath: "/usr/local/var/log/mongodb/mongo.log" }
Tue Oct 22 17:33:32.775 [initandlisten] journal dir=/usr/local/var/mongodb/journal
Tue Oct 22 17:33:32.775 [initandlisten] recover : no journal files present, no recovery needed
Tue Oct 22 17:33:32.806 [websvr] admin web console waiting for connections on port 28017
Tue Oct 22 17:33:32.806 [initandlisten] waiting for connections on port 27017
Tue Oct 22 17:34:21.682 [signalProcessingThread] got signal 15 (Terminated: 15), will terminate after current cmd ends
Tue Oct 22 17:34:21.682 [signalProcessingThread] now exiting
Tue Oct 22 17:34:21.682 dbexit:
Tue Oct 22 17:34:21.682 [signalProcessingThread] shutdown: going to close listening sockets...
Tue Oct 22 17:34:21.682 [signalProcessingThread] closing listening socket: 9
Tue Oct 22 17:34:21.682 [signalProcessingThread] closing listening socket: 10
Tue Oct 22 17:34:21.682 [signalProcessingThread] closing listening socket: 11
Tue Oct 22 17:34:21.682 [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock
Tue Oct 22 17:34:21.682 [signalProcessingThread] shutdown: going to flush diaglog...
Tue Oct 22 17:34:21.682 [signalProcessingThread] shutdown: going to close sockets...
Tue Oct 22 17:34:21.682 [signalProcessingThread] shutdown: waiting for fs preallocator...
Tue Oct 22 17:34:21.682 [signalProcessingThread] shutdown: lock for final commit...
Tue Oct 22 17:34:21.683 [signalProcessingThread] shutdown: final commit...
Tue Oct 22 17:34:21.692 [signalProcessingThread] shutdown: closing all files...
Tue Oct 22 17:34:21.692 [signalProcessingThread] closeAllFiles() finished
Tue Oct 22 17:34:21.692 [signalProcessingThread] journalCleanup...
Tue Oct 22 17:34:21.692 [signalProcessingThread] removeJournalFiles
Tue Oct 22 17:34:21.692 [signalProcessingThread] shutdown: removing fs lock...
Tue Oct 22 17:34:21.693 dbexit: really exiting now我做了好几次来证实这种行为。在Chrome中,状态页面至少不再响应,一旦关闭它,我就会收到一个错误(正如预期的那样)。
我正在做的事情和您发布的内容之间唯一的区别是,我没有使用sudo (事实上,由于对文件的所有权不确定,它拒绝加载或卸载)。因此,我将plist文件的所有权更改为root,并尝试了具有相同结果的sudo。
我能够重新创建卸载失败的唯一方法如下:
sudo launchctl开始(root是plist文件的所有者)sudo的情况下卸载但是,如果出现错误,这将失败:
launchctl: Error unloading: homebrew.mxcl.mongodb注意:随后将所有权更改为常规用户,使卸载成功。
同样,这也会产生相同的错误:
sudo启动(普通用户拥有plist文件)我无法重现你在我尝试过的各种组合中所经历的沉默失败。
一些信息收集提示可能会给你一些线索:
launchctl list | grep mongodb?(它应该列出类似于13340 - homebrew.mxcl.mongodb的内容https://dba.stackexchange.com/questions/51623
复制相似问题