monit is a program used to monitor processes and restart them if they failed. If your server don’t have monit installed, see install instructions at Install Monit on Ubuntu or Install Monit on CentOS
To restart elasticsearch on failure, create a file
vi /etc/monit/conf-enabled/elasticsearch.conf
Add the following content to the file
check process elasticsearch with pidfile "/var/run/elasticsearch/elasticsearch.pid" start program = "/bin/systemctl start elasticsearch" stop program = "/bin/systemctl stop elasticsearch"
Reload monit with
monit reload
To check the status of monit, run
monit status
Example
root@sok:~# monit status Monit 5.26.0 uptime: 8m Process 'elasticsearch' status OK monitoring status Monitored monitoring mode active on reboot start pid 366866 parent pid 1 uid 115 effective uid 115 gid 118 uptime 6m threads 60 children 1 cpu - cpu total - memory 58.0% [2.2 GB] memory total 58.2% [2.2 GB] security attribute unconfined disk read 0 B/s [97.5 MB total] disk write 0 B/s [2.3 MB total] data collected Mon, 09 Aug 2021 10:07:22 System 'sok.guest' status OK monitoring status Monitored monitoring mode active on reboot start load average [0.02] [0.18] [0.47] cpu 4.4%us 1.4%sy 0.1%wa memory usage 3.1 GB [81.7%] swap usage 774.5 MB [18.9%] uptime 3d 22h 39m boot time Thu, 05 Aug 2021 11:28:16 data collected Mon, 09 Aug 2021 10:07:22 root@sok:~#
To see other ways of restarting ElasticSearch, see How to auto restart ElasticSearh service on failure
Back to monit
Leave a Reply