Differential D11860 Diff 28618 src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | abstract class PhabricatorDaemonManagementWorkflow | ||||
protected final function launchDaemons( | protected final function launchDaemons( | ||||
array $daemons, | array $daemons, | ||||
$debug, | $debug, | ||||
$run_as_current_user = false) { | $run_as_current_user = false) { | ||||
// Convert any shorthand classnames like "taskmaster" into proper class | // Convert any shorthand classnames like "taskmaster" into proper class | ||||
// names. | // names. | ||||
foreach ($daemons as $key => $daemon) { | foreach ($daemons as $key => $daemon) { | ||||
$class = $this->findDaemonClass($daemon[0]); | $class = $this->findDaemonClass($daemon['class']); | ||||
$daemons[$key][0] = $class; | $daemons[$key]['class'] = $class; | ||||
} | } | ||||
$console = PhutilConsole::getConsole(); | $console = PhutilConsole::getConsole(); | ||||
if (!$run_as_current_user) { | if (!$run_as_current_user) { | ||||
// Check if the script is started as the correct user | // Check if the script is started as the correct user | ||||
$phd_user = PhabricatorEnv::getEnvConfig('phd.user'); | $phd_user = PhabricatorEnv::getEnvConfig('phd.user'); | ||||
$current_user = posix_getpwuid(posix_geteuid()); | $current_user = posix_getpwuid(posix_geteuid()); | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | protected final function launchDaemons( | ||||
$pid_dir = $this->getPIDDirectory(); | $pid_dir = $this->getPIDDirectory(); | ||||
// 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); | ||||
$config['piddir'] = $pid_dir; | $config['piddir'] = $pid_dir; | ||||
$config['daemons'] = $daemons; | |||||
$config['daemons'] = array(); | |||||
foreach ($daemons as $daemon) { | |||||
list($class, $argv) = $daemon; | |||||
$config['daemons'][] = array( | |||||
'class' => $class, | |||||
'argv' => $argv, | |||||
); | |||||
} | |||||
$command = csprintf('./phd-daemon %Ls', $flags); | $command = csprintf('./phd-daemon %Ls', $flags); | ||||
$phabricator_root = dirname(phutil_get_library_root('phabricator')); | $phabricator_root = dirname(phutil_get_library_root('phabricator')); | ||||
$daemon_script_dir = $phabricator_root.'/scripts/daemon/'; | $daemon_script_dir = $phabricator_root.'/scripts/daemon/'; | ||||
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 | ||||
▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | if ($keep_leases) { | ||||
$console->writeErr("%s\n", pht('Freeing active task leases...')); | $console->writeErr("%s\n", pht('Freeing active task leases...')); | ||||
$count = $this->freeActiveLeases(); | $count = $this->freeActiveLeases(); | ||||
$console->writeErr( | $console->writeErr( | ||||
"%s\n", | "%s\n", | ||||
pht('Freed %s task lease(s).', new PhutilNumber($count))); | pht('Freed %s task lease(s).', new PhutilNumber($count))); | ||||
} | } | ||||
$daemons = array( | $daemons = array( | ||||
array('PhabricatorRepositoryPullLocalDaemon', array()), | array( | ||||
array('PhabricatorGarbageCollectorDaemon', array()), | 'class' => 'PhabricatorRepositoryPullLocalDaemon', | ||||
array('PhabricatorTriggerDaemon', array()), | ), | ||||
array( | |||||
'class' => 'PhabricatorGarbageCollectorDaemon', | |||||
), | |||||
array( | |||||
'class' => 'PhabricatorTriggerDaemon', | |||||
), | |||||
); | ); | ||||
$taskmasters = PhabricatorEnv::getEnvConfig('phd.start-taskmasters'); | $taskmasters = PhabricatorEnv::getEnvConfig('phd.start-taskmasters'); | ||||
for ($ii = 0; $ii < $taskmasters; $ii++) { | for ($ii = 0; $ii < $taskmasters; $ii++) { | ||||
$daemons[] = array('PhabricatorTaskmasterDaemon', array()); | $daemons[] = array( | ||||
'class' => 'PhabricatorTaskmasterDaemon', | |||||
); | |||||
} | } | ||||
$this->launchDaemons($daemons, $is_debug = false); | $this->launchDaemons($daemons, $is_debug = false); | ||||
$console->writeErr(pht('Done.')."\n"); | $console->writeErr(pht('Done.')."\n"); | ||||
return 0; | return 0; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 217 Lines • ▼ Show 20 Lines | private function printLaunchingDaemons(array $daemons, $debug) { | ||||
} | } | ||||
$log_dir = $this->getLogDirectory().'/daemons.log'; | $log_dir = $this->getLogDirectory().'/daemons.log'; | ||||
$console->writeOut( | $console->writeOut( | ||||
"\n%s\n\n", | "\n%s\n\n", | ||||
pht('(Logs will appear in "%s".)', $log_dir)); | pht('(Logs will appear in "%s".)', $log_dir)); | ||||
foreach ($daemons as $daemon) { | foreach ($daemons as $daemon) { | ||||
list($class, $argv) = $daemon; | $is_autoscale = isset($daemon['autoscale']['group']); | ||||
$console->writeOut(" %s %s\n", $class, implode(' ', $argv)); | if ($is_autoscale) { | ||||
$autoscale = pht('(Autoscaling)'); | |||||
} else { | |||||
$autoscale = pht('(Static)'); | |||||
} | |||||
$console->writeOut( | |||||
" %s %s\n", | |||||
$daemon['class'], | |||||
$autoscale, | |||||
implode(' ', idx($daemon, 'argv', array()))); | |||||
} | } | ||||
$console->writeOut("\n"); | $console->writeOut("\n"); | ||||
} | } | ||||
} | } |