Merge remote-tracking branch 'origin/jetty-9.2.x'

This commit is contained in:
Greg Wilkins 2015-03-25 14:00:23 +11:00
commit 1d99c0af7b
3 changed files with 24 additions and 19 deletions

View File

@ -28,10 +28,8 @@ import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
import org.eclipse.jetty.util.component.Destroyable; import org.eclipse.jetty.util.component.Destroyable;
@ -41,8 +39,8 @@ import org.eclipse.jetty.util.thread.ShutdownThread;
/** /**
* Shutdown/Stop Monitor thread. * Shutdown/Stop Monitor thread.
* <p> * <p>
* This thread listens on the port specified by the STOP.PORT system parameter (defaults to -1 for not listening) for request authenticated with the key given * This thread listens on the host/port specified by the STOP.HOST/STOP.PORT system parameter (defaults to 127.0.0.1/-1 for not listening) for
* by the STOP.KEY system parameter (defaults to "eclipse") for admin requests. * request authenticated with the key given by the STOP.KEY system parameter (defaults to "eclipse") for admin requests.
* <p> * <p>
* If the stop port is set to zero, then a random port is assigned and the port number is printed to stdout. * If the stop port is set to zero, then a random port is assigned and the port number is printed to stdout.
* <p> * <p>
@ -82,7 +80,7 @@ public class ShutdownMonitor
return getInstance()._lifeCycles.contains(lifeCycle); return getInstance()._lifeCycles.contains(lifeCycle);
} }
/* ------------------------------------------------------------ */
/** /**
* ShutdownMonitorRunnable * ShutdownMonitorRunnable
* *
@ -297,7 +295,7 @@ public class ShutdownMonitor
{ {
serverSocket = new ServerSocket(); serverSocket = new ServerSocket();
serverSocket.setReuseAddress(true); serverSocket.setReuseAddress(true);
serverSocket.bind(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), port), 1); serverSocket.bind(new InetSocketAddress(InetAddress.getByName(host), port), 1);
if (port == 0) if (port == 0)
{ {
// server assigned port in use // server assigned port in use
@ -330,6 +328,7 @@ public class ShutdownMonitor
} }
private boolean DEBUG; private boolean DEBUG;
private String host;
private int port; private int port;
private String key; private String key;
private boolean exitVm; private boolean exitVm;
@ -351,6 +350,7 @@ public class ShutdownMonitor
this.DEBUG = props.containsKey("DEBUG"); this.DEBUG = props.containsKey("DEBUG");
// Use values passed thru via /jetty-start/ // Use values passed thru via /jetty-start/
this.host = props.getProperty("STOP.HOST","127.0.0.1");
this.port = Integer.parseInt(props.getProperty("STOP.PORT","-1")); this.port = Integer.parseInt(props.getProperty("STOP.PORT","-1"));
this.key = props.getProperty("STOP.KEY",null); this.key = props.getProperty("STOP.KEY",null);
this.exitVm = true; this.exitVm = true;

View File

@ -450,6 +450,7 @@ public class Main
private void doStop(StartArgs args) private void doStop(StartArgs args)
{ {
String stopHost = args.getProperties().getString("STOP.HOST");
int stopPort = Integer.parseInt(args.getProperties().getString("STOP.PORT")); int stopPort = Integer.parseInt(args.getProperties().getString("STOP.PORT"));
String stopKey = args.getProperties().getString("STOP.KEY"); String stopKey = args.getProperties().getString("STOP.KEY");
@ -457,41 +458,41 @@ public class Main
{ {
int stopWait = Integer.parseInt(args.getProperties().getString("STOP.WAIT")); int stopWait = Integer.parseInt(args.getProperties().getString("STOP.WAIT"));
stop(stopPort,stopKey,stopWait); stop(stopHost,stopPort,stopKey,stopWait);
} }
else else
{ {
stop(stopPort,stopKey); stop(stopHost,stopPort,stopKey);
} }
} }
/** /**
* Stop a running jetty instance. * Stop a running jetty instance.
*/ */
public void stop(int port, String key) public void stop(String host, int port, String key)
{ {
stop(port,key,0); stop(host,port,key,0);
} }
public void stop(int port, String key, int timeout) public void stop(String host, int port, String key, int timeout)
{ {
int _port = port; if (host==null || host.length()==0)
String _key = key; host="127.0.0.1";
try try
{ {
if (_port <= 0) if (port <= 0)
{ {
System.err.println("STOP.PORT system property must be specified"); System.err.println("STOP.PORT system property must be specified");
} }
if (_key == null) if (key == null)
{ {
_key = ""; key = "";
System.err.println("STOP.KEY system property must be specified"); System.err.println("STOP.KEY system property must be specified");
System.err.println("Using empty key"); System.err.println("Using empty key");
} }
try (Socket s = new Socket(InetAddress.getByName("127.0.0.1"),_port)) try (Socket s = new Socket(InetAddress.getByName(host),port))
{ {
if (timeout > 0) if (timeout > 0)
{ {
@ -500,7 +501,7 @@ public class Main
try (OutputStream out = s.getOutputStream()) try (OutputStream out = s.getOutputStream())
{ {
out.write((_key + "\r\nstop\r\n").getBytes()); out.write((key + "\r\nstop\r\n").getBytes());
out.flush(); out.flush();
if (timeout > 0) if (timeout > 0)

View File

@ -108,6 +108,10 @@ Startup / Shutdown Command Line:
Properties: Properties:
STOP.HOST=[string]
The host to use to stop the running Jetty server (defaults to 127.0.0.1)
Required along with STOP.PORT if you want to use the --stop option above.
STOP.PORT=[number] STOP.PORT=[number]
The port to use to stop the running Jetty server. The port to use to stop the running Jetty server.
Required along with STOP.KEY if you want to use the --stop option above. Required along with STOP.KEY if you want to use the --stop option above.