diff --git a/resources/sql/autopatches/20140822.daemonenvhash.sql b/resources/sql/autopatches/20140822.daemonenvhash.sql new file mode 100644 index 0000000000..fb95ecec35 --- /dev/null +++ b/resources/sql/autopatches/20140822.daemonenvhash.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_daemon.daemon_log + ADD COLUMN `envHash` CHAR(40) NOT NULL DEFAULT '' AFTER `dateModified`; diff --git a/src/applications/config/check/PhabricatorSetupCheckDaemons.php b/src/applications/config/check/PhabricatorSetupCheckDaemons.php index e70a44968d..8ea68debbe 100644 --- a/src/applications/config/check/PhabricatorSetupCheckDaemons.php +++ b/src/applications/config/check/PhabricatorSetupCheckDaemons.php @@ -31,6 +31,7 @@ final class PhabricatorSetupCheckDaemons extends PhabricatorSetupCheck { 'a', array( 'href' => $doc_href, + 'target' => '_blank' ), pht('Managing Daemons with phd'))); @@ -42,5 +43,44 @@ final class PhabricatorSetupCheckDaemons extends PhabricatorSetupCheck { ->addCommand('phabricator/ $ ./bin/phd start'); } + $environment_hash = PhabricatorEnv::calculateEnvironmentHash(); + $all_daemons = id(new PhabricatorDaemonLogQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE) + ->execute(); + foreach ($all_daemons as $daemon) { + if ($daemon->getEnvHash() != $environment_hash) { + $doc_href = PhabricatorEnv::getDocLink( + 'Managing Daemons with phd'); + + $summary = pht( + 'You should restart the daemons. Their configuration is out of '. + 'date.'); + + $message = pht( + 'The Phabricator daemons are running with an out of date '. + 'configuration. If you are making multiple configuration changes, '. + 'you only need to restart the daemons once after the last change.'. + "\n\n". + 'Use %s to restart daemons. See %s for more information.', + phutil_tag('tt', array(), 'bin/phd restart'), + phutil_tag( + 'a', + array( + 'href' => $doc_href, + 'target' => '_blank' + ), + pht('Managing Daemons with phd'))); + + $this->newIssue('daemons.need-restarting') + ->setShortName(pht('Daemons Need Restarting')) + ->setName(pht('Phabricator Daemons Need Restarting')) + ->setSummary($summary) + ->setMessage($message) + ->addCommand('phabricator/ $ ./bin/phd restart'); + break; + } + } } + } diff --git a/src/applications/daemon/event/PhabricatorDaemonEventListener.php b/src/applications/daemon/event/PhabricatorDaemonEventListener.php index 0fc78daa97..a17b14338f 100644 --- a/src/applications/daemon/event/PhabricatorDaemonEventListener.php +++ b/src/applications/daemon/event/PhabricatorDaemonEventListener.php @@ -39,6 +39,7 @@ final class PhabricatorDaemonEventListener extends PhabricatorEventListener { ->setDaemon($event->getValue('daemonClass')) ->setHost(php_uname('n')) ->setPID(getmypid()) + ->setEnvHash(PhabricatorEnv::calculateEnvironmentHash()) ->setStatus(PhabricatorDaemonLog::STATUS_RUNNING) ->setArgv($event->getValue('argv')) ->setExplicitArgv($event->getValue('explicitArgv')) diff --git a/src/applications/daemon/storage/PhabricatorDaemonLog.php b/src/applications/daemon/storage/PhabricatorDaemonLog.php index 73f3a78eb7..0077e30680 100644 --- a/src/applications/daemon/storage/PhabricatorDaemonLog.php +++ b/src/applications/daemon/storage/PhabricatorDaemonLog.php @@ -15,6 +15,7 @@ final class PhabricatorDaemonLog extends PhabricatorDaemonDAO protected $pid; protected $argv; protected $explicitArgv = array(); + protected $envHash; protected $status; public function getConfiguration() { diff --git a/src/infrastructure/env/PhabricatorEnv.php b/src/infrastructure/env/PhabricatorEnv.php index 8fd6efe5ec..d5e3237b88 100644 --- a/src/infrastructure/env/PhabricatorEnv.php +++ b/src/infrastructure/env/PhabricatorEnv.php @@ -221,6 +221,15 @@ final class PhabricatorEnv { return $env; } + public static function calculateEnvironmentHash() { + $keys = array_keys(self::getAllConfigKeys()); + $values = array(); + foreach ($keys as $key) { + $values[$key] = self::getEnvConfigIfExists($key); + } + return PhabricatorHash::digest(json_encode($values)); + } + /* -( Reading Configuration )---------------------------------------------- */