How to Auto Restart ElasticSearh service on failure

If ElasticSearh service crash on your server, you can auto restart it by modifying systemd service file.

This will open an editor. In the file editor, paste the following text.

Save and exit the editor. Restart elasticsearch service

To verify ElasticSearch auto restart on failure, you can kill the process. To find the process ID, you can use the command “systemctl status elasticsearch”, it will show the current status and PID of ElasticSearch. After killing the process, check the status of ElasticSearch, you will see it auto-starting.

Monitor using cronjob

If you are not using systemd, you can use a cronjob to monitor ElasticSearch and restart in case of failure.

Create a file

In the file, paste the following code

This script will check if port 9200 is open (elasticsearch default port). If you use a non-standard port, replace the port 9200 in the script with your elasticsearch port.

Make the script executable

Create a cronjob


You can also use monit to auto restart Elastic Search. How to Auto restart ElasticSearch with monit

Check ElasticSearch Process is running

In the above method, we check if ElasticSearch listening on a port. Instead, you can check if the process is running or not. Use the following script to check if ElasticSearch process is running, if it crashed, then restart the service.

NOTE: when you use this method, make sure you don’t name the script with name elastic as the script itself shows when you check if elasticsearch is running. So name this script with some generic name, example

Check ElasticSearch status with systemctl

Back to ElasticSearch

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *