1

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
2
  • 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.
0

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:

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/env bash -c "numactl --interleave=all /usr/bin/mongod --quiet --config /etc/mongod.conf"
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false

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

[Install]
WantedBy=multi-user.target

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!

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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