2013年12月8日星期日

java code remotely start close tomcat

Such as title, java code to achieve the above tomcat server remotely close
cyberspace is to achieve some of the above approach , you can achieve on their own tomcat free space management startup and shutdown , but
can be sure that they are not in a server above , or so many of our customers have their own websites tomcat server above should be impossible
so it should be controlled by a remote way , that is how specific control it?
trouble to master a code, or a line of thinking also
I can achieve this machine tomcat startup and shutdown
is to use the net start and net stop command
and verify the situation tomcat start by tasklist
part of the code is as follows :

try {
java.lang.Process p = java.lang.Runtime.getRuntime().exec(
"net stop \"Apache Tomcat\"");
java.io.BufferedReader in = new java.io.BufferedReader(
new java.io.InputStreamReader(p.getInputStream()));
String s;
String t = "成功停止";
boolean restart = false;
while ((s = in.readLine()) != null) {
if (s.indexOf(t) != -1) {
restart = true;
break;
}
}
System.out.println("<" + new Date() + "> Tomcat is stop "
+ (restart ? "OK" : "ERROR"));
} catch (Exception e) {
e.printStackTrace();
}


java.lang.Process p = java.lang.Runtime.getRuntime().exec(
"net start \"Apache Tomcat\"");
java.io.BufferedReader in = new java.io.BufferedReader(
new java.io.InputStreamReader(p.getInputStream()));
String s;
String t = "启动成功";
boolean restart = false;
while ((s = in.readLine()) != null) {
if (s.indexOf(t) != -1) {
restart = true;
break;
}
}


------ Solution ------------------------------------ --------
fact, the most lazy way is :

Runtime run = Runtime.getRuntime ();
Process pro = run.exec ("d: \ \ tomcat \ \ bin \ \ shutdown.bat");

------ Solution ------------------------------------ --------
I think the easiest way to make the server install a "Trojan horse"

put that code running in your local changes and let him listen to a port , you write a client , even on this port to control its behavior.

Of course , this demand is not very regular , usual practice , we are remote login server for ixie operation
------ For reference only -------------- -------------------------
can also directly trying to call : org.apache.catalina.startup.Bootstrap stop instruction execution .
------ For reference only -------------------------------------- -

If you are installing version does not have this option
is shutdow.bat

------ For reference only ---------------------------------- -----

have a full demo it , refer wow
------ For reference only ---------------- -----------------------
there weblogic can use the same way to activate or deactivate it
------ For reference only ---------------------------------------
nobody replied, I am now made an application deployed on seven servers , sometimes inconvenient to start a lot of trouble on the outside , you want to monitor a tomcat android applications on these servers , if you find downtime , you can use the android restart. . do not know can not be achieved.

没有评论:

发表评论