Merge remote-tracking branch 'origin/jetty-7' into jetty-8

This commit is contained in:
Jan Bartel 2012-10-21 20:20:04 +11:00
commit e8a77e7fce
2 changed files with 20 additions and 5 deletions

View File

@ -38,6 +38,7 @@ import java.lang.reflect.Method;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.net.SocketTimeoutException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -182,7 +183,7 @@ public class Main
{ {
int port = Integer.parseInt(Config.getProperty("STOP.PORT","-1")); int port = Integer.parseInt(Config.getProperty("STOP.PORT","-1"));
String key = Config.getProperty("STOP.KEY",null); String key = Config.getProperty("STOP.KEY",null);
stop(port,key, false); stop(port,key);
return null; return null;
} }
@ -190,7 +191,8 @@ public class Main
{ {
int port = Integer.parseInt(Config.getProperty("STOP.PORT","-1")); int port = Integer.parseInt(Config.getProperty("STOP.PORT","-1"));
String key = Config.getProperty("STOP.KEY",null); String key = Config.getProperty("STOP.KEY",null);
stop(port,key, true); int timeout = Integer.parseInt(Config.getProperty("STOP.WAIT", "0"));
stop(port,key, true, timeout);
return null; return null;
} }
@ -1012,11 +1014,11 @@ public class Main
*/ */
public void stop(int port, String key) public void stop(int port, String key)
{ {
stop (port,key,false); stop (port,key,false, 0);
} }
public void stop (int port, String key, boolean wait, int timeout)
public void stop (int port, String key, boolean wait)
{ {
int _port = port; int _port = port;
String _key = key; String _key = key;
@ -1035,6 +1037,8 @@ public class Main
} }
Socket s = new Socket(InetAddress.getByName("127.0.0.1"),_port); Socket s = new Socket(InetAddress.getByName("127.0.0.1"),_port);
if (wait && timeout > 0)
s.setSoTimeout(timeout*1000);
try try
{ {
OutputStream out = s.getOutputStream(); OutputStream out = s.getOutputStream();
@ -1043,6 +1047,7 @@ public class Main
if (wait) if (wait)
{ {
System.err.println("Waiting"+(timeout > 0 ? (" "+timeout+"sec") : "")+" for jetty to stop");
LineNumberReader lin = new LineNumberReader(new InputStreamReader(s.getInputStream())); LineNumberReader lin = new LineNumberReader(new InputStreamReader(s.getInputStream()));
String response=lin.readLine(); String response=lin.readLine();
if ("Stopped".equals(response)) if ("Stopped".equals(response))
@ -1054,6 +1059,11 @@ public class Main
s.close(); s.close();
} }
} }
catch (SocketTimeoutException e)
{
System.err.println("Timed out waiting for stop confirmation");
System.exit(ERR_UNKNOWN);
}
catch (ConnectException e) catch (ConnectException e)
{ {
usageExit(e,ERR_NOT_STOPPED); usageExit(e,ERR_NOT_STOPPED);

View File

@ -95,6 +95,11 @@ Properties:
STOP.KEY=[alphanumeric] STOP.KEY=[alphanumeric]
The passphrase defined to stop the server. The passphrase defined to stop the server.
Requried along with STOP.PORT if you want to use the --stop option above. Requried along with STOP.PORT if you want to use the --stop option above.
STOP.WAIT=[number]
The time (in seconds) to wait for confirmation that the running Jetty server
has stopped. If not specified, the stopper will wait indefinitely. Use in
conjunction with the --stop-wait option.
DEBUG=true DEBUG=true
Enable debug on the start mechanism and sets the Enable debug on the start mechanism and sets the