diff --git a/conf/default.conf.php b/conf/default.conf.php index a52f2cab50..d880ce1c9e 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -1024,6 +1024,16 @@ return array( // "phd launch taskmaster". 'phd.start-taskmasters' => 4, + // Launch daemons in "verbose" mode by default. This creates a lot of output, + // but can help debug issues. Daemons launched in debug mode with "phd debug" + // are always launched in verbose mode. See also 'phd.trace'. + 'phd.verbose' => false, + + // Launch daemons in "trace" mode by default. This creates an ENORMOUS amount + // of output, but can help debug issues. Daemons launched in debug mode with + // "phd debug" are always launched in trace mdoe. See also 'phd.verbose'. + 'phd.trace' => false, + // Path to custom celerity resource map relative to 'phabricator/src'. // See also `scripts/celerity_mapper.php`. 'celerity.resource-path' => '__celerity_resource_map__.php', diff --git a/src/infrastructure/daemon/PhabricatorDaemonControl.php b/src/infrastructure/daemon/PhabricatorDaemonControl.php index 001e55b62e..33059d4cbe 100644 --- a/src/infrastructure/daemon/PhabricatorDaemonControl.php +++ b/src/infrastructure/daemon/PhabricatorDaemonControl.php @@ -208,57 +208,59 @@ EOHELP "Daemon '{$daemon}' is not loaded, misspelled or abstract."); } - $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/'; + foreach ($argv as $key => $arg) { + $argv[$key] = escapeshellarg($arg); + } + + $flags = array(); + if ($debug || PhabricatorEnv::getEnvConfig('phd.trace')) { + $flags[] = '--trace'; + } + + if ($debug || PhabricatorEnv::getEnvConfig('phd.verbose')) { + $flags[] = '--verbose'; + } + + if (!$debug) { + $flags[] = '--daemonize'; + } + + $bootloader = PhutilBootloader::getInstance(); + foreach ($bootloader->getAllLibraries() as $library) { + if ($library == 'phutil') { + // No need to load libphutil, it's necessarily loaded implicitly by the + // daemon itself. + continue; + } + $flags[] = csprintf( + '--load-phutil-library=%s', + phutil_get_library_root($library)); + } + + $flags[] = csprintf('--conduit-uri=%s', PhabricatorEnv::getURI('/api/')); + + if (!$debug) { + $log_dir = $this->getControlDirectory('log').'/daemons.log'; + $flags[] = csprintf('--log=%s', $log_dir); + } + + $pid_dir = $this->getControlDirectory('pid'); + // TODO: This should be a much better user experience. Filesystem::assertExists($pid_dir); Filesystem::assertIsDirectory($pid_dir); Filesystem::assertWritable($pid_dir); - foreach ($argv as $key => $arg) { - $argv[$key] = escapeshellarg($arg); - } - - $bootloader = PhutilBootloader::getInstance(); - $all_libraries = $bootloader->getAllLibraries(); - - $non_default_libraries = array_diff( - $all_libraries, - array('phutil', 'phabricator')); - - $extra_libraries = array(); - foreach ($non_default_libraries as $library) { - $extra_libraries[] = csprintf( - '--load-phutil-library=%s', - phutil_get_library_root($library)); - } + $flags[] = csprintf('--phd=%s', $pid_dir); $command = csprintf( - "./launch_daemon.php ". - "%s ". - "--load-phutil-library=%s ". - "%C ". - "--conduit-uri=%s ". - "--phd=%s ". - ($debug ? '--trace ' : '--daemonize '), + './launch_daemon.php %s %C %C', $daemon, - phutil_get_library_root('phabricator'), - implode(' ', $extra_libraries), - PhabricatorEnv::getURI('/api/'), - $pid_dir); - - if (!$debug) { - // If we're running "phd debug", send output straight to the console - // instead of to a logfile. - $command = csprintf("%C --log=%s", $command, $log_dir); - } - - // Append the daemon's argv. - $command = csprintf("%C %C", $command, implode(' ', $argv)); + implode(' ', $flags), + implode(' ', $argv)); if ($debug) { // Don't terminate when the user sends ^C; it will be sent to the