Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use shell to automatically restart the service

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report