0
votes

I've installed Mongodb on Ubuntu but can not start it,I'm really stuck at this point! I've tried lots of solutions but none of them worked for me.

Any help would be appreciated

when I run start command

sudo service mongod start

It says:

Job for mongod.service failed because the control process exited with 

error code. See "systemctl status mongod.service" and "journalctl -xe" for details.

And output of status command is:

sudo systemctl status mongod.service

● mongod.service Loaded: loaded (/etc/init.d/mongod; bad; vendor preset: enabled) Active: failed (Result: exit-code) since جمعه 2018-03-30 15:00:56 +0430; 2s ago Docs: man:systemd-sysv-generator(8) Process: 5500 ExecStart=/etc/init.d/mongod start (code=exited, status=1/FAILURE)

15:00:56 mahdi-HP-15-Notebook-PC mongod[5500]: Rather than invoking init scripts through /etc/init.d, use the service(8)

مارس 30 15:00:56 mahdi-HP-15-Notebook-PC mongod[5500]: utility, e.g. service mongod start مارس 30 15:00:56 mahdi-HP-15-Notebook-PC mongod[5500]: initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart:

مارس 30 15:00:56 mahdi-HP-15-Notebook-PC mongod[5500]: Since the script you are attempting to invoke has been converted to an

مارس 30 15:00:56 mahdi-HP-15-Notebook-PC mongod[5500]: Upstart job, you may also use the start(8) utility, e.g. start mongod

مارس 30 15:00:56 mahdi-HP-15-Notebook-PC mongod[5500]: start: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Co

مارس 30 15:00:56 mahdi-HP-15-Notebook-PC systemd[1]: mongod.service: Control process exited, code=exited status=1

مارس 30 15:00:56 mahdi-HP-15-Notebook-PC systemd[1]: Failed to start mongod.service.

مارس 30 15:00:56 mahdi-HP-15-Notebook-PC systemd[1]: mongod.service: Unit entered failed state. مارس 30 15:00:56 mahdi-HP-15-Notebook-PC systemd[1]: mongod.service: Failed with result 'exit-code'.

1
have you tried this stackoverflow.com/questions/33010719/…... it works for meAshh
@AshishChoudhary Yes, I tried that, But did not workMahdi Younesi

1 Answers

1
votes

I faced exactly the same problem. I followed the official MongoDB community guide, for installing MongoDB on a xubuntu 16.04 workstation. The service worked fine until I rebooted after installation.

Then the service stopped working and it displayed the behavior that you describe in your question. I noticed that after the first reboot the folder /var/log/mongodb disappeared. After manually creating it, I was able to run mongod, until the next reboot.

The solution to this problem is to change the file /lib/systemd/system/mongod.service, in order to instruct systemd to create this folder and assign it to user mongodb just before loading mongod service. Just add the following lines in the [Service] section:

ExecStartPre=/bin/mkdir -p /var/log/mongodb/
ExecStartPre=/bin/chown -R mongodb:mongodb /var/log/mongodb/  

Then you should be able to start the sevice by using either
sudo systemctl start mongod
or
sudo service mongod start

Here are all the commands for performing the installation based on the official guide.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
sudo apt update
sudo apt install -y mongodb-org

# this command performs the edit described above    
sudo sed -i 's/Group=mongodb/Group=mongodb\nExecStartPre=\/bin\/mkdir -p \/var\/log\/mongodb\/\nExecStartPre=\/bin\/chown -R mongodb:mongodb \/var\/log\/mongodb\//g' /lib/systemd/system/mongod.service

# enable and run the service
sudo systemctl enable mongod
sudo systemctl start mongod

# run mongo client and check the service
mongo --host 127.0.0.1:27017

And here's how to completely remove MongoDB (incuding the logs and the databases):

sudo apt purge mongodb-org*
sudo rm -r /var/lib/mongodb
sudo rm -r /var/log/mongodb