How to auto-restart MongoDB
Introduction:
To set up MongoDB to auto-restart, you can use system-level services and configuration MongoDB files.
Prerequisite:
1. Server root login credentials.
Step 1:
Log in to your Ubuntu or Centos server as a user with sudo privileges. You can use SSH or directly access the server.
$ ssh root@Ip |
Step 2:
Create a Systemd service unit file and edit your MongoDB service.
$ vi /etc/systemd/system/mongod.service |
Under service, add the below lines..
Restart=always |
Step 3:
Reload the Systemd configuration
$ sudo systemctl daemon-reload |
Step 4:
Then enable the monod.service
$ systemctl enable mongod.service |
Step 5:
Start the MongoDB service:
$ sudo systemctl start mongod |
Conclusion
Following the steps mentioned above, we can set up the auto-restart MongoDB.