diff --git a/conf/aphlict/aphlict.default.json b/conf/aphlict/aphlict.default.json index 306e32014f..1f1bafc3ea 100644 --- a/conf/aphlict/aphlict.default.json +++ b/conf/aphlict/aphlict.default.json @@ -14,5 +14,11 @@ "ssl.key": null, "ssl.cert": null } - ] + ], + "logs": [ + { + "path": "/var/log/aphlict.log" + } + ], + "pidfile": "/var/tmp/aphlict/pid/aphlict.pid" } diff --git a/src/applications/aphlict/management/PhabricatorAphlictManagementWorkflow.php b/src/applications/aphlict/management/PhabricatorAphlictManagementWorkflow.php index 6f6014dafb..60d34b89eb 100644 --- a/src/applications/aphlict/management/PhabricatorAphlictManagementWorkflow.php +++ b/src/applications/aphlict/management/PhabricatorAphlictManagementWorkflow.php @@ -4,6 +4,7 @@ abstract class PhabricatorAphlictManagementWorkflow extends PhabricatorManagementWorkflow { private $debug = false; + private $configData; private $configPath; final protected function setDebug($debug) { @@ -74,6 +75,8 @@ abstract class PhabricatorAphlictManagementWorkflow $data, array( 'servers' => 'list', + 'logs' => 'optional list', + 'pidfile' => 'string', )); } catch (Exception $ex) { throw new PhutilArgumentUsageException( @@ -174,43 +177,54 @@ abstract class PhabricatorAphlictManagementWorkflow 'admin')); } + $logs = $data['logs']; + foreach ($logs as $index => $log) { + PhutilTypeSpec::checkMap( + $log, + array( + 'path' => 'string', + )); + + $path = $log['path']; + + try { + $dir = dirname($path); + if (!Filesystem::pathExists($dir)) { + Filesystem::createDirectory($dir, 0755, true); + } + } catch (FilesystemException $ex) { + throw new PhutilArgumentUsageException( + pht( + 'Failed to create directory "%s" for specified log file (with '. + 'index "%s"). You should manually create this directory or '. + 'choose a different logfile location. %s', + $dir, + $ex->getMessage())); + } + } + + $this->configData = $data; $this->configPath = $full_path; + + $pid_path = $this->getPIDPath(); + try { + $dir = dirname($path); + if (!Filesystem::pathExists($dir)) { + Filesystem::createDirectory($dir, 0755, true); + } + } catch (FilesystemException $ex) { + throw new PhutilArgumentUsageException( + pht( + 'Failed to create directory "%s" for specified PID file. You '. + 'should manually create this directory or choose a different '. + 'PID file location. %s', + $dir, + $ex->getMessage())); + } } final public function getPIDPath() { - $path = PhabricatorEnv::getEnvConfig('notification.pidfile'); - - try { - $dir = dirname($path); - if (!Filesystem::pathExists($dir)) { - Filesystem::createDirectory($dir, 0755, true); - } - } catch (FilesystemException $ex) { - throw new Exception( - pht( - "Failed to create '%s'. You should manually create this directory.", - $dir)); - } - - return $path; - } - - final public function getLogPath() { - $path = PhabricatorEnv::getEnvConfig('notification.log'); - - try { - $dir = dirname($path); - if (!Filesystem::pathExists($dir)) { - Filesystem::createDirectory($dir, 0755, true); - } - } catch (FilesystemException $ex) { - throw new Exception( - pht( - "Failed to create '%s'. You should manually create this directory.", - $dir)); - } - - return $path; + return $this->configData['pidfile']; } final public function getPID() { @@ -293,12 +307,8 @@ abstract class PhabricatorAphlictManagementWorkflow } private function getServerArgv() { - $log = $this->getLogPath(); - $server_argv = array(); $server_argv[] = '--config='.$this->configPath; - $server_argv[] = '--log='.$log; - return $server_argv; } diff --git a/src/applications/config/check/PhabricatorExtraConfigSetupCheck.php b/src/applications/config/check/PhabricatorExtraConfigSetupCheck.php index 9afc23a454..e054918c1d 100644 --- a/src/applications/config/check/PhabricatorExtraConfigSetupCheck.php +++ b/src/applications/config/check/PhabricatorExtraConfigSetupCheck.php @@ -305,6 +305,8 @@ final class PhabricatorExtraConfigSetupCheck extends PhabricatorSetupCheck { 'notification.ssl-cert' => $aphlict_reason, 'notification.ssl-key' => $aphlict_reason, + 'notification.pidfile' => $aphlict_reason, + 'notification.log' => $aphlict_reason, ); return $ancient_config; diff --git a/src/applications/config/option/PhabricatorNotificationConfigOptions.php b/src/applications/config/option/PhabricatorNotificationConfigOptions.php index 4f9bfc2869..5855aafb60 100644 --- a/src/applications/config/option/PhabricatorNotificationConfigOptions.php +++ b/src/applications/config/option/PhabricatorNotificationConfigOptions.php @@ -44,13 +44,6 @@ final class PhabricatorNotificationConfigOptions 'string', 'http://localhost:22281/') ->setDescription(pht('Location of the notification receiver server.')), - $this->newOption('notification.log', 'string', '/var/log/aphlict.log') - ->setDescription(pht('Location of the server log file.')), - $this->newOption( - 'notification.pidfile', - 'string', - '/var/tmp/aphlict/pid/aphlict.pid') - ->setDescription(pht('Location of the server PID file.')), ); } diff --git a/src/docs/user/configuration/notifications.diviner b/src/docs/user/configuration/notifications.diviner index 20e7afd3b5..0b828f7072 100644 --- a/src/docs/user/configuration/notifications.diviner +++ b/src/docs/user/configuration/notifications.diviner @@ -75,7 +75,9 @@ it exists) or specify a configuration file explicitly with the `--config` flag: The configuration file has these settings: - - `servers`: A list of servers to start. + - `servers`: //Required list.// A list of servers to start. + - `logs`: //Optional list.// A list of logs to write to. + - `pidfile`: //Required string.// Path to a PID file. Each server in the `servers` list should be an object with these keys: @@ -91,6 +93,10 @@ Each server in the `servers` list should be an object with these keys: - `ssl.cert`: //Optional string.// If you want to use SSL on this port, the path to an SSL certificate. +Each log in the `logs` list should be an object with these keys: + + - `path`: //Required string.// Path to the log file. + The defaults are appropriate for simple cases, but you may need to adjust them if you are running a more complex configuration. @@ -104,9 +110,6 @@ You may also want to adjust these settings: connect to in order to listen for notifications. - `notification.server-uri` Internally-facing host and port that Phabricator will connect to in order to publish notifications. - - `notification.log` Log file location for the server. - - `notification.pidfile` Pidfile location used to stop any running server when - aphlict is restarted. Verifying Server Status diff --git a/support/aphlict/server/aphlict_server.js b/support/aphlict/server/aphlict_server.js index 4037f4f3d6..7244ee7593 100644 --- a/support/aphlict/server/aphlict_server.js +++ b/support/aphlict/server/aphlict_server.js @@ -8,7 +8,6 @@ var fs = require('fs'); function parse_command_line_arguments(argv) { var args = { - log: '/var/log/aphlict.log', test: false, config: null }; @@ -49,9 +48,9 @@ function set_exit_code(code) { process.on('uncaughtException', function(err) { var context = null; - if (err.code == 'EACCES' && err.path == args.log) { + if (err.code == 'EACCES') { context = util.format( - 'Unable to open logfile ("%s"). Check that permissions are set ' + + 'Unable to open file ("%s"). Check that permissions are set ' + 'correctly.', err.path); } @@ -68,11 +67,6 @@ process.on('uncaughtException', function(err) { set_exit_code(1); }); -// Add the logfile so we'll fail if we can't write to it. -if (args.log) { - debug.addLog(args.log); -} - try { require('ws'); } catch (ex) { @@ -89,6 +83,12 @@ require('./lib/AphlictAdminServer'); require('./lib/AphlictClientServer'); var ii; + +var logs = config.logs || []; +for (ii = 0; ii < logs.length; ii++) { + debug.addLog(logs[ii].path); +} + var servers = []; for (ii = 0; ii < config.servers.length; ii++) { var spec = config.servers[ii]; @@ -116,6 +116,10 @@ if (args.test) { debug.log('Starting servers (service PID %d).', process.pid); +for (ii = 0; ii < logs.length; ii++) { + debug.log('Logging to "%s".', logs[ii].path); +} + var aphlict_servers = []; var aphlict_clients = []; var aphlict_admins = [];