
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.
- Edit your mongod service:
sudo vi /lib/systemd/system/mongod.service
- Add under service
Restart=always
- 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.