How to use shell to automatically restart the service
Editor to share with you how to use shell to achieve automatic restart service, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
The code is as follows:
#! / bin/bash
If [!-f / tmp/down_count]; then
Echo "0" > / tmp/down_count
Fi
Curl-I tomcat-host-o "/ tmp/status" > / dev/null 2 > & 1
Code= `awk 'NR==1 {print $2}' / tmp/ status`
If ["$[code]"-ge 500]; then
Down= `expr $(cat / tmp/down_count) + 1`
Echo "$down" > / tmp/down_count
If ["$down"-gt 3]; then
If [!-f "/ tmp/restart_count"]; then
Echo "0" > / tmp/restart_count
Fi
Restart_count= `expr $(cat / tmp/restart_count) + 1`
Echo "$restart_count" > / tmp/restart_count
If ["$restart_count"-le 2]; then
Echo "tomcat down at `date`" > > / tmp/down_info
/ etc/init.d/tomcat6 restart
Fi
Fi
Else
Echo "0" > / tmp/down_count
Echo "0" > / tmp/restart_count
Fi
The script realizes that when the status code of a web page is detected to appear 3 times in a row, the tomcat6 will be restarted automatically, and only twice in a row.
The above is all the contents of the article "how to use shell to automatically restart the service". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!