Using the apt-get
package for ElasticSearh, how can I configure the service to restart itself automatically after crashing on Ubuntu?
Add a comment
|
Restart on failure option is missing in the default service of elasticsearch.
So, We can add Restart=always option in the service.
Steps to add - Restart=always
Edit elasticsearch service unit file using the command
sudo systemctl edit elasticsearch.service
. This command will create a file/etc/systemd/system/elasticsearch.service.d/override.conf
.Now, add the following lines in the unit file.
[Service] Restart=always
- Save the file and refresh the unit file using command
sudo systemctl daemon-reload
- Can check the changes using command
sudo systemctl cat elasticsearch.service
.
Note:
We can use Restart= always, on-abnormal, on-success, on-failure, etc based on the requirement. Reference.
Editing unit file - Reference
Write a #!/bin/sh
script as follows:
if ps -ef | grep -v grep | grep elastic ; then
exit 0
else
/etc/init.d/elasticsearch start >> /var/run/elasticsearch.pid &
exit 0
fi
-
It didn't add in my new lines. - insert a break after "then", "exit 0", "else", "..znc.pid & "exit 0". last line is fi. – ecaleohs Oct 15 '14 at 14:01