MongoDB 2.6 does not start on Ubuntu 15.04
I installed MongoDB 2.6 on clean installed Ubuntu 15.04:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install -y mongodb-org
It finished without any problems. However, when I tried to start it, I got the following error:
$ sudo service mongod start
Failed to start mongod.service: Unit mongod.service failed to load: No such file or directory.
How can I fix this?
I installed from the debian wheeze repository and it works fine.
First make sure you remove the mongodb-org package and all its dependencies:
sudo apt-get purge mongodb-org
sudo apt-get autoremove
Remove the old mongodb.list you created:
sudo rm /etc/apt/sources.list.d/mongodb.list
Use the Debian repository instead:
echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
Update and install again:
sudo apt-get update
sudo apt-get install -y mongodb-org
After that, you can succesffully start the server:
sudo service mongod start
or
systemctl start mongod
(as clarified by Ernie Hershey in reply to Roman Gaufman's comment here: https://jira.mongodb.org/browse/SERVER-17742)
The MongoDB team says they won't support Ubuntu 15.04 and plan to support 16.04 instead (see https://jira.mongodb.org/browse/SERVER-17742).
Ubuntu 15.04 advances the default init system from Upstart to systemd. I had no success starting MongoDB 3.0 with systemd.
You can switch back to Upstart by installing upstart-sysv
:
sudo apt-get install upstart-sysv
Then reboot and MongoDB should be up.
I hope to find an easy way to run MongoDB on Ubuntu 15.04 without switching things back in time.
You're installing from the packages published directly from mongodb.org. You should be installing from the packages supplied in the Ubuntu respository. The Debian/Ubuntu packages have been patched with systemd service units, to fill the hole left by mongodb.org.
(There's no shortage of mongodb.service
unit files on the WWW. It's not hard to write one, either. I have.)
Specifically: you'll find such a service unit in the mongodb-server version 2.6 package for Ubuntu version 15. So just install that package.
(Note that the Debian/Ubuntu-supplied service units do not apply the mongo-recommended systemd service unit directives.)
Further reading
- https://unix.stackexchange.com/a/187540/5132
I created a Systemd script that seems to work for Ubuntu 15.04+ and Mongo 3.0+:
[Unit]
Description=High-performance, schema-free document-oriented database
Documentation=man:mongod(1)
After=network.target
[Service]
Type=forking
User=mongodb
Group=mongodb
RuntimeDirectory=mongod
PIDFile=/var/run/mongod/mongod.pid
ExecStart=/usr/bin/mongod -f /etc/mongod.conf --pidfilepath /var/run/mongod/mongod.pid --fork
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
https://gist.github.com/benileo/ada486d73f58dd93a0ee
Make sure you set your data directory in /etc/mongod.conf
Isn't this the best answer? From a duplicate question: https://askubuntu.com/a/694226/255468 by @sclausen
It's just the lack of a service file for systemd. No need to go back to upstart like Kartik did or use a different repository than described in https://docs.mongodb.org/manual/installation/.
Create 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