在线上运行了一段时间发现有时候后台的进程没有down掉,但是web服务不能正常的解析jsp。把web服务重启后,一切恢复正常。
现在,把以前
扫描端口的方式修改
监控http请求返回的状态码来实现。
操作步骤:
具体实现参考
Web服务自动监控shell
#!/bin/sh
#####################################################
#desc:扫描后台服务器的应用服务器,若不能正常访问则重启
#author:gaozhonghui
#mail:gaozhh@cdeledu.com
#date:20121127
#######################################################
year=`date -d "today" +"%Y"`
monthday=`date -d "today" +"%m"`
date=$(date -d "today" +"%Y%m%d")
#被监控服务器、端口列表
#str = web服务文件夹:端口号
server_all_list=(
'www.test.com^http://127.0.0.1:8050/portal'
)
#应用服务器基路径
serverBasePath="/web/webserver/jboss/"
#日志路径
logBasePath="/web/webserver/logs/$year/$monthday/"
function_getPID(){
local PID=`ps -ef|grep $1|grep java |awk '{print $2}'`
echo $PID
}
function_jstackinfo(){
PID=`function_getPID $1`
if [ x$PID != x"" ] ;then
if [ ! -d ${logBasePath} ];then
mkdir -p ${logBasePath}
fi
jstack -l ${PID} >> ${logBasePath}"jstack_$1_${date}.log"
fi
}
function_shutdown(){
local shutdownSh=${serverBasePath}$1"/bin/shutdown.sh"
if [ -f $shutdownSh ];then
local PID=`function_getPID $1`
if [ x$PID != x"" ] ;then
sh $shutdownSh > /dev/null 2>&1
sleep 2
fi
local PID2=`function_getPID $1`
if [ x$PID2 != x"" ];then
kill -9 $PID2
fi
fi
}
function_startup(){
local startupSh=${serverBasePath}$1"/bin/startup.sh"
if [ -f $shutdownSh ];then
sh $startupSh > /dev/null 2>&1
fi
}
function_restart(){
function_shutdown $1
sleep 5
function_startup $1
}
#获得http 状态码
function_getHttpCode(){
local http_code=`curl -o /dev/null -s -m $1 --connect-timeout $1 -w %{http_code} $2`
local first_http_code=${http_code:0:1}
echo $first_http_code
}
for server in ${server_all_list[@]}; do
server_ip=127.0.0.1
server_name=$(echo ${server} | awk -F '^' '{print $1}')
server_url=$(echo ${server} | awk -F '^' '{print $2}')
http_code_10s=`function_getHttpCode 10 $server_url`
if [ "$http_code_10s" != "0" ] && [ "$http_code_10s" != "4" ] && [ "$http_code_10s" != "5" ];then
#status: 0,http down 1,http ok 2,http down but ping ok
status=1
else
http_code_30s=`function_getHttpCode 30 $server_url`
if [ "$http_code_30s" != "0" ] && [ "$http_code_10s" != "4" ] && [ "$http_code_10s" != "5" ];then
status=1
else
if ping -c 1 $server_ip > /dev/null 2>&1;then
status=2
else
status=0
fi
fi
fi
#根据不同状态操作服务
if [ x$status != x"1" ];then
PID=`function_getPID ${server_name}`
if [ x$PID != x ];then
function_jstackinfo ${server_name}
function_restart ${server_name}
else
function_startup ${server_name}
fi
fi
done
分享到:
相关推荐
shell_v2 这是Shell Holberton School项目第二版的存储库 描述 此外壳程序能够将数据输入标准输入中,进行读取,确定其是否具有功能,并在这种情况下执行命令。 安装 克隆此存储库后,需要运行以下命令来编译其内容...
visual_studio_2010_integrated_shell_cn,VS打包必备
linux shell script tutorial_v2_r5.pdf
在Windows平台下安装PHP后,在使用PHP的exec、shell_exec等函数时,经常会遇到报错:unable to fork...,这实际上是因为PHP对cmd.exe没有足够的权限引起的。
Glances自动安装脚本_Shell_下载.zip
本资源是基于vs2017写的窗口程序,主要讲解是Shell_NotifyIcon()系统托盘图标的API函数的使用。亲测有效
使用ruTorrent为rTorrent自动安装脚本_Shell_CSS_下载.zip
linux命令行以及shell编程必备书籍,英文通俗易懂,内容翔实
BrewUp-macOS自动更新Homebrew_Shell_下载.zip
利用app_process实现免root调用shell_Java_下载.zip
用于开发、测试和CI的自动化脚本_Shell_Python_下载.zip
Linux Shell 实例精解,比较详尽的源码
用于推荐任务的对抗性自动编码器_Python_Shell_下载.zip
将git项目自动化部分放到SAE的svn服务器上_Shell_下
用于生成3D人脸的卷积网格自动编码器_Python_Shell_下载.zip
访问系统托盘的方法是通过Shell_NotifyIcon函数和NOTIFYICONDATA结构实现的。 typedef struct _NOTIFYICONDATA { DWORD cbSize; HWND hWnd; UINT uID; UINT uFlags; UINT uCallbackMessage; HICON ...
Private Shell_CN.exe
UEFI Spec, EFI shell下脚本编程及了解spec看此文件 最新的UEFI Spec版本。
Zabbix自定义脚本和自动安装_Shell_下载.zip
用shell脚本解析配置文件获取变量参数