New daemon start/stop methods for use with Procrun
Added additional entry points GerritLauncher.daemonStart and GerritLauncher.daemonStop for use when hosting Gerrit in some other process. The intention of this is to make it an easy fit to the [Apache Commons Daemon Procrun][1]. This adds an easy way to host Gerrit with embedded Jetty as Windows Service. Also moved a bit of logic in Daemon from anonymous thread into the stop method. [1]: http://commons.apache.org/proper/commons-daemon/procrun.html Change-Id: Ie1fd3b7fceb56e159dc7f02fbcf481b0fcdb08e2
This commit is contained in:
@@ -55,6 +55,8 @@ public final class GerritLauncher {
|
||||
private static final String pkg = "com.google.gerrit.pgm";
|
||||
public static final String NOT_ARCHIVED = "NOT_ARCHIVED";
|
||||
|
||||
private static ClassLoader daemonClassLoader;
|
||||
|
||||
public static void main(final String[] argv) throws Exception {
|
||||
System.exit(mainImpl(argv));
|
||||
}
|
||||
@@ -102,6 +104,44 @@ public final class GerritLauncher {
|
||||
return invokeProgram(cl, argv);
|
||||
}
|
||||
|
||||
public static void daemonStart(final String[] argv) throws Exception {
|
||||
if (daemonClassLoader != null) {
|
||||
throw new IllegalStateException(
|
||||
"daemonStart can be called only once per JVM instance");
|
||||
}
|
||||
final ClassLoader cl = libClassLoader(false);
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
|
||||
daemonClassLoader = cl;
|
||||
|
||||
String[] daemonArgv = new String[argv.length + 1];
|
||||
daemonArgv[0] = "daemon";
|
||||
for (int i = 0; i < argv.length; i++) {
|
||||
daemonArgv[i + 1] = argv[i];
|
||||
}
|
||||
int res = invokeProgram(cl, daemonArgv);
|
||||
if (res != 0) {
|
||||
throw new Exception("Unexpected return value: " + res);
|
||||
}
|
||||
}
|
||||
|
||||
public static void daemonStop(final String[] argv) throws Exception {
|
||||
if (daemonClassLoader == null) {
|
||||
throw new IllegalStateException(
|
||||
"daemonStop can be called only after call to daemonStop");
|
||||
}
|
||||
String[] daemonArgv = new String[argv.length + 2];
|
||||
daemonArgv[0] = "daemon";
|
||||
daemonArgv[1] = "--stop-only";
|
||||
for (int i = 0; i < argv.length; i++) {
|
||||
daemonArgv[i + 2] = argv[i];
|
||||
}
|
||||
int res = invokeProgram(daemonClassLoader, daemonArgv);
|
||||
if (res != 0) {
|
||||
throw new Exception("Unexpected return value: " + res);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isProlog(String cn) {
|
||||
return "PrologShell".equals(cn) || "Rulec".equals(cn);
|
||||
}
|
||||
|
Reference in New Issue
Block a user