-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added clean shutdown hooks to jetty.
- Loading branch information
Showing
9 changed files
with
239 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ zktodo2test.dat.properties | |
/.settings | ||
/.openshift | ||
/zktodo2test.dat.script | ||
/nohup.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --port $PORT target/*.war | ||
web: java $JAVA_OPTS -jar target/jetty-runner-jmx.jar --port $PORT target/*.war | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"> | ||
|
||
<!-- ============================================================================ --> | ||
<!-- To correctly start Jetty with JMX module enabled, this configuration --> | ||
<!-- file must appear first in the list of the configuration files. --> | ||
<!-- The simplest way to achieve this is to add etc/jetty-jmx.xml as the --> | ||
<!-- first file in configuration file list at the end of start.ini file. --> | ||
<!-- ============================================================================ --> | ||
<Configure id="Server" class="org.eclipse.jetty.server.Server"> | ||
|
||
<!-- =========================================================== --> | ||
<!-- Set the java.rmi.server.hostname property in case you've --> | ||
<!-- got a misconfigured /etc/hosts entry or the like. --> | ||
<!-- =========================================================== --> | ||
<!-- | ||
<Call class="java.lang.System" name="setProperty"> | ||
<Arg>java.rmi.server.hostname</Arg> | ||
<Arg>127.0.0.1</Arg> | ||
</Call> | ||
--> | ||
|
||
<!-- =========================================================== --> | ||
<!-- Initialize an mbean server --> | ||
<!-- =========================================================== --> | ||
<Call id="MBeanServer" class="java.lang.management.ManagementFactory" | ||
name="getPlatformMBeanServer" /> | ||
|
||
<!-- =========================================================== --> | ||
<!-- Initialize the Jetty MBean container --> | ||
<!-- =========================================================== --> | ||
<New id="MBeanContainer" class="org.eclipse.jetty.jmx.MBeanContainer"> | ||
<Arg><Ref id="MBeanServer" /></Arg> | ||
<Call name="start"/> | ||
</New> | ||
|
||
<!-- Add to the Server to listen for object events --> | ||
<Get id="Container" name="container"> | ||
<Call name="addEventListener"> | ||
<Arg><Ref id="MBeanContainer" /></Arg> | ||
</Call> | ||
</Get> | ||
|
||
<!-- Add to the Server as a managed lifecycle --> | ||
<Call name="addBean"> | ||
<Arg><Ref id="MBeanContainer"/></Arg> | ||
<Arg type="boolean">true</Arg> | ||
</Call> | ||
|
||
<!-- Add the static log --> | ||
<Ref id="MBeanContainer"> | ||
<Call name="addBean"> | ||
<Arg> | ||
<New class="org.eclipse.jetty.util.log.Log"/> | ||
</Arg> | ||
</Call> | ||
</Ref> | ||
|
||
<!-- In order to connect to the JMX server remotely from a different | ||
process, possibly running on a different host, Jetty JMX module | ||
can create a remote JMX connector. It requires RMI registry to | ||
be started prior to creating the connector server because the | ||
JMX specification uses RMI to facilitate connections. | ||
--> | ||
|
||
<!-- Optionally start the RMI registry. Normally RMI registry runs on | ||
port 1099. The argument below can be changed in order to comply | ||
with the firewall requirements. | ||
--> | ||
|
||
<Call name="createRegistry" class="java.rmi.registry.LocateRegistry"> | ||
<Arg type="java.lang.Integer"><SystemProperty name="jetty.jmxrmiport" default="1099"/></Arg> | ||
<Call name="sleep" class="java.lang.Thread"> | ||
<Arg type="java.lang.Integer">1000</Arg> | ||
</Call> | ||
</Call> | ||
|
||
|
||
<!-- Optionally add a remote JMX connector. The parameters of the constructor | ||
below specify the JMX service URL, and the object name string for the | ||
connector server bean. The parameters of the JMXServiceURL constructor | ||
specify the protocol that clients will use to connect to the remote JMX | ||
connector (RMI), the hostname of the server (local hostname), port number | ||
(automatically assigned), and the URL path. Note that URL path contains | ||
the RMI registry hostname and port number, that may need to be modified | ||
in order to comply with the firewall requirements. | ||
--> | ||
|
||
<New id="ConnectorServer" class="org.eclipse.jetty.jmx.ConnectorServer"> | ||
<Arg> | ||
<New class="javax.management.remote.JMXServiceURL"> | ||
<Arg type="java.lang.String">rmi</Arg> | ||
<Arg type="java.lang.String" /> | ||
<Arg type="java.lang.Integer"><SystemProperty name="jetty.jmxrmiport" default="1099"/></Arg> | ||
<Arg type="java.lang.String">/jndi/rmi://<SystemProperty name="jetty.jmxrmihost" default="localhost"/>:<SystemProperty name="jetty.jmxrmiport" default="1099"/>/jmxrmi</Arg> | ||
</New> | ||
</Arg> | ||
<Arg>org.eclipse.jetty.jmx:name=rmiconnectorserver</Arg> | ||
<Call name="start" /> | ||
</New> | ||
</Configure> | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.zkforge.zktodo2.jetty; | ||
|
||
import static java.lang.System.out; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.management.InstanceNotFoundException; | ||
import javax.management.MBeanException; | ||
import javax.management.MBeanServerConnection; | ||
import javax.management.MalformedObjectNameException; | ||
import javax.management.ObjectName; | ||
import javax.management.ReflectionException; | ||
import javax.management.remote.JMXConnector; | ||
import javax.management.remote.JMXConnectorFactory; | ||
import javax.management.remote.JMXServiceURL; | ||
|
||
/** | ||
* A class to do a clean shutdown of a jetty server which has jmx management | ||
* interfaces enabled. | ||
* | ||
* @author simbo | ||
*/ | ||
public class StopJettyJmx { | ||
|
||
enum Paramaeters { | ||
NAME_JETTY_JMX("org.eclipse.jetty.jmx:name=rmiconnectorserver") | ||
, NAME_JETTY_SERVER("org.eclipse.jetty.server:type=server,id=0") | ||
, NAME_JETTY_MAVEN("org.mortbay.jetty.plugin:type=jettyserver,id=0"); | ||
final String val; | ||
Paramaeters(String val){ | ||
this.val = val; | ||
} | ||
} | ||
enum Commands { | ||
COMMAND_STOP("stop"); | ||
final String val; | ||
Commands(String val){ | ||
this.val = val; | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
if (args.length != 2) { | ||
usage(); | ||
System.exit(-1); | ||
} | ||
|
||
final String type = args[0]; | ||
out.println("type: " + type); | ||
final String jmxUrl = args[1]; | ||
out.println("jmxUrl: " + jmxUrl); | ||
|
||
try { | ||
JMXConnector jmxc = JMXConnectorFactory.connect(new JMXServiceURL( | ||
jmxUrl), null); | ||
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); | ||
|
||
if (type.equalsIgnoreCase(Paramaeters.NAME_JETTY_SERVER.name())) { | ||
invoke(mbsc, Paramaeters.NAME_JETTY_SERVER, Commands.COMMAND_STOP); | ||
invoke(mbsc, Paramaeters.NAME_JETTY_JMX, Commands.COMMAND_STOP); | ||
} else if( type.equalsIgnoreCase(Paramaeters.NAME_JETTY_MAVEN.name())){ | ||
invoke(mbsc, Paramaeters.NAME_JETTY_MAVEN, Commands.COMMAND_STOP); | ||
} else { | ||
throw new IllegalArgumentException(String.format("I don't understand '%s' please use %s or %s", type, Paramaeters.NAME_JETTY_SERVER.name(), Paramaeters.NAME_JETTY_MAVEN.name())); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
System.exit(-1); | ||
} | ||
} | ||
|
||
protected static void invoke(MBeanServerConnection mbsc, Paramaeters object, | ||
Commands command) throws MalformedObjectNameException, | ||
InstanceNotFoundException, MBeanException, ReflectionException, | ||
IOException { | ||
ObjectName jettyServer = new ObjectName(object.val); | ||
mbsc.invoke(jettyServer, command.val, null, null); | ||
} | ||
|
||
private static void usage() { | ||
out.println("usage:"); | ||
out.println("\tjava " + StopJettyJmx.class.getCanonicalName() | ||
+ " [NAME_JETTY_SERVER|NAME_JETTY_MAVEN] JMX_URL"); | ||
out.println("where JMX_URL is shown on the jetty startup log"); | ||
out.println("e.g. java " | ||
+ StopJettyJmx.class.getCanonicalName() | ||
+ " NAME_JETTY_SERVER service:jmx:rmi://Simon-Masseys-Mac-mini-2.local:1099/jndi/rmi://localhost:1099/jmxrmi"); | ||
out.println("N.B If you want to be able to make a remote connnection you need to start the server with -Dcom.sun.management.jmxremote.* options."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters