Web端 自动远程执行重启tomcat服务命令
vi restart.sh #!/bin/sh
JAVA_HOME=/usr/java6
export JAVA_HOME
CLASSPATH=$JAVA_HOME/lib:.:$JAVA_HOME/jre/lib
export CLASSPATH
APACHE_HOME=/usr/local/tomcat6
export APACHE_HOME
PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$APACHE_HOME/bin
export PATH
sh /usr/local/tomcat6/bin/shutdown.sh
sleep 2
sh /usr/local/tomcat6/bin/startup.sh :wq chmod u+x ./restart.sh //给矛sh文件可执行权限 ./restart.sh runsh.jsp
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%
Runtime rt = Runtime.getRuntime();
rt.exec("/usr/local/tomcat6/bin/restart.sh");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ">
<html xmlns=" ">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>远程重启tomcat</title>
<script src=" " type="text/javascript"></script>
</head>
<body>
远程重启tomcat命令执行,请稍候!
当前状态:<span id="flag"></span>
<script type="text/javascript">
function ping(){
$.ajax({
url: 'http://目标网址',
type: 'GET',
complete: function(response) {
if(response.status == 200) {
$("#flag").html('<a href="/">重启成功!</a>');
clearInterval(gtime);
} else {
$("#flag").html('启动中,请稍候!'+response.status);
}
}
});
}
var gtime;
$(document).ready(function(){
gtime = setInterval(ping, 2000);//每隔2秒自动扫描网站是否可用
});
</script>
</body>
</html>