$ /devops

How to auto-restart Mongodb in Linux AMI or Ubuntu

published · 1 minute read · linux mongodb
How to auto-restart Mongodb in Linux AMI or Ubuntu

How to auto-restart Mongodb in Linux AMI or Ubuntu in case of crash whenever mongod daemon gets killed, it will get respawned by systemctl.

  1. Edit your mongod service:
sudo vi /lib/systemd/system/mongod.service
  1. Add under service
Restart=always
  1. Reload systemctl daemon
sudo systemctl daemon-reload

Now whenever mongod daemon gets killed, it will get respawned by systemctl.

Autostart mongod process on reboot

After you install MongoDB run on terminal:

systemctl enable mongod.service

This will make your MongoDB service daemon auto-start on reboot of the server.