Bom dia pessoal!!!
Existe alguma forma de, através de algum código JAva presente num servlet ou no quartz, eu enviar um comando para o tomcat reiniciar???
Obrigado!
Bom dia pessoal!!!
Existe alguma forma de, através de algum código JAva presente num servlet ou no quartz, eu enviar um comando para o tomcat reiniciar???
Obrigado!
Não sei se tem algo mais pratico, mas poderia ser assim:
Runtime.getRuntime().exec("java -jar c:/dir_do_tomcat/bin/bootstrap.jar stop");
O objetivo é reiniciar o tomcat remotamente? Ou só reiniciar o contexto?
Tem a interface web de controle do tomcat. Digita no seu navegador
http://server:8080/manager/html.
Não testei, mas se precisasse faria algo do tipo:
public class CommandTomcat extends Thread {
private String cmd;
public CommandTomcat(final String cmd) { this.cmd = cmd; }
public void run() {
exec();
}
private synchronized exec() {
try {
final Runtime runTime = Runtime.getRuntime();
final Process p = runTime.exec(cmd);
showInput(p.getInputStream());
} catch (Exception e) { /*TODO*/} finally { notifyAll(); }
}
private void showInput(final InputStream in) {
final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
final StringBuilder buffer = new StringBuilder();
String aLine = null;
while ((aLine = reader.readLine()) != null) {
buffer.append(aLine);
}
System.out.println(buffer);
}
}
private void restart() {
final String stopCmd =
"java -jar %CATALINA_HOME%/bin/bootstrap.jar stop";
final Thread stopTC = new CommandTomcat(stopCmd);
stopTC.start();
stopTC.join();
final String startCmd =
"java -jar %CATALINA_HOME%/bin/bootstrap.jar start";
final Thread startTC = new CommandTomcat(startCmd);
startTC.start();
}
Vais ter de trabalhar no mecanismo de sincronização entre o Stop e o Start porque se ele tentar iniciar com uma instância ainda executando vai dar problema com as portas. Já deve dar uma idéia. T+
[quote=“victorpinto”]O objetivo é reiniciar o tomcat remotamente? Ou só reiniciar o contexto?
Tem a interface web de controle do tomcat. Digita no seu navegador
http://server:8080/manager/html.[/quote]
Eu preciso reiniciar o tomcat inteiro, só o contexto não me resolve o problema… Obrigado aí cara!
[quote=“jairelton”]Não sei se tem algo mais pratico, mas poderia ser assim:
Runtime.getRuntime().exec("java -jar c:/dir_do_tomcat/bin/bootstrap.jar stop");
É nestesentido mesmo que vou ter que trabalhar!
Obrigado!
[quote=“iktuz”]Não testei, mas se precisasse faria algo do tipo:
public class CommandTomcat extends Thread {
private String cmd;
public CommandTomcat(final String cmd) { this.cmd = cmd; }
public void run() {
exec();
}
private synchronized exec() {
try {
final Runtime runTime = Runtime.getRuntime();
final Process p = runTime.exec(cmd);
showInput(p.getInputStream());
} catch (Exception e) { /*TODO*/} finally { notifyAll(); }
}
private void showInput(final InputStream in) {
final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
final StringBuilder buffer = new StringBuilder();
String aLine = null;
while ((aLine = reader.readLine()) != null) {
buffer.append(aLine);
}
System.out.println(buffer);
}
}
private void restart() {
final String stopCmd =
"java -jar %CATALINA_HOME%/bin/bootstrap.jar stop";
final Thread stopTC = new CommandTomcat(stopCmd);
stopTC.start();
stopTC.join();
final String startCmd =
"java -jar %CATALINA_HOME%/bin/bootstrap.jar start";
final Thread startTC = new CommandTomcat(startCmd);
startTC.start();
}
Vais ter de trabalhar no mecanismo de sincronização entre o Stop e o Start porque se ele tentar iniciar com uma instância ainda executando vai dar problema com as portas. Já deve dar uma idéia. T+[/quote]
Poxa, perfeito cara! Vou trabalhar sobre este código…
Muitíssimo obrigado!
Estou com esse mesmo problema.
Tenho uma aplicação em um servidor e preciso que essa aplicação reinicie o servidor todo.
Alguém utilizou essa solução descrita?
Uma duvida: se eu rodar um “stop” tudo morre?, como vai rodar o “start”?
Sugestões?
Obrigado