diff --git a/scripts/daemon/phabricator_daemon_launcher.php b/scripts/daemon/phabricator_daemon_launcher.php index 2d1b528ef4..8283103b7f 100755 --- a/scripts/daemon/phabricator_daemon_launcher.php +++ b/scripts/daemon/phabricator_daemon_launcher.php @@ -42,6 +42,8 @@ switch (isset($argv[1]) ? $argv[1] : 'help') { if (!$need_launch) { echo "There are no repositories with tracking enabled.\n"; } else { + will_launch($control); + foreach ($need_launch as $repository) { $name = $repository->getName(); $callsign = $repository->getCallsign(); @@ -63,6 +65,8 @@ switch (isset($argv[1]) ? $argv[1] : 'help') { if (!$need_launch) { echo "There are no repositories with tracking enabled.\n"; } else { + will_launch($control); + foreach ($need_launch as $repository) { $name = $repository->getName(); $callsign = $repository->getCallsign(); @@ -159,6 +163,8 @@ switch (isset($argv[1]) ? $argv[1] : 'help') { $daemon = reset($match); } + will_launch($control); + if ($is_debug) { echo "Launching {$daemon} in debug mode (nondaemonized)...\n"; } else { @@ -210,3 +216,11 @@ function phd_load_tracked_repositories() { return $repositories; } + +function will_launch($control) { + echo "Staging launch...\n"; + $control->pingConduit(); + $log_dir = $control->getControlDirectory('log').'/daemons.log'; + echo "NOTE: Logs will appear in '{$log_dir}'.\n\n"; +} + diff --git a/src/infrastructure/daemon/control/PhabricatorDaemonControl.php b/src/infrastructure/daemon/control/PhabricatorDaemonControl.php index 1936862bba..938d890fba 100644 --- a/src/infrastructure/daemon/control/PhabricatorDaemonControl.php +++ b/src/infrastructure/daemon/control/PhabricatorDaemonControl.php @@ -163,6 +163,19 @@ EOHELP return 1; } + public function pingConduit() { + // It's fairly common to have issues here, e.g. because Phabricator isn't + // running, isn't accessible, you put the domain in your hostsfile but it + // isn't available on the production host, etc. If any of this doesn't work, + // conduit will throw. + + // We do this here rather than in the daemon since there's an HTTPS + curl + // + fork issue of some kind that makes + $conduit = new ConduitClient(PhabricatorEnv::getURI('/api/')); + $conduit->setTimeout(5); + $conduit->callMethodSynchronous('conduit.ping', array()); + } + public function launchDaemon($daemon, array $argv, $debug = false) { $symbols = $this->loadAvailableDaemonClasses(); $symbols = ipull($symbols, 'name', 'name'); @@ -171,6 +184,7 @@ EOHELP } $pid_dir = $this->getControlDirectory('pid'); + $log_dir = $this->getControlDirectory('log').'/daemons.log'; $libphutil_root = dirname(phutil_get_library_root('phutil')); $launch_daemon = $libphutil_root.'/scripts/daemon/'; @@ -205,12 +219,14 @@ EOHELP implode(' ', $extra_libraries)." ". "--conduit-uri=%s ". "--phd=%s ". + "--log=%s ". ($debug ? '--trace ' : '--daemonize '). implode(' ', $argv), $daemon, phutil_get_library_root('phabricator'), PhabricatorEnv::getURI('/api/'), - $pid_dir); + $pid_dir, + $log_dir); if ($debug) { // Don't terminate when the user sends ^C; it will be sent to the @@ -234,7 +250,7 @@ EOHELP return; } - protected function getControlDirectory($dir) { + public function getControlDirectory($dir) { $path = PhabricatorEnv::getEnvConfig('phd.pid-directory').'/'.$dir; if (!Filesystem::pathExists($path)) { list($err) = exec_manual('mkdir -p %s', $path);