perNewuser has asked for the wisdom of the Perl Monks concerning the following question:

I want to write perl scrip to restart automatically the Apache server when it crushes , can any body help me how I can get it run?

Replies are listed 'Best First'.
Re: Apache restart
by NetWallah (Canon) on Mar 15, 2017 at 19:01 UTC
Re: Apache restart
by Marshall (Canon) on Mar 16, 2017 at 02:52 UTC
    I don't know for sure if you are the Anonymous Monk at Re^2: Apache restart? But this first statement: "my operating system is window 8" leads me to believe that is probably true. Please use your user log-in so that we can track who is saying what!

    Under Windows, a Unix daemon is called a service. There is O/S support for a Windows Service to both start it and keep it running.

    Under Windows go to Control Panel -> Administrative Tools -> Services. Find the appropriate Service, right click and look at Propertes->Recovery. There are options for "first failure", "second failure" etc. One of the options is simply "restart the service".

Re: Apache restart
by Anonymous Monk on Mar 15, 2017 at 19:05 UTC
    Once you have written the scrip you use perl to run it.
      my operating system is window 8 and I saw few previous solution for linux, I was wondering if there is similar script for perl the linux that I saw was
      #!/bin/bash if [`pgrep apache2 -c` -le "0" ]; then /etc/init.d/apache2 stop pkill -u www-data /etc/init.d/apache2 sta +rt echo "restarting....." SUBJECT="Apache auto restart" # Email To ? EMAIL="me@mydomain.com" # Email text/message EMAILMESSAGE="apache auto restart done" # send an email using /bin/mail /bin/mail -s "$SUBJECT" "$EMAIL" " +$EMAILMESSAGE" fi
        Hello,

        if, as wise Marshall said, if your are the Anonymous Monk who run Apache on windows you can follow the Marshall advice about on fail service configuration, or you can create a Perl wrap around some windows commands.

        See SC and NET (service) commands.

        This can be something to start with (UNTESTED!!):

        # the Apache checker is running forever while (1){ my $status # put here the right name of the Apche ser +vice open my $check, "sc query W32Time|" or die "unable to run the check. +."; while (<$check>){ if ($_ =~ /STATUS\s+:\s(\d\s\w+)$/){ $status = $1; last; } } close $check; print scalar localtime(time), " Apache is in the state: ",$status,"\ +n"; unless ($status eq '4 RUNNING'){ print "Apache is not running! Trying a restart\n"; open my $start, 'NET START "W32Time"|' or die "Unable to attemp +t restart!"; print while <$start>; # add more actions: mail, event write... } sleep 60; # or another reasonable amount of time.. }

        HtH

        L*

        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.