将 MongoDB 服务器作为服务运行(与终端分离)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7016880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 12:12:24  来源:igfitidea点击:

Run MongoDB server as a service (detached from terminal)?

servicemongodb

提问by tybro0103

When I start the MongoDB server (mongod) from terminal it keeps that tab open. How do I go about running it as a service?

当我从终端启动 MongoDB 服务器(mongod)时,它会保持该选项卡打开。我如何将它作为服务运行?

I'm on OSX Lion.

我在 OSX Lion 上。

I like how the rails server script has a -d option to detach it from terminal.

我喜欢 rails 服务器脚本如何有一个 -d 选项来将它与终端分离。

回答by Emily

This is built into mongod, much like it is in the rails server. Instead of -dyou'll need to use --forkand you'll probably want to specify --logpath /path-to/logfile --logappendas well, so that your output will be logged and will keep any previous logs.

这是内置于 中的mongod,就像它在 Rails 服务器中一样。而不是-d您需要使用--fork并且您可能还想指定--logpath /path-to/logfile --logappend,以便您的输出将被记录并保留任何以前的日志。

See the docs on starting and stopping Mongofor more information.

有关更多信息,请参阅有关启动和停止 Mongo 的文档

回答by Chris Fulstow

To set up MongoDB to run as a background service, check out the mongo-installerpackage for OS X 10.5+ or the MongoDB-OSX-Launchctlscripts.

要将 MongoDB 设置为作为后台服务运行,请查看OS X 10.5+的mongo-installer包或MongoDB-OSX-Launchctl脚本。