Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 55318  / 3 Years ago, sat, october 23, 2021, 4:57:04

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 ...

More From » 16.04

 Answers
0

Installing



This is the method I ended up using (from user Adam C's comment re: using more up to date version of mongodb). It worked for me but I'm not an authority on the matter.



https://askubuntu.com/a/757385/367134



Then I had to make a service file, see:



https://askubuntu.com/a/694226/367134



And edit the path in that service file from:



/etc/mongodb.conf 


to:



/etc/mongod.conf


And then make mongodb start on system startup with:



sudo systemctl enable mongodb


see:



https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units



Now mongodb is starting on 16.04 system startup.



Uninstalling Old MongoDB



Before I did that however, I had to remove the existing installs and directories, which i did like this (steps mainly from https://askubuntu.com/a/497144/367134):



# go to /etc/apt/sources.list.d and remove any mongodb lists, then:

# sanity check - see what is installed
sudo dpkg -l | grep mongo

# remove all packages
sudo apt-get remove mongodb* --purge
sudo apt-get autoremove

# remove old directories
sudo rm -r -f /var/lib/mongodb/
sudo rm -r -f /var/log/mongodb/

[#15844] Sunday, October 24, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
wenceslockro

Total Points: 494
Total Questions: 127
Total Answers: 97

Location: Chad
Member since Mon, Dec 5, 2022
1 Year ago
;