Merge "Catch daemon startup failures in error_log"

This commit is contained in:
Shawn O. Pearce
2010-03-02 22:27:18 -08:00
committed by Android Code Review

View File

@@ -116,49 +116,54 @@ public class Daemon extends SiteProgram {
manager.add(ErrorLogFile.start(getSitePath())); manager.add(ErrorLogFile.start(getSitePath()));
} }
dbInjector = createDbInjector(MULTI_USER); try {
cfgInjector = createCfgInjector(); dbInjector = createDbInjector(MULTI_USER);
sysInjector = createSysInjector(); cfgInjector = createCfgInjector();
manager.add(dbInjector, cfgInjector, sysInjector); sysInjector = createSysInjector();
manager.add(dbInjector, cfgInjector, sysInjector);
if (sshd) { if (sshd) {
initSshd(); initSshd();
}
if (httpd) {
initHttpd();
}
manager.start();
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 (httpd) {
if (runId != null) { initHttpd();
try { }
runFile.createNewFile();
runFile.setReadable(true, false);
FileOutputStream out = new FileOutputStream(runFile); manager.start();
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 { try {
out.write((runId + "\n").getBytes("UTF-8")); runFile.createNewFile();
} finally { runFile.setReadable(true, false);
out.close();
}
} catch (IOException err) {
log.warn("Cannot write --run-id to " + runFile, err);
}
}
RuntimeShutdown.waitFor(); FileOutputStream out = new FileOutputStream(runFile);
return 0; 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;
} catch (Throwable err) {
log.error("Unable to start daemon", err);
return 1;
}
} }
private String myVersion() { private String myVersion() {