In Progress Web monitor script

DTS-Dan

Registered
Nov 17, 2020
1
1
3
Alaska
cPanel Access Level
Root Administrator
I'm looking for some help w a script that I can set in cron to check for content delivery from apache.
It would run local on the server and use cURL to check for a proper response within 2 seconds. If it fails, the script would cause the httpd service to restart.

Something like:
curl https://siteaddress.tld/success.html that returns:
<html><head>​
</head><body>​
<p>Success!</p>​
</body></html>​
on success.
if it doesn't return the content in <2000ms, httpd gets restarted and a notification is sent.

The purpose is that we've had at least two instances of Apache not delivering content, although the service was running.

Any thoughts or assistance is appreciated.

Thanks,
Dan
 
  • Like
Reactions: ramjankhan

WasChristine

Technical Analyst
Aug 10, 2018
57
11
83
Houston, TX
cPanel Access Level
Root Administrator
Hello,

The chkservd service is intended to monitor Apache to see if it is available and attempt graceful reboot if it is not. If you want this for a specific website, however, then it would require a custom script of sorts. While cPanel may not be able to advise you on how to do so directly, what we will do is move this post to the community Developer Experience space for potential advice from other users.
 
  • Like
Reactions: ramjankhan

plesk4lyf

Active Member
PartnerNOC
May 21, 2018
37
7
8
Sydney
cPanel Access Level
Root Administrator
Hi Dan,

Your script is disgusting... I love it.

Here's your cronjob:
Bash:
*/5 * * * * timeout 3s curl -so /dev/null https://siteaddress.tld/success.html || (/scripts/restartsrv_httpd && echo ""|mailx -s "$(date):Timeout... Restarted HTTPD" youremailhere)
You should probably actually just go through the apache logs to see what the reason was though.
 
  • Like
Reactions: WasChristine