Differential D11143 Diff 27104 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`. | // First, start the server in configuration test mode with --test. This | ||||
| $this->getNodeBinary(); | // will let us error explicitly if there are missing modules, before we | ||||
| } | // fork and lose access to the console. | ||||
| $test_argv = $this->getServerArgv($debug); | |||||
| final protected function launch($debug = false) { | $test_argv[] = '--test=true'; | ||||
| $console = PhutilConsole::getConsole(); | |||||
| if ($debug) { | execx( | ||||
| $console->writeOut(pht("Starting Aphlict server in foreground...\n")); | '%s %s %Ls', | ||||
| } else { | $this->getNodeBinary(), | ||||
| Filesystem::writeFile($this->getPIDPath(), getmypid()); | $this->getAphlictScriptPath(), | ||||
| $test_argv); | |||||
| } | } | ||||
| private function getServerArgv($debug) { | |||||
| $ssl_key = PhabricatorEnv::getEnvConfig('notification.ssl-key'); | |||||
epriestley: Oh, unused -- I'll remove. | |||||
| $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 ($user) { | if ($ssl_key) { | ||||
| $server_argv[] = csprintf('--user=%s', $user); | $server_argv[] = '--ssl-key='.$ssl_key; | ||||
| } | |||||
| if ($ssl_cert) { | |||||
| $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 20 Lines • Show All 98 Lines • Show Last 20 Lines | |||||
Oh, unused -- I'll remove.