I would like to run mongod in the background as an always present sort of thing. What would be the best way to do this? Kind of like the way I can run MySQL on startup and it's just always there running in the background. Maybe it's just some bash scripts, but it would be nice to hear if there is a better way. If it is just bash - what would that look like? Thanks.
|
The MongoDB daemon (mongod) has a command-line option to run the server in the background...
This command-line option requires that you also specify a file to log messages to (since it can not use the current console). An example of this command looks like:
You could put this into an /etc/init.d/mongod bash script file. And then to have the service run at startup, create the standard symbolic links (S## & K##) inside of /etc/rc#.d/. Here is a tutorial that explains this process in more detail. Scroll down to the section titled "Init Script Activation". This also has the added benefit of being able to execute commands like...
|
|||
|
|
|
Since you are on a Mac, you should use Homebrew to install MongoDB (you will need to install Homebrew if you haven't yet):
Let's say the version that was installed is named
This will launch |
|||
|
|
|
Classically, to run in the background, just start with
|
|||
|
|
|
The best way to get a program to run at startup on OS X is to create a LaunchDaemon (see Apple's docs, and take a look at some of the Apple-supplied daemons in /System/Library/LaunchDaemons) and install it in /Library/LaunchDaemons. Lingon can help you create the .plist file. |
|||
|
|