In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to use Crontab to monitor and maintain Tomcat applications in Linux". The editor shows you the operation process through an actual case. The method of operation is simple, fast and practical. I hope that this article "how to use Crontab in Linux to monitor and maintain Tomcat applications regularly" can help you solve the problem.
Application interface of monitoring: news interface, weather interface
Solution: automatically restart tomcat when the application interface is not available, and send an alarm email to the relevant personnel
#! / bin/bash#---# function description: # Monitor whether the specified http service is available, and restart tomcat## immediately if not available: # 1. Place this script in the / home/opentsp/crontab/ directory. # 2. Modify the script execution authority to be executable. # 3. Add to the scheduled task, scheduled execution time (recommended is 20 minutes) # 4. Modify the list of email sender information (send email to relevant personnel when the service is restarted) #-Zhou Lingfei (2014-08-13) #-- export lc_all=zh_cn.utf-8# website address, Parameter server_name= "interesting Cloud Interface Service" url_2= "http://127.0.0.1/get_rss_news?p=%7b%27chid%27:%27tiyu%27%7d"keyworld_2=''url_3="http://127.0.0.1/get_json_weather?p=%7blon:116.407617, Lat:39.993956,date:1%7d "keyworld_3='temperature'# mailing list mail_ary= (xxxxxxxxx@navinfo.comxxxxxxxxx@navinfo.comxxxxxxxxx@navinfo.com) # API call failed handling method function dofail () {local ipinfo=$ (ifconfig | sed-n '2p' | awk' {print substr ($2J 6)}')) # send email for _ v in ${mail_ary [*]} Do echo "[$server_name exception]-[$(date-d" 0 min "+% y-%m-%d% h:%m:%s")]-[request address: $1]-[request return code: $2] "| mail-s ${ipinfo} service exception ${_ v} done # write log echo" [error]-[ $(date-d "0 min" + "% y-%m-%d% h:%m:%s")]-return code [$2]-restart tomcat service "> > detect-http.log # close tomcat sh / home/opentsp/crontab/ibr-shutdown.sh exit } # request timeout setting time_out=40function docheck () {local url_x=$1; local keyworld_x=$2; http_status_code= `curl-m $time_out-o / dev/null-s-w "{http_code}" ${url_x} "`if [$http_status_code! = 200] Then # request failed echo "> fail-error code ${http_status_code}"; dofail ${url_x} ${http_status_code}; else # server responded normally. Check the returned content if curl-m ${time_out}-s ${url_x} | grep-Q ${keyworld_x} Then echo "- > success"; else echo "- > > fail"; # returned content error handling dofail ${url_x} ${http_status_code} Fi fi} # # check-News docheck ${url_2} ${keyworld_2} # check-Weather docheck ${url_3} ${keyworld_3}
Put the above code into the scheduled task in linux. It is recommended that the scheduled task time is 20 minutes.
This is the end of the introduction to "how to use Crontab to monitor and maintain Tomcat applications regularly in Linux". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.