in reply to Re: Apache restart
in thread Apache restart

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

Replies are listed 'Best First'.
Re^3: Apache restart
by Discipulus (Canon) on Mar 16, 2017 at 08:13 UTC
    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.