win下服务器tomcat检查,检测tomcat端口是否挂掉,如果挂掉自动重启。脚本如下
#include <File.au3>
;tomcat目录
$tomcatDir = "C:\ovk\apache-tomcat-7.0.55\bin\"
;vlc目录
$vlcPath = "C:\Program Files\VideoLAN\VLC\vlc.exe"
;自办频道1 文件 文件名必须为ziban1.ts
$ziban1Path = "C:\pingdao\ziban1.ts"
;自办频道1 组播地址
$ziban1Dest = "238.1.1.36:3000"
;自办频道2 文件 文件名必须为ziban2.ts
$ziban2Path = "C:\pingdao\ziban2.ts"
;自办频道2 组播地址
$ziban2Dest = "238.1.1.37:3000"
;自办频道3 文件 文件名必须为ziban3.ts
$ziban3Path = "C:\pingdao\ziban3.ts"
;自办频道3 组播地址
$ziban3Dest = "238.1.1.38:3000"
;以下配置说明: 周一和周六的9:45 将会重启tomcat服务
;自动重启星期? 周三
$wday1 = 4
;自动重启星期? 周六
$wday2 = 7
;自动重启 小时? 3点
$hour1 = 11
;自动重启 分钟? 0分
$min1 = 27
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Opt("TrayMenuMode", 0)
Opt("TrayAutoPause", 0)
Opt("TrayIconHide", 0)
Opt("TrayIconHide", 0)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TraySetToolTip("OSTV守护程序")
TrayTip("提示:", "OSTV服务程序已启动!", 10, 1)
Sleep(2000)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
While True
Local $sDate = @YEAR & "-" & @MON & "-" & @MDAY
if Not WinExists("TomcatOSTV") Then
Run($tomcatDir & "startup.bat", $tomcatDir)
TrayTip("警告:", "检测到tomcat未启动,已重新开启!", 10, 2)
_FileWriteLog(@ScriptDir & "\" & $sDate & ".log", "TomcatOSTV Crashed!")
EndIf
if Not WinExists("ziban1.ts - VLC media player") Then
Sleep(5000)
if Not WinExists("ziban1.ts - VLC media player") Then
TrayTip("警告:", "检测到自办频道1未启动,已重新开启!", 10, 2)
Run($vlcPath & " " & $ziban1Path & " --loop --sout=#duplicate{dst=std{access=udp,mux=ts,dst=" & $ziban1Dest & "}}")
_FileWriteLog(@ScriptDir & "\" & $sDate & ".log", "ziban1 Crashed!")
EndIf
EndIf
if Not WinExists("ziban2.ts - VLC media player") Then
Sleep(5000)
if Not WinExists("ziban2.ts - VLC media player") Then
TrayTip("警告:", "检测到自办频道2未启动,已重新开启!", 10, 2)
Run($vlcPath & " " & $ziban2Path & " --loop --sout=#duplicate{dst=std{access=udp,mux=ts,dst=" & $ziban2Dest & "}}")
_FileWriteLog(@ScriptDir & "\" & $sDate & ".log", "ziban2 Crashed!")
EndIf
EndIf
if Not WinExists("ziban3.ts - VLC media player") Then
Sleep(5000)
if Not WinExists("ziban3.ts - VLC media player") Then
TrayTip("警告:", "检测到自办频道3未启动,已重新开启!", 10, 2)
Run($vlcPath & " " & $ziban3Path & " --loop --sout=#duplicate{dst=std{access=udp,mux=ts,dst=" & $ziban3Dest & "}}")
_FileWriteLog(@ScriptDir & "\" & $sDate & ".log", "ziban3 Crashed!")
EndIf
EndIf
Sleep(10000)
if @WDAY == $wday1 Or @WDAY == $wday2 Then
if @HOUR == $hour1 And @MIN == $min1 Then
TrayTip("提示:", "已到预定时间,Tomcat服务会在20秒后重新启动!", 10, 1)
_FileWriteLog(@ScriptDir & "\" & $sDate & ".log", "TomcatOSTV will restart in 20s!")
Sleep(20000)
Run($tomcatDir & "shutdown.bat", $tomcatDir)
Sleep(10000)
Run($tomcatDir & "startup.bat", $tomcatDir)
TrayTip("提示:", "Tomcat服务启动成功!", 10, 1)
_FileWriteLog(@ScriptDir & "\" & $sDate & ".log", "TomcatOSTV Restarted!")
Sleep(20000)
EndIf
EndIf
WEnd
本文出自 “ghost” 博客,请务必保留此出处http://fangwei009.blog.51cto.com/5234706/1690177
原文地址:http://fangwei009.blog.51cto.com/5234706/1690177