Differential D11143 Diff 27109 src/applications/aphlict/management/PhabricatorAphlictManagementWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/aphlict/management/PhabricatorAphlictManagementWorkflow.php
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | foreach ($extension->getFunctions() as $function) { | ||||
if (!function_exists($function)) { | if (!function_exists($function)) { | ||||
echo "ERROR: The PHP function {$function}() is disabled. You must ". | echo "ERROR: The PHP function {$function}() is disabled. You must ". | ||||
"enable it to run aphlict on this machine.\n"; | "enable it to run aphlict on this machine.\n"; | ||||
exit(1); | exit(1); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
final protected function willLaunch() { | final protected function willLaunch($debug = false) { | ||||
$console = PhutilConsole::getConsole(); | $console = PhutilConsole::getConsole(); | ||||
$pid = $this->getPID(); | $pid = $this->getPID(); | ||||
if ($pid) { | if ($pid) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht( | pht( | ||||
'Unable to start notifications server because it is already '. | 'Unable to start notifications server because it is already '. | ||||
'running. Use `aphlict restart` to restart it.')); | 'running. Use `aphlict restart` to restart it.')); | ||||
} | } | ||||
if (posix_getuid() != 0) { | if (posix_getuid() == 0) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht( | pht( | ||||
'You must run this script as root; the Aphlict server needs to bind '. | // TODO: Update this message after a while. | ||||
'to privileged ports.')); | 'The notification server should not be run as root. It no '. | ||||
'longer requires access to privileged ports.')); | |||||
} | } | ||||
// This will throw if we can't find an appropriate `node`. | // Make sure we can write to the PID file. | ||||
$this->getNodeBinary(); | if (!$debug) { | ||||
Filesystem::writeFile($this->getPIDPath(), ''); | |||||
} | } | ||||
final protected function launch($debug = false) { | // First, start the server in configuration test mode with --test. This | ||||
$console = PhutilConsole::getConsole(); | // will let us error explicitly if there are missing modules, before we | ||||
// fork and lose access to the console. | |||||
$test_argv = $this->getServerArgv($debug); | |||||
$test_argv[] = '--test=true'; | |||||
if ($debug) { | execx( | ||||
$console->writeOut(pht("Starting Aphlict server in foreground...\n")); | '%s %s %Ls', | ||||
epriestley: Oh, unused -- I'll remove. | |||||
} else { | $this->getNodeBinary(), | ||||
Filesystem::writeFile($this->getPIDPath(), getmypid()); | $this->getAphlictScriptPath(), | ||||
$test_argv); | |||||
} | } | ||||
private function getServerArgv($debug) { | |||||
$ssl_key = PhabricatorEnv::getEnvConfig('notification.ssl-key'); | |||||
$ssl_cert = PhabricatorEnv::getEnvConfig('notification.ssl-cert'); | |||||
$server_uri = PhabricatorEnv::getEnvConfig('notification.server-uri'); | $server_uri = PhabricatorEnv::getEnvConfig('notification.server-uri'); | ||||
$server_uri = new PhutilURI($server_uri); | $server_uri = new PhutilURI($server_uri); | ||||
$client_uri = PhabricatorEnv::getEnvConfig('notification.client-uri'); | $client_uri = PhabricatorEnv::getEnvConfig('notification.client-uri'); | ||||
$client_uri = new PhutilURI($client_uri); | $client_uri = new PhutilURI($client_uri); | ||||
$user = PhabricatorEnv::getEnvConfig('notification.user'); | |||||
$log = PhabricatorEnv::getEnvConfig('notification.log'); | $log = PhabricatorEnv::getEnvConfig('notification.log'); | ||||
$server_argv = array(); | $server_argv = array(); | ||||
$server_argv[] = csprintf('--port=%s', $client_uri->getPort()); | $server_argv[] = '--port='.$client_uri->getPort(); | ||||
$server_argv[] = csprintf('--admin=%s', $server_uri->getPort()); | $server_argv[] = '--admin='.$server_uri->getPort(); | ||||
$server_argv[] = csprintf('--host=%s', $server_uri->getDomain()); | |||||
if ($ssl_key) { | |||||
$server_argv[] = '--ssl-key='.$ssl_key; | |||||
} | |||||
if ($user) { | if ($ssl_cert) { | ||||
$server_argv[] = csprintf('--user=%s', $user); | $server_argv[] = '--ssl-cert='.$ssl_cert; | ||||
} | } | ||||
if (!$debug) { | if (!$debug) { | ||||
$server_argv[] = csprintf('--log=%s', $log); | $server_argv[] = '--log='.$log; | ||||
} | |||||
return $server_argv; | |||||
} | |||||
private function getAphlictScriptPath() { | |||||
$root = dirname(phutil_get_library_root('phabricator')); | |||||
return $root.'/support/aphlict/server/aphlict_server.js'; | |||||
} | |||||
final protected function launch($debug = false) { | |||||
$console = PhutilConsole::getConsole(); | |||||
if ($debug) { | |||||
$console->writeOut(pht("Starting Aphlict server in foreground...\n")); | |||||
} else { | |||||
Filesystem::writeFile($this->getPIDPath(), getmypid()); | |||||
} | } | ||||
$command = csprintf( | $command = csprintf( | ||||
'%s %s %C', | '%s %s %Ls', | ||||
$this->getNodeBinary(), | $this->getNodeBinary(), | ||||
dirname(__FILE__).'/../../../../support/aphlict/server/aphlict_server.js', | $this->getAphlictScriptPath(), | ||||
implode(' ', $server_argv)); | $this->getServerArgv($debug)); | ||||
if (!$debug) { | if (!$debug) { | ||||
declare(ticks = 1); | declare(ticks = 1); | ||||
pcntl_signal(SIGINT, array($this, 'cleanup')); | pcntl_signal(SIGINT, array($this, 'cleanup')); | ||||
pcntl_signal(SIGTERM, array($this, 'cleanup')); | pcntl_signal(SIGTERM, array($this, 'cleanup')); | ||||
} | } | ||||
register_shutdown_function(array($this, 'cleanup')); | register_shutdown_function(array($this, 'cleanup')); | ||||
Show All 35 Lines | final protected function executeStartCommand() { | ||||
// When we fork, the child process will inherit its parent's set of open | // When we fork, the child process will inherit its parent's set of open | ||||
// file descriptors. If the parent process of bin/aphlict is waiting for | // file descriptors. If the parent process of bin/aphlict is waiting for | ||||
// bin/aphlict's file descriptors to close, it will be stuck waiting on | // bin/aphlict's file descriptors to close, it will be stuck waiting on | ||||
// the daemonized process. (This happens if e.g. bin/aphlict is started | // the daemonized process. (This happens if e.g. bin/aphlict is started | ||||
// in another script using passthru().) | // in another script using passthru().) | ||||
fclose(STDOUT); | fclose(STDOUT); | ||||
fclose(STDERR); | fclose(STDERR); | ||||
$this->launch(); | $this->launch(); | ||||
return 0; | return 0; | ||||
} | } | ||||
final protected function executeStopCommand() { | final protected function executeStopCommand() { | ||||
$console = PhutilConsole::getConsole(); | $console = PhutilConsole::getConsole(); | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |
Oh, unused -- I'll remove.