Automatically monitor and restart Apache service scripts under Linux

  
 

In order to achieve a highly available Apache-based web environment, after Apache automatically stops running for various reasons, you want to restore website access immediately. This requires a tool to monitor Apache's running status and automatically restart the httpd service. I found the relevant information on the Internet and rewrote the following simple monitoring and restart script:

Principle

Local access to the Apache service through the server (similar to the user accessing the website), such as no more than 15s Returns the normal 220 header code, indicating that the Apache service has stopped running, and immediately restarts the httpd service.

Usage Method

Method 1:

1. Execute vi on the Linux server to edit a new script, copy the following script code, and then exit and save.
Bash[root@localhost /]# vi /opt/autorshttpd

#!/bin/bash

URL="http://127.0.0.1/"

curlit()

{

curl --connect-timeout 15 --max-time 20 --head --silent "$URL"

Copyright © Windows knowledge All Rights Reserved