2014-06-05 21:13:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
abstract class PhabricatorAphlictManagementWorkflow
|
|
|
|
extends PhabricatorManagementWorkflow {
|
|
|
|
|
2015-01-08 23:59:33 +01:00
|
|
|
private $debug = false;
|
|
|
|
private $clientHost;
|
|
|
|
|
|
|
|
public function didConstruct() {
|
|
|
|
$this
|
|
|
|
->setArguments(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'name' => 'client-host',
|
|
|
|
'param' => 'hostname',
|
|
|
|
'help' => pht('Hostname to bind to for the client server.'),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(PhutilArgumentParser $args) {
|
|
|
|
$this->clientHost = $args->getArg('client-host');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-05 21:13:44 +02:00
|
|
|
final public function getPIDPath() {
|
|
|
|
return PhabricatorEnv::getEnvConfig('notification.pidfile');
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function getPID() {
|
|
|
|
$pid = null;
|
|
|
|
if (Filesystem::pathExists($this->getPIDPath())) {
|
|
|
|
$pid = (int)Filesystem::readFile($this->getPIDPath());
|
|
|
|
}
|
|
|
|
return $pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function cleanup($signo = '?') {
|
|
|
|
global $g_future;
|
|
|
|
if ($g_future) {
|
|
|
|
$g_future->resolveKill();
|
|
|
|
$g_future = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
Filesystem::remove($this->getPIDPath());
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2015-01-08 23:59:33 +01:00
|
|
|
protected final function setDebug($debug) {
|
|
|
|
$this->debug = $debug;
|
|
|
|
}
|
|
|
|
|
2014-06-05 21:13:44 +02:00
|
|
|
public static function requireExtensions() {
|
|
|
|
self::mustHaveExtension('pcntl');
|
|
|
|
self::mustHaveExtension('posix');
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function mustHaveExtension($ext) {
|
|
|
|
if (!extension_loaded($ext)) {
|
|
|
|
echo "ERROR: The PHP extension '{$ext}' is not installed. You must ".
|
|
|
|
"install it to run aphlict on this machine.\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
$extension = new ReflectionExtension($ext);
|
|
|
|
foreach ($extension->getFunctions() as $function) {
|
|
|
|
$function = $function->name;
|
|
|
|
if (!function_exists($function)) {
|
|
|
|
echo "ERROR: The PHP function {$function}() is disabled. You must ".
|
|
|
|
"enable it to run aphlict on this machine.\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-08 23:59:33 +01:00
|
|
|
final protected function willLaunch() {
|
2014-06-05 21:13:44 +02:00
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
|
|
|
|
$pid = $this->getPID();
|
|
|
|
if ($pid) {
|
2014-06-07 22:56:23 +02:00
|
|
|
throw new PhutilArgumentUsageException(
|
|
|
|
pht(
|
|
|
|
'Unable to start notifications server because it is already '.
|
|
|
|
'running. Use `aphlict restart` to restart it.'));
|
2014-06-05 21:13:44 +02:00
|
|
|
}
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
if (posix_getuid() == 0) {
|
2014-06-07 22:56:23 +02:00
|
|
|
throw new PhutilArgumentUsageException(
|
|
|
|
pht(
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
// TODO: Update this message after a while.
|
|
|
|
'The notification server should not be run as root. It no '.
|
|
|
|
'longer requires access to privileged ports.'));
|
2014-06-05 21:13:44 +02:00
|
|
|
}
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
// Make sure we can write to the PID file.
|
2015-01-08 23:59:33 +01:00
|
|
|
if (!$this->debug) {
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
Filesystem::writeFile($this->getPIDPath(), '');
|
|
|
|
}
|
2014-06-05 21:13:44 +02:00
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
// First, start the server in configuration test mode with --test. This
|
|
|
|
// will let us error explicitly if there are missing modules, before we
|
|
|
|
// fork and lose access to the console.
|
2015-01-08 23:59:33 +01:00
|
|
|
$test_argv = $this->getServerArgv();
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
$test_argv[] = '--test=true';
|
2014-06-05 21:13:44 +02:00
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
execx(
|
|
|
|
'%s %s %Ls',
|
|
|
|
$this->getNodeBinary(),
|
|
|
|
$this->getAphlictScriptPath(),
|
|
|
|
$test_argv);
|
|
|
|
}
|
|
|
|
|
2015-01-08 23:59:33 +01:00
|
|
|
private function getServerArgv() {
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
$ssl_key = PhabricatorEnv::getEnvConfig('notification.ssl-key');
|
|
|
|
$ssl_cert = PhabricatorEnv::getEnvConfig('notification.ssl-cert');
|
2014-06-05 21:13:44 +02:00
|
|
|
|
|
|
|
$server_uri = PhabricatorEnv::getEnvConfig('notification.server-uri');
|
|
|
|
$server_uri = new PhutilURI($server_uri);
|
|
|
|
|
|
|
|
$client_uri = PhabricatorEnv::getEnvConfig('notification.client-uri');
|
|
|
|
$client_uri = new PhutilURI($client_uri);
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
$log = PhabricatorEnv::getEnvConfig('notification.log');
|
2014-06-05 21:13:44 +02:00
|
|
|
|
|
|
|
$server_argv = array();
|
2015-01-08 23:59:33 +01:00
|
|
|
$server_argv[] = '--client-port='.$client_uri->getPort();
|
|
|
|
$server_argv[] = '--admin-port='.$server_uri->getPort();
|
|
|
|
$server_argv[] = '--admin-host='.$server_uri->getDomain();
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
|
|
|
|
if ($ssl_key) {
|
|
|
|
$server_argv[] = '--ssl-key='.$ssl_key;
|
|
|
|
}
|
2014-06-05 21:13:44 +02:00
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
if ($ssl_cert) {
|
|
|
|
$server_argv[] = '--ssl-cert='.$ssl_cert;
|
2014-06-05 21:13:44 +02:00
|
|
|
}
|
|
|
|
|
2015-01-08 23:59:33 +01:00
|
|
|
if (!$this->debug) {
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
$server_argv[] = '--log='.$log;
|
|
|
|
}
|
|
|
|
|
2015-01-08 23:59:33 +01:00
|
|
|
if ($this->clientHost) {
|
|
|
|
$server_argv[] = '--client-host='.$this->clientHost;
|
|
|
|
}
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
return $server_argv;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getAphlictScriptPath() {
|
|
|
|
$root = dirname(phutil_get_library_root('phabricator'));
|
|
|
|
return $root.'/support/aphlict/server/aphlict_server.js';
|
|
|
|
}
|
|
|
|
|
2015-01-08 23:59:33 +01:00
|
|
|
final protected function launch() {
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
|
2015-01-08 23:59:33 +01:00
|
|
|
if ($this->debug) {
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
$console->writeOut(pht("Starting Aphlict server in foreground...\n"));
|
|
|
|
} else {
|
|
|
|
Filesystem::writeFile($this->getPIDPath(), getmypid());
|
2014-06-05 21:13:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$command = csprintf(
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
'%s %s %Ls',
|
2014-06-07 22:56:23 +02:00
|
|
|
$this->getNodeBinary(),
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
$this->getAphlictScriptPath(),
|
2015-01-08 23:59:33 +01:00
|
|
|
$this->getServerArgv());
|
2014-06-05 21:13:44 +02:00
|
|
|
|
2015-01-08 23:59:33 +01:00
|
|
|
if (!$this->debug) {
|
2014-06-05 21:13:44 +02:00
|
|
|
declare(ticks = 1);
|
|
|
|
pcntl_signal(SIGINT, array($this, 'cleanup'));
|
|
|
|
pcntl_signal(SIGTERM, array($this, 'cleanup'));
|
|
|
|
}
|
|
|
|
register_shutdown_function(array($this, 'cleanup'));
|
|
|
|
|
2015-01-08 23:59:33 +01:00
|
|
|
if ($this->debug) {
|
2014-06-05 21:13:44 +02:00
|
|
|
$console->writeOut("Launching server:\n\n $ ".$command."\n\n");
|
|
|
|
|
|
|
|
$err = phutil_passthru('%C', $command);
|
|
|
|
$console->writeOut(">>> Server exited!\n");
|
|
|
|
exit($err);
|
|
|
|
} else {
|
|
|
|
while (true) {
|
|
|
|
global $g_future;
|
|
|
|
$g_future = new ExecFuture('exec %C', $command);
|
|
|
|
$g_future->resolve();
|
|
|
|
|
|
|
|
// If the server exited, wait a couple of seconds and restart it.
|
|
|
|
unset($g_future);
|
|
|
|
sleep(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -( Commands )----------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
final protected function executeStartCommand() {
|
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
$this->willLaunch();
|
|
|
|
|
|
|
|
$pid = pcntl_fork();
|
|
|
|
if ($pid < 0) {
|
|
|
|
throw new Exception('Failed to fork()!');
|
|
|
|
} else if ($pid) {
|
|
|
|
$console->writeErr(pht("Aphlict Server started.\n"));
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// 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
|
|
|
|
// in another script using passthru().)
|
|
|
|
fclose(STDOUT);
|
|
|
|
fclose(STDERR);
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
|
2014-06-05 21:13:44 +02:00
|
|
|
$this->launch();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
final protected function executeStopCommand() {
|
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
|
|
|
|
$pid = $this->getPID();
|
|
|
|
if (!$pid) {
|
|
|
|
$console->writeErr(pht("Aphlict is not running.\n"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$console->writeErr(pht("Stopping Aphlict Server (%s)...\n", $pid));
|
|
|
|
posix_kill($pid, SIGINT);
|
|
|
|
|
|
|
|
$start = time();
|
|
|
|
do {
|
|
|
|
if (!PhabricatorDaemonReference::isProcessRunning($pid)) {
|
|
|
|
$console->writeOut(
|
|
|
|
"%s\n",
|
|
|
|
pht('Aphlict Server (%s) exited normally.', $pid));
|
|
|
|
$pid = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
usleep(100000);
|
|
|
|
} while (time() < $start + 5);
|
|
|
|
|
|
|
|
if ($pid) {
|
|
|
|
$console->writeErr(pht('Sending %s a SIGKILL.', $pid)."\n");
|
|
|
|
posix_kill($pid, SIGKILL);
|
|
|
|
unset($pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
Filesystem::remove($this->getPIDPath());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-07 22:56:23 +02:00
|
|
|
private function getNodeBinary() {
|
|
|
|
if (Filesystem::binaryExists('nodejs')) {
|
|
|
|
return 'nodejs';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Filesystem::binaryExists('node')) {
|
|
|
|
return 'node';
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new PhutilArgumentUsageException(
|
|
|
|
pht(
|
|
|
|
'No `nodejs` or `node` binary was found in $PATH. You must install '.
|
|
|
|
'Node.js to start the Aphlict server.'));
|
|
|
|
}
|
|
|
|
|
2014-06-05 21:13:44 +02:00
|
|
|
}
|