Skip to content

Commit 99e9a26

Browse files
author
Marcel Beck
committed
Separates the PID and log directories of daemons
Summary: The Log and PID directory should be separable in the config file Test Plan: Start the daemons, and check if the pid and log files are stored in directories that were specified in the config file. Reviewers: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3149
1 parent 7ea925d commit 99e9a26

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

conf/default.conf.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,10 @@
10951095

10961096
// Directory that phd (the Phabricator daemon control script) should use to
10971097
// track running daemons.
1098-
'phd.pid-directory' => '/var/tmp/phd',
1098+
'phd.pid-directory' => '/var/tmp/phd/pid',
1099+
1100+
// Directory that the Phabricator daemons should use to store the log file
1101+
'phd.log-directory' => '/var/tmp/phd/log',
10991102

11001103
// Number of "TaskMaster" daemons that "phd start" should start. You can
11011104
// raise this if you have a task backlog, or explicitly launch more with

scripts/daemon/phabricator_daemon_launcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ function will_launch($control, $with_logs = true) {
225225
echo "Staging launch...\n";
226226
$control->pingConduit();
227227
if ($with_logs) {
228-
$log_dir = $control->getControlDirectory('log').'/daemons.log';
228+
$log_dir = $control->getLogDirectory().'/daemons.log';
229229
echo "NOTE: Logs will appear in '{$log_dir}'.\n\n";
230230
}
231231
}

src/infrastructure/daemon/PhabricatorDaemonControl.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ public function launchDaemon($daemon, array $argv, $debug = false) {
254254
$flags[] = csprintf('--conduit-uri=%s', PhabricatorEnv::getURI('/api/'));
255255

256256
if (!$debug) {
257-
$log_dir = $this->getControlDirectory('log').'/daemons.log';
258-
$flags[] = csprintf('--log=%s', $log_dir);
257+
$log_file = $this->getLogDirectory().'/daemons.log';
258+
$flags[] = csprintf('--log=%s', $log_file);
259259
}
260260

261-
$pid_dir = $this->getControlDirectory('pid');
261+
$pid_dir = $this->getPIDDirectory();
262262

263263
// TODO: This should be a much better user experience.
264264
Filesystem::assertExists($pid_dir);
@@ -295,21 +295,30 @@ public static function ignoreSignal($signo) {
295295
return;
296296
}
297297

298-
public function getControlDirectory($dir) {
299-
$path = PhabricatorEnv::getEnvConfig('phd.pid-directory').'/'.$dir;
298+
private function getControlDirectory($path) {
300299
if (!Filesystem::pathExists($path)) {
301300
list($err) = exec_manual('mkdir -p %s', $path);
302301
if ($err) {
303302
throw new Exception(
304303
"phd requires the directory '{$path}' to exist, but it does not ".
305304
"exist and could not be created. Create this directory or update ".
306-
"'phd.pid-directory' in your configuration to point to an existing ".
307-
"directory.");
305+
"'phd.pid-directory' / 'phd.log-directory' in your configuration ".
306+
"to point to an existing directory.");
308307
}
309308
}
310309
return $path;
311310
}
312311

312+
public function getPIDDirectory() {
313+
$path = PhabricatorEnv::getEnvConfig('phd.pid-directory');
314+
return $this->getControlDirectory($path);
315+
}
316+
317+
public function getLogDirectory() {
318+
$path = PhabricatorEnv::getEnvConfig('phd.log-directory');
319+
return $this->getControlDirectory($path);
320+
}
321+
313322
protected function loadAvailableDaemonClasses() {
314323
$loader = new PhutilSymbolLoader();
315324
return $loader
@@ -321,7 +330,7 @@ protected function loadAvailableDaemonClasses() {
321330
public function loadRunningDaemons() {
322331
$results = array();
323332

324-
$pid_dir = $this->getControlDirectory('pid');
333+
$pid_dir = $this->getPIDDirectory();
325334
$pid_files = Filesystem::listDirectory($pid_dir);
326335
if (!$pid_files) {
327336
return $results;

0 commit comments

Comments
 (0)