I can do

mongod -f /etc/mongodb.conf 

How do I achieve the same effect when starting mongodb as a service? ie

sudo service start mongodb

By default this does not read from the config file.

I am on Ubuntu.

1 Answer 1


I think you're limited to changing it in the upstart config file, like so:

# Ubuntu upstart file at /etc/init/mongodb.conf

limit nofile 20000 20000

kill timeout 300 # wait 300s between SIGTERM and SIGKILL.

pre-start script
    mkdir -p /var/lib/mongodb/
    mkdir -p /var/log/mongodb/
end script

start on runlevel [2345]
stop on runlevel [06]

  if [ -f /etc/default/mongodb ]; then . /etc/default/mongodb; fi
  if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec  /usr/bin/mongod -- --config /etc/my-mongodb.conf; fi
end script

In the above I've changed the path in this line:

  if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon \
      --start --quiet --chuid mongodb --exec  /usr/bin/mongod -- \
      --config /etc/my-mongodb.conf; fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .