Hi,
I am trying to get ifstated to monitor nginx & relayd
demons but can't quite figure out how to do it. As both nginx & relayd
have a master process and child threads, I am trying to figure out how
to check that all the processes are running and if there's a problem
(maby one thread dies) kill the service and restart it. As I think this
is the correct to thing to do.
This is my ifstated.conf for nginx, It checks for a predefined number of
processes and if there's a problem It trys to kill the process and start
it again. But it doesn't work. Can anyone help ?
init-state auto
# ps -aux and check that there are 6 processes running
nginx_check = '( "ps -aux | grep \"nginx\" | grep -v grep | wc -l | grep
6" every 5)'
state auto {
if $nginx_check {
set-state nginx_online
}
if ! $nginx_check {
set-state nginx_offline
}
}
# When nginx comed up log it.
state nginx_online {
init {
run "echo Nginx Up : $(date) >> /var/log/ifstated.log"
}
if ! $nginx_check {
set-state nginx_offline
}
}
# When nginx is down or there's not 6 process running, kill the remain
processes and restart,
# This is the part that's not working.
state nginx_offline {
init {
run "echo Nginx Down : $(date) >> /var/log/ifstated.log"
run "pkill nginx | sleep 5"
run "nginx -c /etc/nginx/nginx.conf"
}
if $nginx_check {
set-state nginx_online
}
}
Thanks
Keith