@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move Aphlict logging and PID configuration options to config file

Summary: Ref T10697. Mostly straightforward. Also allow the server to have multiple logs and log options in the future (e.g., different verbosities or separate admin/client logs or whatever). No specific plans for this, but the default log is pretty noisy today.

Test Plan: Set up a couple of logs, started server, saw it log to them.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10697

Differential Revision: https://secure.phabricator.com/D15702

+64 -46
+7 -1
conf/aphlict/aphlict.default.json
··· 14 14 "ssl.key": null, 15 15 "ssl.cert": null 16 16 } 17 - ] 17 + ], 18 + "logs": [ 19 + { 20 + "path": "/var/log/aphlict.log" 21 + } 22 + ], 23 + "pidfile": "/var/tmp/aphlict/pid/aphlict.pid" 18 24 }
+36 -26
src/applications/aphlict/management/PhabricatorAphlictManagementWorkflow.php
··· 4 4 extends PhabricatorManagementWorkflow { 5 5 6 6 private $debug = false; 7 + private $configData; 7 8 private $configPath; 8 9 9 10 final protected function setDebug($debug) { ··· 74 75 $data, 75 76 array( 76 77 'servers' => 'list<wild>', 78 + 'logs' => 'optional list<wild>', 79 + 'pidfile' => 'string', 77 80 )); 78 81 } catch (Exception $ex) { 79 82 throw new PhutilArgumentUsageException( ··· 174 177 'admin')); 175 178 } 176 179 177 - $this->configPath = $full_path; 178 - } 180 + $logs = $data['logs']; 181 + foreach ($logs as $index => $log) { 182 + PhutilTypeSpec::checkMap( 183 + $log, 184 + array( 185 + 'path' => 'string', 186 + )); 179 187 180 - final public function getPIDPath() { 181 - $path = PhabricatorEnv::getEnvConfig('notification.pidfile'); 188 + $path = $log['path']; 182 189 183 - try { 184 - $dir = dirname($path); 185 - if (!Filesystem::pathExists($dir)) { 186 - Filesystem::createDirectory($dir, 0755, true); 190 + try { 191 + $dir = dirname($path); 192 + if (!Filesystem::pathExists($dir)) { 193 + Filesystem::createDirectory($dir, 0755, true); 194 + } 195 + } catch (FilesystemException $ex) { 196 + throw new PhutilArgumentUsageException( 197 + pht( 198 + 'Failed to create directory "%s" for specified log file (with '. 199 + 'index "%s"). You should manually create this directory or '. 200 + 'choose a different logfile location. %s', 201 + $dir, 202 + $ex->getMessage())); 187 203 } 188 - } catch (FilesystemException $ex) { 189 - throw new Exception( 190 - pht( 191 - "Failed to create '%s'. You should manually create this directory.", 192 - $dir)); 193 204 } 194 205 195 - return $path; 196 - } 206 + $this->configData = $data; 207 + $this->configPath = $full_path; 197 208 198 - final public function getLogPath() { 199 - $path = PhabricatorEnv::getEnvConfig('notification.log'); 200 - 209 + $pid_path = $this->getPIDPath(); 201 210 try { 202 211 $dir = dirname($path); 203 212 if (!Filesystem::pathExists($dir)) { 204 213 Filesystem::createDirectory($dir, 0755, true); 205 214 } 206 215 } catch (FilesystemException $ex) { 207 - throw new Exception( 216 + throw new PhutilArgumentUsageException( 208 217 pht( 209 - "Failed to create '%s'. You should manually create this directory.", 210 - $dir)); 218 + 'Failed to create directory "%s" for specified PID file. You '. 219 + 'should manually create this directory or choose a different '. 220 + 'PID file location. %s', 221 + $dir, 222 + $ex->getMessage())); 211 223 } 224 + } 212 225 213 - return $path; 226 + final public function getPIDPath() { 227 + return $this->configData['pidfile']; 214 228 } 215 229 216 230 final public function getPID() { ··· 293 307 } 294 308 295 309 private function getServerArgv() { 296 - $log = $this->getLogPath(); 297 - 298 310 $server_argv = array(); 299 311 $server_argv[] = '--config='.$this->configPath; 300 - $server_argv[] = '--log='.$log; 301 - 302 312 return $server_argv; 303 313 } 304 314
+2
src/applications/config/check/PhabricatorExtraConfigSetupCheck.php
··· 305 305 306 306 'notification.ssl-cert' => $aphlict_reason, 307 307 'notification.ssl-key' => $aphlict_reason, 308 + 'notification.pidfile' => $aphlict_reason, 309 + 'notification.log' => $aphlict_reason, 308 310 ); 309 311 310 312 return $ancient_config;
-7
src/applications/config/option/PhabricatorNotificationConfigOptions.php
··· 44 44 'string', 45 45 'http://localhost:22281/') 46 46 ->setDescription(pht('Location of the notification receiver server.')), 47 - $this->newOption('notification.log', 'string', '/var/log/aphlict.log') 48 - ->setDescription(pht('Location of the server log file.')), 49 - $this->newOption( 50 - 'notification.pidfile', 51 - 'string', 52 - '/var/tmp/aphlict/pid/aphlict.pid') 53 - ->setDescription(pht('Location of the server PID file.')), 54 47 ); 55 48 } 56 49
+7 -4
src/docs/user/configuration/notifications.diviner
··· 75 75 76 76 The configuration file has these settings: 77 77 78 - - `servers`: A list of servers to start. 78 + - `servers`: //Required list.// A list of servers to start. 79 + - `logs`: //Optional list.// A list of logs to write to. 80 + - `pidfile`: //Required string.// Path to a PID file. 79 81 80 82 Each server in the `servers` list should be an object with these keys: 81 83 ··· 91 93 - `ssl.cert`: //Optional string.// If you want to use SSL on this port, 92 94 the path to an SSL certificate. 93 95 96 + Each log in the `logs` list should be an object with these keys: 97 + 98 + - `path`: //Required string.// Path to the log file. 99 + 94 100 The defaults are appropriate for simple cases, but you may need to adjust them 95 101 if you are running a more complex configuration. 96 102 ··· 104 110 connect to in order to listen for notifications. 105 111 - `notification.server-uri` Internally-facing host and port that Phabricator 106 112 will connect to in order to publish notifications. 107 - - `notification.log` Log file location for the server. 108 - - `notification.pidfile` Pidfile location used to stop any running server when 109 - aphlict is restarted. 110 113 111 114 112 115 Verifying Server Status
+12 -8
support/aphlict/server/aphlict_server.js
··· 8 8 9 9 function parse_command_line_arguments(argv) { 10 10 var args = { 11 - log: '/var/log/aphlict.log', 12 11 test: false, 13 12 config: null 14 13 }; ··· 49 48 50 49 process.on('uncaughtException', function(err) { 51 50 var context = null; 52 - if (err.code == 'EACCES' && err.path == args.log) { 51 + if (err.code == 'EACCES') { 53 52 context = util.format( 54 - 'Unable to open logfile ("%s"). Check that permissions are set ' + 53 + 'Unable to open file ("%s"). Check that permissions are set ' + 55 54 'correctly.', 56 55 err.path); 57 56 } ··· 67 66 debug.log(message.join('\n\n')); 68 67 set_exit_code(1); 69 68 }); 70 - 71 - // Add the logfile so we'll fail if we can't write to it. 72 - if (args.log) { 73 - debug.addLog(args.log); 74 - } 75 69 76 70 try { 77 71 require('ws'); ··· 89 83 require('./lib/AphlictClientServer'); 90 84 91 85 var ii; 86 + 87 + var logs = config.logs || []; 88 + for (ii = 0; ii < logs.length; ii++) { 89 + debug.addLog(logs[ii].path); 90 + } 91 + 92 92 var servers = []; 93 93 for (ii = 0; ii < config.servers.length; ii++) { 94 94 var spec = config.servers[ii]; ··· 115 115 } 116 116 117 117 debug.log('Starting servers (service PID %d).', process.pid); 118 + 119 + for (ii = 0; ii < logs.length; ii++) { 120 + debug.log('Logging to "%s".', logs[ii].path); 121 + } 118 122 119 123 var aphlict_servers = []; 120 124 var aphlict_clients = [];