Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb running only while ssh connection is kept

Tags:

mongodb

Hello I'm testing mongo experimental version, which doesn't have an installer and is ran from directory by putting ./mongod but the problem is that the process quits whenever I close my ssh connection. What I'm supposed to do to keep it running even after closing ssh connection?

like image 331
PartyPete Avatar asked Jun 10 '26 09:06

PartyPete


2 Answers

To start the mongod process as a background daemon you should run it with the parameters --fork (run as a daemon) and --logpath (a filename for log output).

You probably want to specify the --dbpath as well (unless you are OK with the default of /data/db).

So putting that together:

$ mongod --fork --dbpath /path/to/data --logpath /path/to/mongod.log    
about to fork child process, waiting until server is ready for connections.
forked process: 64043
all output going to: /path/to/mongod.log
child process started successfully, parent exiting

$

After the server starts you will be returned to a command prompt.

If you want to shut down the server gracefully, log in via the mongo shell and run db.shutdownServer().

For more information see Manage mongod Processes in the MongoDB Manual.

like image 186
Stennie Avatar answered Jun 16 '26 22:06

Stennie


It looks like that it is not started as a daemon so when you close your ssh session it got HUP signal. You can avoid it by using:

nohup command-to-start-mongo &
like image 35
JosefN Avatar answered Jun 16 '26 21:06

JosefN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!