How to ensure that a service is always running on CentOS?

11

I created a startup script for my application in CentOS, so I can use the following commands to initialize / stop the application:

service django_app start
service django_app stop

How do I make sure this service is always running?

For example, if there are any errors in the application and the service is terminated, is there any way to restart the service automatically in CentOS?

    
asked by anonymous 12.02.2014 / 18:09

3 answers

3

find monit, a simple and functional orchestrator:

config example:

check process meuapp with pidfile /var/vcqescolhe/app.pid
start program = "/etc/init.d/app  start" uid 500 gid 499
stop program = "/etc/init.d/app stop" uid 500 gid 499
if failed host 127.0.0.1 port 8080 then restart
if failed host localhost port 8080
    protocol HTTP request "/meuapp/beheappy/smileinsignificante.jpg" with timeout     10 seconds then restart

This monitor can even send emails ... it is faster than a nagios or zabbix

    
12.02.2014 / 19:00
2

A much simpler way than monit, as commented by J. Bruni in your question, is to make a script.

vi /xyz/django_app_verify.sh

#!/bin/bash
if [ ! "$(pidof django_app)" ] 
then
  /xyz/comandoParaIniciarSeu_django_app &
fi

Then add in crontab

* * * * * /xyz/django_app_verify.sh > /dev/null

So it runs every minute. This solution is more frequent than it seems.

    
24.02.2014 / 16:30
1

Another alternative is the Supervisor!

pip install supervisor

Then you create a configuration file with the programs that will be monitored. A minimum example would be:

[program:foo]
command=/bin/cat

The official tutorial is on this page .

    
08.05.2014 / 23:56