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.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import org.eclipse.jetty.util.component.Destroyable;
@ -41,8 +39,8 @@ import org.eclipse.jetty.util.thread.ShutdownThread;
/**
* Shutdown/Stop Monitor thread.
* <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
* by the STOP.KEY system parameter (defaults to "eclipse") for admin requests.
* 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
* request authenticated with the key given by the STOP.KEY system parameter (defaults to "eclipse") for admin requests.
* <p>
* If the stop port is set to zero, then a random port is assigned and the port number is printed to stdout.
* <p>
@ -82,7 +80,7 @@ public class ShutdownMonitor
return getInstance()._lifeCycles.contains(lifeCycle);
}
/* ------------------------------------------------------------ */
/**
* ShutdownMonitorRunnable
*
@ -297,7 +295,7 @@ public class ShutdownMonitor
{
serverSocket = new ServerSocket();
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)
{
// server assigned port in use
@ -330,6 +328,7 @@ public class ShutdownMonitor
}
private boolean DEBUG;
private String host;
private int port;
private String key;
private boolean exitVm;
@ -351,6 +350,7 @@ public class ShutdownMonitor
this.DEBUG = props.containsKey("DEBUG");
// 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.key = props.getProperty("STOP.KEY",null);
this.exitVm = true;

View File

@ -450,6 +450,7 @@ public class Main
private void doStop(StartArgs args)
{
String stopHost = args.getProperties().getString("STOP.HOST");
int stopPort = Integer.parseInt(args.getProperties().getString("STOP.PORT"));
String stopKey = args.getProperties().getString("STOP.KEY");
@ -457,41 +458,41 @@ public class Main
{
int stopWait = Integer.parseInt(args.getProperties().getString("STOP.WAIT"));
stop(stopPort,stopKey,stopWait);
stop(stopHost,stopPort,stopKey,stopWait);
}
else
{
stop(stopPort,stopKey);
stop(stopHost,stopPort,stopKey);
}
}
/**
* 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;
String _key = key;
if (host==null || host.length()==0)
host="127.0.0.1";
try
{
if (_port <= 0)
if (port <= 0)
{
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("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)
{
@ -500,7 +501,7 @@ public class Main
try (OutputStream out = s.getOutputStream())
{
out.write((_key + "\r\nstop\r\n").getBytes());
out.write((key + "\r\nstop\r\n").getBytes());
out.flush();
if (timeout > 0)

View File

@ -108,6 +108,10 @@ Startup / Shutdown Command Line:
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]
The port to use to stop the running Jetty server.
Required along with STOP.KEY if you want to use the --stop option above.