Differential D15702 Diff 37845 src/applications/aphlict/management/PhabricatorAphlictManagementWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/aphlict/management/PhabricatorAphlictManagementWorkflow.php
<?php | <?php | ||||
abstract class PhabricatorAphlictManagementWorkflow | abstract class PhabricatorAphlictManagementWorkflow | ||||
extends PhabricatorManagementWorkflow { | extends PhabricatorManagementWorkflow { | ||||
private $debug = false; | private $debug = false; | ||||
private $configData; | |||||
private $configPath; | private $configPath; | ||||
final protected function setDebug($debug) { | final protected function setDebug($debug) { | ||||
$this->debug = $debug; | $this->debug = $debug; | ||||
return $this; | return $this; | ||||
} | } | ||||
protected function getLaunchArguments() { | protected function getLaunchArguments() { | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | try { | ||||
$ex->getMessage())); | $ex->getMessage())); | ||||
} | } | ||||
try { | try { | ||||
PhutilTypeSpec::checkMap( | PhutilTypeSpec::checkMap( | ||||
$data, | $data, | ||||
array( | array( | ||||
'servers' => 'list<wild>', | 'servers' => 'list<wild>', | ||||
'logs' => 'optional list<wild>', | |||||
'pidfile' => 'string', | |||||
)); | )); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht( | pht( | ||||
'Configuration file has improper configuration keys at top '. | 'Configuration file has improper configuration keys at top '. | ||||
'level. %s', | 'level. %s', | ||||
$ex->getMessage())); | $ex->getMessage())); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | if (!$has_admin) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht( | pht( | ||||
'Configuration file does not specify any administrative '. | 'Configuration file does not specify any administrative '. | ||||
'servers. This service will be unable to receive messages. '. | 'servers. This service will be unable to receive messages. '. | ||||
'You must specify at least one server with type "%s".', | 'You must specify at least one server with type "%s".', | ||||
'admin')); | 'admin')); | ||||
} | } | ||||
$this->configPath = $full_path; | $logs = $data['logs']; | ||||
} | foreach ($logs as $index => $log) { | ||||
PhutilTypeSpec::checkMap( | |||||
$log, | |||||
array( | |||||
'path' => 'string', | |||||
)); | |||||
final public function getPIDPath() { | $path = $log['path']; | ||||
$path = PhabricatorEnv::getEnvConfig('notification.pidfile'); | |||||
try { | try { | ||||
$dir = dirname($path); | $dir = dirname($path); | ||||
if (!Filesystem::pathExists($dir)) { | if (!Filesystem::pathExists($dir)) { | ||||
Filesystem::createDirectory($dir, 0755, true); | Filesystem::createDirectory($dir, 0755, true); | ||||
} | } | ||||
} catch (FilesystemException $ex) { | } catch (FilesystemException $ex) { | ||||
throw new Exception( | throw new PhutilArgumentUsageException( | ||||
pht( | pht( | ||||
"Failed to create '%s'. You should manually create this directory.", | 'Failed to create directory "%s" for specified log file (with '. | ||||
$dir)); | 'index "%s"). You should manually create this directory or '. | ||||
'choose a different logfile location. %s', | |||||
$dir, | |||||
$ex->getMessage())); | |||||
} | } | ||||
return $path; | |||||
} | } | ||||
final public function getLogPath() { | $this->configData = $data; | ||||
$path = PhabricatorEnv::getEnvConfig('notification.log'); | $this->configPath = $full_path; | ||||
$pid_path = $this->getPIDPath(); | |||||
try { | try { | ||||
$dir = dirname($path); | $dir = dirname($path); | ||||
if (!Filesystem::pathExists($dir)) { | if (!Filesystem::pathExists($dir)) { | ||||
Filesystem::createDirectory($dir, 0755, true); | Filesystem::createDirectory($dir, 0755, true); | ||||
} | } | ||||
} catch (FilesystemException $ex) { | } catch (FilesystemException $ex) { | ||||
throw new Exception( | throw new PhutilArgumentUsageException( | ||||
pht( | pht( | ||||
"Failed to create '%s'. You should manually create this directory.", | 'Failed to create directory "%s" for specified PID file. You '. | ||||
$dir)); | 'should manually create this directory or choose a different '. | ||||
'PID file location. %s', | |||||
$dir, | |||||
$ex->getMessage())); | |||||
} | |||||
} | } | ||||
return $path; | final public function getPIDPath() { | ||||
return $this->configData['pidfile']; | |||||
} | } | ||||
final public function getPID() { | final public function getPID() { | ||||
$pid = null; | $pid = null; | ||||
if (Filesystem::pathExists($this->getPIDPath())) { | if (Filesystem::pathExists($this->getPIDPath())) { | ||||
$pid = (int)Filesystem::readFile($this->getPIDPath()); | $pid = (int)Filesystem::readFile($this->getPIDPath()); | ||||
} | } | ||||
return $pid; | return $pid; | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | final protected function willLaunch() { | ||||
$test_argv = $this->getServerArgv(); | $test_argv = $this->getServerArgv(); | ||||
$test_argv[] = '--test=true'; | $test_argv[] = '--test=true'; | ||||
execx('%C', $this->getStartCommand($test_argv)); | execx('%C', $this->getStartCommand($test_argv)); | ||||
} | } | ||||
private function getServerArgv() { | private function getServerArgv() { | ||||
$log = $this->getLogPath(); | |||||
$server_argv = array(); | $server_argv = array(); | ||||
$server_argv[] = '--config='.$this->configPath; | $server_argv[] = '--config='.$this->configPath; | ||||
$server_argv[] = '--log='.$log; | |||||
return $server_argv; | return $server_argv; | ||||
} | } | ||||
final protected function launch() { | final protected function launch() { | ||||
$console = PhutilConsole::getConsole(); | $console = PhutilConsole::getConsole(); | ||||
if ($this->debug) { | if ($this->debug) { | ||||
$console->writeOut( | $console->writeOut( | ||||
▲ Show 20 Lines • Show All 135 Lines • Show Last 20 Lines |