Use shell scripts in CentOS to monitor whether the website is normal
Source: Internet
Author: User
Recently I bought a vps and put a website on it. when a large volume of traffic is always unresponsive, I wrote a monitoring script to check the website every minute. if the website cannot be accessed, I restarted the service. 1. write a Shell script and save it to/opt/http_monitor #! /Bin/bash # website url URL & quot; http://www.xxx.com/recently bought a vps, put a website on it, a lot of access is always no response, I wrote a monitoring script, the service is detected once every minute and restarted if it cannot be accessed.
1. write a Shell script and save it to/opt/http_monitor.
#! /Bin/bash
# If the server can respond normally, 200 of the code should be returned.
If [$ HTTP_CODE! = 200]; then
# Restart the service
Service httpd restart
Fi
2. add to crontab and use the crontab-e command to add a new task:
Shell code
# Run once every minute
*/1 */opt/http_monitor
3. stop the service, test, cool! Started automatically one minute later! However, the Chinese characters are garbled. after checking that the system variables were not loaded, you can add the locale environment variable to http_monitor:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.