1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +01:00

Add --verbose support to phd

Summary:
Support the `--verbose` flag added in D2795 in `phd`. See T1389.

Also simplify argument generation a little bit.

Test Plan: Ran "nice" daemon with debug,  daemon + verbose, daemon + no verbose.

Reviewers: vrana, jungejason, edward, aurelijus

Reviewed By: aurelijus

CC: aran

Maniphest Tasks: T1389

Differential Revision: https://secure.phabricator.com/D2797
This commit is contained in:
epriestley 2012-06-19 12:56:41 -07:00
parent d4b6b095cb
commit fabe52335e
2 changed files with 52 additions and 40 deletions

View file

@ -1024,6 +1024,16 @@ return array(
// "phd launch <N> taskmaster". // "phd launch <N> taskmaster".
'phd.start-taskmasters' => 4, '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'. // Path to custom celerity resource map relative to 'phabricator/src'.
// See also `scripts/celerity_mapper.php`. // See also `scripts/celerity_mapper.php`.
'celerity.resource-path' => '__celerity_resource_map__.php', 'celerity.resource-path' => '__celerity_resource_map__.php',

View file

@ -208,57 +208,59 @@ EOHELP
"Daemon '{$daemon}' is not loaded, misspelled or abstract."); "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')); $libphutil_root = dirname(phutil_get_library_root('phutil'));
$launch_daemon = $libphutil_root.'/scripts/daemon/'; $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. // TODO: This should be a much better user experience.
Filesystem::assertExists($pid_dir); Filesystem::assertExists($pid_dir);
Filesystem::assertIsDirectory($pid_dir); Filesystem::assertIsDirectory($pid_dir);
Filesystem::assertWritable($pid_dir); Filesystem::assertWritable($pid_dir);
foreach ($argv as $key => $arg) { $flags[] = csprintf('--phd=%s', $pid_dir);
$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));
}
$command = csprintf( $command = csprintf(
"./launch_daemon.php ". './launch_daemon.php %s %C %C',
"%s ".
"--load-phutil-library=%s ".
"%C ".
"--conduit-uri=%s ".
"--phd=%s ".
($debug ? '--trace ' : '--daemonize '),
$daemon, $daemon,
phutil_get_library_root('phabricator'), implode(' ', $flags),
implode(' ', $extra_libraries), implode(' ', $argv));
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));
if ($debug) { if ($debug) {
// Don't terminate when the user sends ^C; it will be sent to the // Don't terminate when the user sends ^C; it will be sent to the