Shell script code for automatically restarting the service

Source: Internet
Author: User

Copy codeThe Code is as follows :#! /Bin/bash
If [! -F/tmp/down_count]; then
Echo "0" & gt;/tmp/down_count
Fi
Curl-I tomcat-host-o "/tmp/status" & gt;/dev/null 2 & gt; & amp; 1
Code = 'awk' NR = 1 {print $2} '/tmp/status'
If ["$ [code]"-ge 500]; then
Down = 'expr $ (cat/tmp/down_count) + 1'
Echo "$ down" & gt;/tmp/down_count
If ["$ down"-gt 3]; then
If [! -F "/tmp/restart_count"]; then
Echo "0" & gt;/tmp/restart_count
Fi
Restart_count = 'expr $ (cat/tmp/restart_count) + 1'
Echo "$ restart_count" & gt;/tmp/restart_count
If ["$ restart_count"-le 2]; then
Echo "tomcat down at 'date'" & gt;/tmp/down_info
/Etc/init. d/tomcat6 restart
Fi
Fi
Else
Echo "0" & gt;/tmp/down_count
Echo "0" & gt;/tmp/restart_count
Fi

The script is implemented. When the status code of the detected webpage is greater than or equal to 500 for three consecutive times, Tomcat 6 is automatically restarted and restarted only twice in a row.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.