I installed MongoDB through the software centre in Ubuntu 16.04:
mongodb 1:2.6.10-0ubuntu1
I believe this currently contains MongoDB 2.6.10.
I am running an application on apache2 localhost setup and have to start mongod
manually each time the system starts with:
mongod
I want it to start automatically.
I've come across two main methods to do this:
update-rc.d mongodb defaults
from: https://askubuntu.com/a/89914/367134
which results in:
update-rc.d mongodb defaults
insserv: fopen(.depend.stop): Permission denied
But this didn't produce error:
sudo update-rc.d mongodb defaults
I've also seen a few references to edit the "MongoDB config file", but I'm not sure what this refers to as I can see config files in more than one location:
/etc/mongodb.conf
/etc/init/mongodb.conf
/etc/init.d/mongodb
And, once in the correct file, I'm not sure what to change in there.
In /etc/init/mongodb.conf
I can see:
start on runlevel [2345]
stop on runlevel [!2345]
What is the correct way to ensure mongod
starts on system startup in 16.04?
I've been reading this, and looked in /etc/rc2.d
and can see:
S01mongodb@ --> /etc/init.d/mongodb
Update:
After running suggestion:
sudo systemctl enable mongodb
and then restarting, running systemctl status mongodb
returns:
* mongodb.service - An object/document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2016-04-18 23:42:28 AEST; 7min ago
Docs: man:mongod(1)
Process: 655 ExecStart=/usr/bin/mongod --config /etc/mongodb.conf (code=exited, status=100)
Main PID: 655 (code=exited, status=100)
Apr 18 23:42:27 me-comp systemd[1]: Started An object/document-oriented database
Apr 18 23:42:28 me-comp systemd[1]: mongodb.service: Main process exited, code=exited, status=100/n/a
Apr 18 23:42:28 me-comp systemd[1]: mongodb.service: Unit entered failed state.
Apr 18 23:42:28 me-comp systemd[1]: mongodb.service: Failed with result 'exit-code'.
Permission Troubleshooting
/var/lib/mongodb
= drwxr-xr-x mongodb mongodb
.
/var/log/mongodb
= drwxr-xr-x mongodb mongodb
.
/var/log/mongodb/mongodb.log
= -rw-r--r-- mongodb nogroup
.
/var/log/mongodb/mongod.log
= -rw-r--r-- mongodb mongodb
.
/data/db/mongod.lock
= -rwxrwxr-x me me
and 0 bytes.
/data
= drwxr-xr-x root root
.
/data/db
= drwxr-xr-x me root
.
Config File Contents
/etc/mongodb.conf
:
# Where to store the data.
dbpath=/var/lib/mongodb
#where to log
logpath=/var/log/mongodb/mongodb.log
logappend=true
bind_ip = 127.0.0.1
#port = 27017 ...