1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00

Don't fatal on daemon status updates from phd

Summary:
See D3126, T1667, T1658. Prior to D3126, `phd` did not use MySQL directly. Now that it does, there are at least two specific problems (see inline comment).

In the long term, we should probably break this dependency and use Conduit. However, we don't currently have access to the daemon log ID and getting it is a mess (the overseer generates it), and I think I want to rewrite how all this works at some point anyway (the daemon calls are currently completely unauthenticated, which is silly -- we should move them to an authenticated channel at some point, I think).

Test Plan: Ran `phd stop` with a bad MySQL config against a non-running daemon, didn't get a query error.

Reviewers: nh, vrana, btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1667, T1658

Differential Revision: https://secure.phabricator.com/D3314
This commit is contained in:
epriestley 2012-08-16 14:13:24 -07:00
parent 2a815e0715
commit 5342bb1073
2 changed files with 28 additions and 19 deletions

View file

@ -53,12 +53,7 @@ final class PhabricatorDaemonControl {
foreach ($daemons as $daemon) {
$name = $daemon->getName();
if (!$daemon->isRunning()) {
$daemon_log = $daemon->loadDaemonLog();
if ($daemon_log) {
$daemon_log->setStatus(PhabricatorDaemonLog::STATUS_DEAD);
$daemon_log->save();
}
$daemon->updateStatus(PhabricatorDaemonLog::STATUS_DEAD);
$status = 2;
$name = '<DEAD> '.$name;
}
@ -116,11 +111,7 @@ final class PhabricatorDaemonControl {
if (!$daemon->isRunning()) {
echo "Daemon is not running.\n";
unset($running[$key]);
$daemon_log = $daemon->loadDaemonLog();
if ($daemon_log) {
$daemon_log->setStatus(PhabricatorDaemonLog::STATUS_EXITED);
$daemon_log->save();
}
$daemon->updateStatus(PhabricatorDaemonLog::STATUS_EXITED);
} else {
posix_kill($pid, SIGINT);
}

View file

@ -35,15 +35,33 @@ final class PhabricatorDaemonReference {
return $ref;
}
public function loadDaemonLog() {
if (!$this->daemonLog) {
$this->daemonLog = id(new PhabricatorDaemonLog())->loadOneWhere(
'daemon = %s AND pid = %d AND dateCreated = %d',
$this->name,
$this->pid,
$this->start);
public function updateStatus($new_status) {
try {
if (!$this->daemonLog) {
$this->daemonLog = id(new PhabricatorDaemonLog())->loadOneWhere(
'daemon = %s AND pid = %d AND dateCreated = %d',
$this->name,
$this->pid,
$this->start);
}
if ($this->daemonLog) {
$this->daemonLog
->setStatus($new_status)
->save();
}
} catch (AphrontQueryException $ex) {
// Ignore anything that goes wrong here. We anticipate at least two
// specific failure modes:
//
// - Upgrade scripts which run `git pull`, then `phd stop`, then
// `bin/storage upgrade` will fail when trying to update the `status`
// column, as it does not exist yet.
// - Daemons running on machines which do not have access to MySQL
// (like an IRC bot) will not be able to load or save the log.
//
//
}
return $this->daemonLog;
}
public function getPID() {