01: package org.mortbay.jetty.win32service;
02:
03: import org.mortbay.jetty.Server;
04: import org.tanukisoftware.wrapper.WrapperManager;
05: import org.tanukisoftware.wrapper.WrapperListener;
06: import java.io.File;
07:
08: public class JettyServiceWrapperListener implements WrapperListener {
09: private static Server __server = null;
10:
11: public JettyServiceWrapperListener() {
12: }
13:
14: public void controlEvent(int event) {
15: if (!WrapperManager.isControlledByNativeWrapper()) {
16: if ((event == WrapperManager.WRAPPER_CTRL_C_EVENT)
17: || (event == WrapperManager.WRAPPER_CTRL_CLOSE_EVENT)
18: || (event == WrapperManager.WRAPPER_CTRL_SHUTDOWN_EVENT)) {
19: WrapperManager.stop(0);
20: }
21: }
22:
23: }
24:
25: public Integer start(String[] args) {
26: for (int i = 0; i < args.length; i++) {
27: System.out.println("ARG[" + i + "] = " + args[i]);
28: }
29: org.mortbay.start.Main.main(args);
30: return null;
31: }
32:
33: public int stop(int code) {
34: try {
35: System.out
36: .println("JettyServiceWrapperListener: Stopping Jetty 6 Service!!!");
37: __server.stop();
38: System.out
39: .println("JettyServiceWrapperListener: Jetty 6 Service Stopped!!!");
40: return code;
41: } catch (Exception e) {
42: System.out.println("Stop Server Error");
43: e.printStackTrace();
44: return -1;
45: }
46:
47: }
48:
49: public static void setServer(Server server) {
50: __server = server;
51: }
52:
53: public static Server getServer() {
54: return __server;
55: }
56:
57: public static void main(String[] args) {
58: String newStrArgs[] = new String[args.length + 1];
59: newStrArgs[0] = System.getProperty("jetty.home")
60: + "etc/jetty-win32-service.xml";
61: for (int i = 0; i < args.length; i++) {
62: newStrArgs[i + 1] = args[i];
63: }
64: WrapperManager.start(new JettyServiceWrapperListener(),
65: newStrArgs);
66: }
67:
68: }
|