hi monks, i wrote someting very usefull to me, i thought i should share with all of u, plz excuse me, if u don't find my snippet very usefull. Discription: the script checks httpd server and if it is dead or not running for some reason, it will start it.
#!/usr/bin/perl -w ############################## #Author : opensourcer #Date : 23-04-05 # ############################## use Config; <<'#'; contains info about the variables or path like $CONFIG->{HTTPD_PID_OP +EN} u can replace $CONFIG->{HTTPD_PID_OPEN} = 'path of httpd.pid'; # sub check_service { my $httpd_status = 1; #for some shit work # for trapping eval{ local $SIG{ALRM} = \&start_services; #setting exception + to start_services sub routine #set alarm to 15 seconds alarm(15); #open pid file of httpd.pid unless (open(HTTPD_PID_OPEN, $CONFIG->{HTTPD_PID_OPEN})) { # if found problem set signal to 0 alarm(0); # if opened the pid check wether service is running $httpd_status = system('ps -P $httpd_pid'); #send 0 when service is is running if ($httpd_status == 0) { print "httpd server is OK"; } else #the server is crashed { alarm(0); print "Seems that httpd server is crashed\n"; start_services("ALRM"); #raise exception with HTTPD + as signal } #if unable to open pid then raise exception start_services("ALRM"); } else #every thing is ok run with normal processing { print "httpd Server running ok\n"; } }; # end of eval # if raise error equall to start do something # can be changed in feature if ($@ =~ /start/) { print "now starting httpd server\n"; $connect = "yes"; } } #end of function #This sub routine starts httpd if stoped sub start_services { my ($signame) = shift; #catchs signals print "httpd stopped responding at " . localtime() . "\n"; # This subroutine gets called inside an eval() so that it # can interrupt the hung system call. Note that the value here # will be returned to the caller. print system('/home/opensourcer/apache/bin/apachectl start'); die "start\n"; #setting sig to start } # end of start services &check_service;