notification when apache2 service is down
how or where can I set up email notification when apache2 service is down? Debian 10
5 Replies
Write a shell script that does the following:
Runs the command
/usr/sbin/apachectl status 2>&1 | grep 'not running' >/dev/null 2>&1
If the exit status ($?) is zero, then web server is not running (so send the email…however it is you do that).
If the exit status ($?) is one, the web server is running (so don't send the email).
Something like this:
#!/bin/sh
/usr/sbin/apachectl status 2>&1 | grep 'not running' >/dev/null 2>&1
if [ $? = 0 ]
then
echo 'send the email here'
fi
exit 0
Run the script every minute/5 minutes/hour/whatever using cron.
Your shell script can alternatively run sudo systemctl apache2 status
but then it has to filter through a whole bunch of systemd crapola to arrive at a decision. If you look at systemd's apache2.service, it just uses /usr/sbin/apachectl to do its job in the first place.
By using apachectl from the start, your script will cut out the middle man; be easier to write; and run faster.
-- sw
I use UptimeRobot to monitor my individual sites. You can monitor 50 sites for free.
I would posit that UptimeRobot is monitoring something different than what I posted. UptimeRobot is monitoring site accessibility and not whether the server is running or not.
Granted, a site will be inaccessible if the server is not running but it will also be inaccessible if it's misconfigured. So, if a site is misconfigured, you have a disconnect between the server being up/down and the site being in-/accessible.
Other than that, UptimeRobot looks like a great service.
-- sw
Here is another service which will monitor cron jobs as well as site uptime. Not free but not very expensive… has a 14 day free trial. Again, it monitors 'jobs' and not apache itself from what I can glean.