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;

In reply to starting httpd from perl by opensourcer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.