Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting mongod as a service with config file setting

I want to be able to do sudo service mongod start with the option of giving it the path to the configuration file /etc/mongod.conf.

So far I have been able to run mongod as daemon by setting the processManagement.fork variable in /etc/mongod.conf to true as such:

# mongod.conf

storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0


processManagement:
  fork: true

then running the command:

>> mongod --config /etc/mongod.conf

However, I think it would be best to run it as a service so I can easily start and stop it without having to kill the daemon process every time I want to stop the mongod server.

like image 905
SalmaFG Avatar asked Nov 17 '16 10:11

SalmaFG


1 Answers

Try add your mongo bin directory to path

export PATH=$PATH:/path/to/mongodb/bin
  1. Create the service file in /etc/init.d/mongo

copy the content from here mongodb GitHub repo

  1. chmod 700 /etc/init.d/mongo
  2. update-rc.d defaults
  3. update-rc.d enable

Now see you service in

service --status-all

PS: you should have access to create file in /etc/init.d folder and make nessesary changes as per your system requirement

like image 150
Darshan J Avatar answered Sep 20 '22 17:09

Darshan J