1

How can I restart mongodb that I just killed in Linux?

Before killing:

$ service mongodb status
● mongodb.service - An object/document-oriented database
   Loaded: loaded (/lib/systemd/system/mongodb.service; disabled; vendor preset: enabled)
   Active: active (running) since Tue 2017-01-03 08:41:16 GMT; 4h 5min ago
     Docs: man:mongod(1)
 Main PID: 1036 (mongod)
    Tasks: 10
   Memory: 61.0M
      CPU: 1min 1.636s
   CGroup: /system.slice/mongodb.service
           └─1036 /usr/bin/mongod --config /etc/mongodb.conf

So I wanted to stop/ kill it for a while for other programs:

$ sudo kill 1036
$ service mongodb status
● mongodb.service - An object/document-oriented database
   Loaded: loaded (/lib/systemd/system/mongodb.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:mongod(1)

But how can I start it again?

I'm on Ubuntu 16.04.

EDIT:

$ systemctl start mongod 
Failed to start mongod.service: Unit mongod.service not found.

EDIT 2:

Get this error below when I have the other program running on mondodb. so I killed that program and it works as before.

$ sudo systemctl start mongodb
$ service mongodb status
● mongodb.service - An object/document-oriented database
   Loaded: loaded (/lib/systemd/system/mongodb.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2017-01-03 13:05:19 GMT; 9s ago
     Docs: man:mongod(1)
  Process: 21732 ExecStart=/usr/bin/mongod --config /etc/mongodb.conf (code=exited, status=48)
 Main PID: 21732 (code=exited, status=48)
Run
  • 54,938
  • 169
  • 450
  • 748

3 Answers3

7

Ubuntu 16.04 LTS

sudo systemctl start mongodb

Not only for MongoDB, but for any application installed, you can use

sudo systemctl start <app_name>
sudo systemctl restart <app_name>
Sai Kiran
  • 167
  • 7
  • Check out this post: http://stackoverflow.com/questions/37565758/mongodb-not-working-on-ubuntu-16-04 – Sai Kiran Jan 03 '17 at 13:09
  • thanks. how can i stop mongo correctly? I tried with `$ sudo systemctl stop mongod` then I get this error `Failed to stop mongod.service: Unit mongod.service not loaded.` – Run Jan 03 '17 at 13:29
  • the service is mongodb.service, so you need start/ stop mongodb, not mongod – dormi330 Jan 03 '17 at 13:34
4

Seems like you are using systemd.

Try:

  • systemctl start mongod => Start the the service
  • systemctl status mongod => Status of the service
  • systemctl restart mongod => restart the service
  • systemctl reload mongod => reload the service
alper
  • 2,919
  • 9
  • 53
  • 102
Nidhin David
  • 2,426
  • 3
  • 31
  • 45
  • how can i stop mongo correctly? I tried with `$ sudo systemctl stop mongod` then I get this error `Failed to stop mongod.service: Unit mongod.service not loaded.` – Run Jan 03 '17 at 13:29
  • @teelou systemctl stop mongod...The error says that your mongod is either not running or it is already stopped. This works for me in Ubuntu 16.04, verified it just now – Nidhin David Jan 04 '17 at 10:33
2

You checked status with :

service mongod status

so this should start mongod:

service mongod start

so this should stop mongod:

sudo service mongod stop

It works at my end. for missing permissions:

sudo service mongod start
cartman619
  • 552
  • 4
  • 17
  • I tried that before but getting this error `Failed to stop mongod.service: Unit mongod.service not loaded.` – Run Jan 03 '17 at 13:27
  • 1
    chk this [link](http://askubuntu.com/questions/770054/mongodb-3-2-doesnt-start-on-lubuntu-16-04-lts-as-a-service) – cartman619 Jan 03 '17 at 13:37