in reply to Apache restart

Once you have written the scrip you use perl to run it.

Replies are listed 'Best First'.
Re^2: Apache restart
by Anonymous Monk on Mar 15, 2017 at 19:23 UTC
    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.