gerrit.sh: Wait until the daemon is serving requests
Don't display "OK" until the daemon is able to serve requests. This permits subsequent scripts to rely on our exit status to know whether or not Gerrit Code Review is ready. We now wait up to 90 seconds for the server to come online before we report "OK" or "FAILED" to the console and the caller. Because its difficult to compute the exact network addresses that the daemon will be listening on, we instead pass it a magic cookie as part of the arguments. When the daemon's network listeners are accepting connections the main thread writes that cookie into the logs/gerrit.run file. The calling script polls that file until the cookie shows up. Bug: issue 451 Change-Id: Ic5018b347a5037221c3d26c16c71173f5071d244 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -42,6 +42,9 @@ import org.kohsuke.args4j.Option;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -73,6 +76,9 @@ public class Daemon extends SiteProgram {
|
||||
@Option(name = "--console-log", usage = "Log to console (not $site_path/logs)")
|
||||
private boolean consoleLog;
|
||||
|
||||
@Option(name = "--run-id", usage = "Cookie to store in $site_path/logs/gerrit.run")
|
||||
private String runId;
|
||||
|
||||
private final LifecycleManager manager = new LifecycleManager();
|
||||
private Injector dbInjector;
|
||||
private Injector cfgInjector;
|
||||
@@ -80,11 +86,16 @@ public class Daemon extends SiteProgram {
|
||||
private Injector sshInjector;
|
||||
private Injector webInjector;
|
||||
private Injector httpdInjector;
|
||||
private File runFile;
|
||||
|
||||
@Override
|
||||
public int run() throws Exception {
|
||||
mustHaveValidSite();
|
||||
|
||||
if (runId != null) {
|
||||
runFile = new File(new File(getSitePath(), "logs"), "gerrit.run");
|
||||
}
|
||||
|
||||
if (httpd == null) {
|
||||
httpd = !slave;
|
||||
}
|
||||
@@ -119,13 +130,33 @@ public class Daemon extends SiteProgram {
|
||||
}
|
||||
|
||||
manager.start();
|
||||
log.info("Gerrit Code Review " + myVersion() + " ready");
|
||||
RuntimeShutdown.add(new Runnable() {
|
||||
public void run() {
|
||||
log.info("caught shutdown, cleaning up");
|
||||
if (runId != null) {
|
||||
runFile.delete();
|
||||
}
|
||||
manager.stop();
|
||||
}
|
||||
});
|
||||
|
||||
log.info("Gerrit Code Review " + myVersion() + " ready");
|
||||
if (runId != null) {
|
||||
try {
|
||||
runFile.createNewFile();
|
||||
runFile.setReadable(true, false);
|
||||
|
||||
FileOutputStream out = new FileOutputStream(runFile);
|
||||
try {
|
||||
out.write((runId + "\n").getBytes("UTF-8"));
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
} catch (IOException err) {
|
||||
log.warn("Cannot write --run-id to " + runFile, err);
|
||||
}
|
||||
}
|
||||
|
||||
RuntimeShutdown.waitFor();
|
||||
return 0;
|
||||
}
|
||||
|
@@ -99,6 +99,7 @@ public class LogFileCompressor implements Runnable {
|
||||
return ErrorLogFile.LOG_NAME.equals(name) //
|
||||
|| "sshd_log".equals(name) //
|
||||
|| "httpd_log".equals(name) //
|
||||
|| "gerrit.run".equals(name) //
|
||||
|| name.endsWith(".pid");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user