什么是在Mac OS X上阻止mongod的有效方法?

时间:2022-09-04 01:07:50

i'm running mongo 1.8.2 and trying to see how to cleanly shut it down on Mac.

我正在运行mongo 1.8.2,试图看看如何在Mac上彻底关闭它。

on our ubuntu servers i can shutdown mongo cleanly from the mongo shell with:

在我们的ubuntu服务器上,我可以从mongo shell关闭mongo,它可以:

> use admin
> db.shutdownServer()

but on my Mac, it does not kill the mongod process. the output shows that it 'should be' shutdown but when i ps -ef | grep mongo it shows me an active process. also, i can still open a mongo shell and query my dbs like it was never shutdown.

但是在我的Mac电脑上,它并没有杀死mongod进程。输出显示它应该是关闭的,但是当我ps -ef | grep mongo时,它显示了一个积极的过程。此外,我还可以打开mongo shell并查询我的dbs,就像它从来没有关闭过一样。

the output from my db.shutdownServer() locally is:

我的db.shutdownServer()本地的输出是:

MongoDB shell version: 1.8.2
connecting to: test
> use admin                  
switched to db admin
> db.shutdownServer()
Tue Dec 13 11:44:21 DBClientCursor::init call() failed
Tue Dec 13 11:44:21 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1
server should be down...
Tue Dec 13 11:44:21 trying reconnect to 127.0.0.1
Tue Dec 13 11:44:21 reconnect 127.0.0.1 failed couldn't connect to server 127.0.0.1
Tue Dec 13 11:44:21 Error: error doing query: unknown shell/collection.js:150

i know i can just kill the process but i'd like to do it more cleanly.

我知道我可以杀死这个过程,但我想更干净一些。

6 个解决方案

#1


121  

It's probably because launchctl is managing your mongod instance. If you want to start and shutdown mongod instance, unload that first:

这可能是因为launchctl管理你的mongod实例。如果您想启动和关闭mongod实例,首先卸载:

launchctl unload -w ~/Library/LaunchAgents/org.mongodb.mongod.plist

Then start mongod manually:

然后开始mongod手动:

mongod -f path/to/mongod.conf --fork

You can find your mongod.conf location from ~/Library/LaunchAgents/org.mongodb.mongod.plist.

你可以找到你的蒙神。相依~ /图书馆/ LaunchAgents / org.mongodb.mongod.plist位置。

After that, db.shutdownServer() would work just fine.

之后,db.shutdownServer()就可以正常工作了。

Added Feb 22 2014:

2014年2月22日:

If you have mongodb installed via homebrew, homebrew actually has a handy brew services command. To show current running services:

如果你的mongodb是通过homebrew安装的,那么homebrew实际上有一个现成的brew服务命令。显示当前运行服务:

brew services list

啤酒服务列表

To start mongodb:

启动mongodb:

brew services start mongodb

啤酒服务启动mongodb

To stop mongodb if it's already running:

如果mongodb已经在运行,就停止它:

brew services stop mongodb

啤酒服务停止mongodb

Update

更新

As edufinn pointed out in the comment, brew services is now available as user-defined command and can be installed with following command: brew tap gapple/services.

正如edufinn在评论中指出的,brew服务现在可以作为用户定义的命令使用,并且可以按照以下命令安装:brew tap gapple/services。

#2


21  

If you installed mongodb with homebrew, there's an easier way:

如果你把mongodb安装在homebrew上,有一个更简单的方法:

List mongo job with launchctl:

列表mongo job with launchctl:

launchctl list | grep mongo

Stop mongo job:

停止mongo工作:

launchctl stop <job label>

(For me this is launchctl stop homebrew.mxcl.mongodb)

(对我来说,这就是launchctl停止homebrew.mxcl.mongodb)

Start mongo job:

蒙戈开始工作:

launchctl start <job label>

#3


11  

Simple way is to get the process id of mongodb and kill it. Please note DO NOT USE kill -9 pid for this as it may cause damage to the database.

简单的方法是获取mongodb的进程id并将其杀死。请注意不要使用kill -9 pid,因为它可能会对数据库造成损坏。

so, 1. get the pid of mongodb

所以,1。获取mongodb的pid。

$ pgrep mongo

美元pgrep mongo

you will get pid of mongo, Now

现在,你会得到蒙戈的pid。

$ kill

美元杀死

You may use kill -15 as well

你也可以使用kill -15。

#4


4  

I prefer to stop the MongoDB server using the port command itself.

我更喜欢使用端口命令本身来阻止MongoDB服务器。

sudo port unload mongodb

And to start it again.

重新开始。

sudo port load mongodb

#5


3  

Check out these docs:

查看这些文档:

http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo#StartingandStoppingMongo-SendingaUnixINTorTERMsignal

http://www.mongodb.org/display/DOCS/Starting +和+停止+ Mongo # StartingandStoppingMongo-SendingaUnixINTorTERMsignal

If you started it in a terminal you should be ok with a ctrl + 'c' -- this will do a clean shutdown.

如果你在一个终端启动它,你应该可以使用ctrl + 'c'——这将会彻底关闭。

However, if you are using launchctl there are specific instructions for that which will vary depending on how it was installed.

但是,如果您正在使用launchctl,则会有具体的指示,根据安装的方式会有所不同。

If you are using Homebrew it would be launchctl stop homebrew.mxcl.mongodb

如果你使用的是自制啤酒,那么它就会被发射到家中。

#6


2  

This is an old question, but its one I found while searching as well.

这是一个老问题,但我在搜索时也发现了这个问题。

If you installed with brew then the solution would actually be the this:

如果你安装了brew,那么解决方案就是:

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

launchctl卸载~ /图书馆/ LaunchAgents / homebrew.mxcl.mongodb.plist

#1


121  

It's probably because launchctl is managing your mongod instance. If you want to start and shutdown mongod instance, unload that first:

这可能是因为launchctl管理你的mongod实例。如果您想启动和关闭mongod实例,首先卸载:

launchctl unload -w ~/Library/LaunchAgents/org.mongodb.mongod.plist

Then start mongod manually:

然后开始mongod手动:

mongod -f path/to/mongod.conf --fork

You can find your mongod.conf location from ~/Library/LaunchAgents/org.mongodb.mongod.plist.

你可以找到你的蒙神。相依~ /图书馆/ LaunchAgents / org.mongodb.mongod.plist位置。

After that, db.shutdownServer() would work just fine.

之后,db.shutdownServer()就可以正常工作了。

Added Feb 22 2014:

2014年2月22日:

If you have mongodb installed via homebrew, homebrew actually has a handy brew services command. To show current running services:

如果你的mongodb是通过homebrew安装的,那么homebrew实际上有一个现成的brew服务命令。显示当前运行服务:

brew services list

啤酒服务列表

To start mongodb:

启动mongodb:

brew services start mongodb

啤酒服务启动mongodb

To stop mongodb if it's already running:

如果mongodb已经在运行,就停止它:

brew services stop mongodb

啤酒服务停止mongodb

Update

更新

As edufinn pointed out in the comment, brew services is now available as user-defined command and can be installed with following command: brew tap gapple/services.

正如edufinn在评论中指出的,brew服务现在可以作为用户定义的命令使用,并且可以按照以下命令安装:brew tap gapple/services。

#2


21  

If you installed mongodb with homebrew, there's an easier way:

如果你把mongodb安装在homebrew上,有一个更简单的方法:

List mongo job with launchctl:

列表mongo job with launchctl:

launchctl list | grep mongo

Stop mongo job:

停止mongo工作:

launchctl stop <job label>

(For me this is launchctl stop homebrew.mxcl.mongodb)

(对我来说,这就是launchctl停止homebrew.mxcl.mongodb)

Start mongo job:

蒙戈开始工作:

launchctl start <job label>

#3


11  

Simple way is to get the process id of mongodb and kill it. Please note DO NOT USE kill -9 pid for this as it may cause damage to the database.

简单的方法是获取mongodb的进程id并将其杀死。请注意不要使用kill -9 pid,因为它可能会对数据库造成损坏。

so, 1. get the pid of mongodb

所以,1。获取mongodb的pid。

$ pgrep mongo

美元pgrep mongo

you will get pid of mongo, Now

现在,你会得到蒙戈的pid。

$ kill

美元杀死

You may use kill -15 as well

你也可以使用kill -15。

#4


4  

I prefer to stop the MongoDB server using the port command itself.

我更喜欢使用端口命令本身来阻止MongoDB服务器。

sudo port unload mongodb

And to start it again.

重新开始。

sudo port load mongodb

#5


3  

Check out these docs:

查看这些文档:

http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo#StartingandStoppingMongo-SendingaUnixINTorTERMsignal

http://www.mongodb.org/display/DOCS/Starting +和+停止+ Mongo # StartingandStoppingMongo-SendingaUnixINTorTERMsignal

If you started it in a terminal you should be ok with a ctrl + 'c' -- this will do a clean shutdown.

如果你在一个终端启动它,你应该可以使用ctrl + 'c'——这将会彻底关闭。

However, if you are using launchctl there are specific instructions for that which will vary depending on how it was installed.

但是,如果您正在使用launchctl,则会有具体的指示,根据安装的方式会有所不同。

If you are using Homebrew it would be launchctl stop homebrew.mxcl.mongodb

如果你使用的是自制啤酒,那么它就会被发射到家中。

#6


2  

This is an old question, but its one I found while searching as well.

这是一个老问题,但我在搜索时也发现了这个问题。

If you installed with brew then the solution would actually be the this:

如果你安装了brew,那么解决方案就是:

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

launchctl卸载~ /图书馆/ LaunchAgents / homebrew.mxcl.mongodb.plist