Skip to content

Commit c6b0925

Browse files
author
epriestley
committedApr 14, 2016
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
1 parent c84dee5 commit c6b0925

File tree

6 files changed

+64
-46
lines changed

6 files changed

+64
-46
lines changed
 

‎conf/aphlict/aphlict.default.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,11 @@
1414
"ssl.key": null,
1515
"ssl.cert": null
1616
}
17-
]
17+
],
18+
"logs": [
19+
{
20+
"path": "/var/log/aphlict.log"
21+
}
22+
],
23+
"pidfile": "/var/tmp/aphlict/pid/aphlict.pid"
1824
}

‎src/applications/aphlict/management/PhabricatorAphlictManagementWorkflow.php

+36-26
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ abstract class PhabricatorAphlictManagementWorkflow
44
extends PhabricatorManagementWorkflow {
55

66
private $debug = false;
7+
private $configData;
78
private $configPath;
89

910
final protected function setDebug($debug) {
@@ -74,6 +75,8 @@ protected function parseLaunchArguments(PhutilArgumentParser $args) {
7475
$data,
7576
array(
7677
'servers' => 'list<wild>',
78+
'logs' => 'optional list<wild>',
79+
'pidfile' => 'string',
7780
));
7881
} catch (Exception $ex) {
7982
throw new PhutilArgumentUsageException(
@@ -174,43 +177,54 @@ protected function parseLaunchArguments(PhutilArgumentParser $args) {
174177
'admin'));
175178
}
176179

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+
));
179187

180-
final public function getPIDPath() {
181-
$path = PhabricatorEnv::getEnvConfig('notification.pidfile');
188+
$path = $log['path'];
182189

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()));
187203
}
188-
} catch (FilesystemException $ex) {
189-
throw new Exception(
190-
pht(
191-
"Failed to create '%s'. You should manually create this directory.",
192-
$dir));
193204
}
194205

195-
return $path;
196-
}
197-
198-
final public function getLogPath() {
199-
$path = PhabricatorEnv::getEnvConfig('notification.log');
206+
$this->configData = $data;
207+
$this->configPath = $full_path;
200208

209+
$pid_path = $this->getPIDPath();
201210
try {
202211
$dir = dirname($path);
203212
if (!Filesystem::pathExists($dir)) {
204213
Filesystem::createDirectory($dir, 0755, true);
205214
}
206215
} catch (FilesystemException $ex) {
207-
throw new Exception(
216+
throw new PhutilArgumentUsageException(
208217
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()));
211223
}
224+
}
212225

213-
return $path;
226+
final public function getPIDPath() {
227+
return $this->configData['pidfile'];
214228
}
215229

216230
final public function getPID() {
@@ -293,12 +307,8 @@ final protected function willLaunch() {
293307
}
294308

295309
private function getServerArgv() {
296-
$log = $this->getLogPath();
297-
298310
$server_argv = array();
299311
$server_argv[] = '--config='.$this->configPath;
300-
$server_argv[] = '--log='.$log;
301-
302312
return $server_argv;
303313
}
304314

‎src/applications/config/check/PhabricatorExtraConfigSetupCheck.php

+2
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ public static function getAncientConfig() {
305305

306306
'notification.ssl-cert' => $aphlict_reason,
307307
'notification.ssl-key' => $aphlict_reason,
308+
'notification.pidfile' => $aphlict_reason,
309+
'notification.log' => $aphlict_reason,
308310
);
309311

310312
return $ancient_config;

‎src/applications/config/option/PhabricatorNotificationConfigOptions.php

-7
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ public function getOptions() {
4444
'string',
4545
'http://localhost:22281/')
4646
->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.')),
5447
);
5548
}
5649

‎src/docs/user/configuration/notifications.diviner

+7-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ it exists) or specify a configuration file explicitly with the `--config` flag:
7575

7676
The configuration file has these settings:
7777

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.
7981

8082
Each server in the `servers` list should be an object with these keys:
8183

@@ -91,6 +93,10 @@ Each server in the `servers` list should be an object with these keys:
9193
- `ssl.cert`: //Optional string.// If you want to use SSL on this port,
9294
the path to an SSL certificate.
9395

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+
94100
The defaults are appropriate for simple cases, but you may need to adjust them
95101
if you are running a more complex configuration.
96102

@@ -104,9 +110,6 @@ You may also want to adjust these settings:
104110
connect to in order to listen for notifications.
105111
- `notification.server-uri` Internally-facing host and port that Phabricator
106112
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.
110113

111114

112115
Verifying Server Status

‎support/aphlict/server/aphlict_server.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ var fs = require('fs');
88

99
function parse_command_line_arguments(argv) {
1010
var args = {
11-
log: '/var/log/aphlict.log',
1211
test: false,
1312
config: null
1413
};
@@ -49,9 +48,9 @@ function set_exit_code(code) {
4948

5049
process.on('uncaughtException', function(err) {
5150
var context = null;
52-
if (err.code == 'EACCES' && err.path == args.log) {
51+
if (err.code == 'EACCES') {
5352
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 ' +
5554
'correctly.',
5655
err.path);
5756
}
@@ -68,11 +67,6 @@ process.on('uncaughtException', function(err) {
6867
set_exit_code(1);
6968
});
7069

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-
7670
try {
7771
require('ws');
7872
} catch (ex) {
@@ -89,6 +83,12 @@ require('./lib/AphlictAdminServer');
8983
require('./lib/AphlictClientServer');
9084

9185
var ii;
86+
87+
var logs = config.logs || [];
88+
for (ii = 0; ii < logs.length; ii++) {
89+
debug.addLog(logs[ii].path);
90+
}
91+
9292
var servers = [];
9393
for (ii = 0; ii < config.servers.length; ii++) {
9494
var spec = config.servers[ii];
@@ -116,6 +116,10 @@ if (args.test) {
116116

117117
debug.log('Starting servers (service PID %d).', process.pid);
118118

119+
for (ii = 0; ii < logs.length; ii++) {
120+
debug.log('Logging to "%s".', logs[ii].path);
121+
}
122+
119123
var aphlict_servers = [];
120124
var aphlict_clients = [];
121125
var aphlict_admins = [];

0 commit comments

Comments
 (0)
Failed to load comments.