int killDb(int port, ProcessId _pid, int signal, const BSONObj& opt) {
|
ProcessId pid;
|
int exitCode = 0;
|
if (port > 0) {
|
if (!registry.isPortRegistered(port)) {
|
log() << "No db started on port: " << port << endl;
|
return 0;
|
}
|
pid = registry.pidForPort(port);
|
} else {
|
pid = _pid;
|
}
|
|
kill_wrapper(pid, signal, port, opt);
|
|
int i = 0;
|
for (; i < 130; ++i) {
|
if (i == 60) {
|
log() << "process on port " << port << ", with pid " << pid
|
<< " not terminated, sending sigkill" << endl;
|
kill_wrapper(pid, SIGKILL, port, opt);
|
}
|
if (wait_for_pid(pid, false, &exitCode))
|
break;
|
sleepmillis(1000);
|
}
|
if (i == 130) {
|
log() << "failed to terminate process on port " << port << ", with pid " << pid << endl;
|
verify("Failed to terminate process" == 0);
|
}
|
|
registry.deleteProgram(pid);
|
// FIXME I think the intention here is to do an extra sleep only when SIGKILL is sent to the
|
// child process. We may want to change the 4 below to 29, since values of i greater than that
|
// indicate we sent a SIGKILL.
|
if (i > 4 || signal == SIGKILL) {
|
sleepmillis(4000); // allow operating system to reclaim resources
|
}
|
|
return exitCode;
|
}
|