Differential D20643 Diff 49246 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 65 Lines • ▼ Show 20 Lines | private function findDaemonClass($substring) { | ||||
} | } | ||||
return head($match); | return head($match); | ||||
} | } | ||||
final protected function launchDaemons( | final protected function launchDaemons( | ||||
array $daemons, | array $daemons, | ||||
$debug, | $debug, | ||||
$foreground = false, | |||||
$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['class']); | $class = $this->findDaemonClass($daemon['class']); | ||||
$daemons[$key]['class'] = $class; | $daemons[$key]['class'] = $class; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | final protected function launchDaemons( | ||||
$instance = $this->getInstance(); | $instance = $this->getInstance(); | ||||
if ($instance) { | if ($instance) { | ||||
$flags[] = '-l'; | $flags[] = '-l'; | ||||
$flags[] = $instance; | $flags[] = $instance; | ||||
} | } | ||||
$config = array(); | $config = array(); | ||||
if (!$debug) { | if (!$foreground) { | ||||
$config['daemonize'] = true; | $config['daemonize'] = true; | ||||
} | |||||
if (!$debug) { | |||||
$config['log'] = $this->getLogDirectory().'/daemons.log'; | $config['log'] = $this->getLogDirectory().'/daemons.log'; | ||||
} | } | ||||
$config['daemons'] = $daemons; | $config['daemons'] = $daemons; | ||||
$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 ($foreground) { | ||||
// 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 | ||||
// subprocess which will terminate normally. | // subprocess which will terminate normally. | ||||
pcntl_signal( | pcntl_signal( | ||||
SIGINT, | SIGINT, | ||||
array(__CLASS__, 'ignoreSignal')); | array(__CLASS__, 'ignoreSignal')); | ||||
echo "\n phabricator/scripts/daemon/ \$ {$command}\n\n"; | echo "\n phabricator/scripts/daemon/ \$ {$command}\n\n"; | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | |||||
/* -( Commands )----------------------------------------------------------- */ | /* -( Commands )----------------------------------------------------------- */ | ||||
final protected function executeStartCommand(array $options) { | final protected function executeStartCommand(array $options) { | ||||
PhutilTypeSpec::checkMap( | PhutilTypeSpec::checkMap( | ||||
$options, | $options, | ||||
array( | array( | ||||
'keep-leases' => 'optional bool', | 'keep-leases' => 'optional bool', | ||||
'force' => 'optional bool', | 'force' => 'optional bool', | ||||
'foreground' => 'optional bool', | |||||
'reserve' => 'optional float', | 'reserve' => 'optional float', | ||||
)); | )); | ||||
$console = PhutilConsole::getConsole(); | $console = PhutilConsole::getConsole(); | ||||
if (!idx($options, 'force')) { | if (!idx($options, 'force')) { | ||||
$process_refs = $this->getOverseerProcessRefs(); | $process_refs = $this->getOverseerProcessRefs(); | ||||
if ($process_refs) { | if ($process_refs) { | ||||
$this->logWarn( | $this->logWarn( | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | $daemons = array( | ||||
array( | array( | ||||
'class' => 'PhabricatorTaskmasterDaemon', | 'class' => 'PhabricatorTaskmasterDaemon', | ||||
'label' => 'task', | 'label' => 'task', | ||||
'pool' => PhabricatorEnv::getEnvConfig('phd.taskmasters'), | 'pool' => PhabricatorEnv::getEnvConfig('phd.taskmasters'), | ||||
'reserve' => idx($options, 'reserve', 0), | 'reserve' => idx($options, 'reserve', 0), | ||||
), | ), | ||||
); | ); | ||||
$this->launchDaemons($daemons, $is_debug = false); | $this->launchDaemons( | ||||
$daemons, | |||||
$is_debug = false, | |||||
idx($options, 'foreground', false)); | |||||
$console->writeErr("%s\n", pht('Done.')); | $console->writeErr("%s\n", pht('Done.')); | ||||
return 0; | return 0; | ||||
} | } | ||||
final protected function executeStopCommand(array $options) { | final protected function executeStopCommand(array $options) { | ||||
$grace_period = idx($options, 'graceful', 15); | $grace_period = idx($options, 'graceful', 15); | ||||
$force = idx($options, 'force'); | $force = idx($options, 'force'); | ||||
▲ Show 20 Lines • Show All 270 Lines • Show Last 20 Lines |