I recently upgraded to Ubuntu 16.04 after which MongoDB 3.0.2 is not starting.

$ sudo service mongod start

which would throw error:

Failed to start mongod.service: Unit mongod.service failed to load: No such file or directory.

I saw these error logs by executing systemctl status mongod.service

● mongod.service
   Loaded: loaded (/etc/init.d/mongod; bad; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2016-04-29 10:48:02 IST; 10s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 8624 ExecStart=/etc/init.d/mongod start (code=exited, status=1/FAILURE)

mongod[8223]: Rather than invoking init scripts through /etc/init.d, use the service(8)
mongod[8223]: utility, e.g. service mongod start
mongod[8223]: initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection
mongod[8223]: Since the script you are attempting to invoke has been converted to an
mongod[8223]: Upstart job, you may also use the start(8) utility, e.g. start mongod
mongod[8223]: start: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection r
systemd[1]: mongod.service: Control process exited, code=exited status=1
systemd[1]: Failed to start mongod.service.
systemd[1]: mongod.service: Unit entered failed state.
systemd[1]: mongod.service: Failed with result 'exit-code'.

I tried the below mentioned solutions, but none worked:

  1. Created a file /lib/systemd/system/mongodb.service with the following content:

[Unit] Description=High-performance, schema-free document-oriented database After=network.target

[Service] User=mongodb ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf

[Install] WantedBy=multi-user.target

  1. Tried installing upstartv sudo apt-get install upstart-sysv
  • remove upstart-sysv you can start mongo by a systemd unit.
  • check your mongod.config configuration file. It shouldn't have processManagement.fork: true
  • check your mongo dbpath and log folders mongodb user (in service file) that you run your script with should have permission to access these files.
  • if still have problems check your mongod.log file (you specified it in config file) you can find more detailed errors there.
| improve this answer | |

Ok, I did:

    • Backup:

    # cp -vr /var/lib/mongodb /root/

    # cp /etc/mongod.conf /root

    • Deleted the old init:

    # rm -fr /etc/init.d/mongod

3 - Created the file /etc/systemd/system/multi-user.target.wants/mongod.service, like:

# nano /etc/systemd/system/multi-user.target.wants/mongod.service

4 - I copied this script from other system that was already Xenial:

Description=High-performance, schema-free document-oriented database

ExecStart=/usr/bin/env bash -c "numactl --interleave=all /usr/bin/mongod --quiet --config /etc/mongod.conf"
# file size
# cpu time
# virtual memory size
# open files
# processes/threads
# total threads (user+kernel)

# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings


5 - Still fails if you try to start it (take a look at the start command, it uses numactl, so:

# apt-get install -y numactl

6 - Reload services:

# systemctl daemon-reload

7 - Remove old locks (pray to your database is sane):

# rm -fr /var/lib/mongodb/mongod.lock

8 - Restart, check status and be happy:

# systemctl restart mongod.service
# systemctl status mongod.service
● mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/etc/systemd/system/multi-user.target.wants/mongod.service; bad; vendor preset: enabled)
   Active: active (running) since Qui 2018-05-17 21:15:16 -03; 2s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 6301 (mongod)
   CGroup: /system.slice/mongod.service
           └─6301 /usr/bin/mongod --quiet --config /etc/mongod.conf

Mai 17 21:15:16 xx-server systemd[1]: Started High-performance, schema-free document-oriented database.


I've just faced this today, so, maybe there are still some Trusty systems to be Xenial using MongoDB around this realm of LTS. Sorry for the markup, I'm still improving this. Best to you all!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.