From ef22fe1e743c85e9d2d7e1fdc321b4a1bb5ba466 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 22 Feb 2015 16:29:46 -0800 Subject: [PATCH] Add a --force command to `phd start` Summary: Ref T7352. This isn't wildly useful for us but seems generally reasonable, can be helpful with testing, and @hach-que has a use case for it. The only reason we issue this warning is to prevent user error; you can still launch all the daemons with `phd launch` manually and daemons all use locks to protect critical regions. Test Plan: Ran `phd start --force` a bunch, saw zillions of daemons. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley, hach-que Maniphest Tasks: T7352 Differential Revision: https://secure.phabricator.com/D11861 --- ...abricatorDaemonManagementStartWorkflow.php | 9 ++++- .../PhabricatorDaemonManagementWorkflow.php | 33 ++++++++++--------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/applications/daemon/management/PhabricatorDaemonManagementStartWorkflow.php b/src/applications/daemon/management/PhabricatorDaemonManagementStartWorkflow.php index 4fe526d365..7826dde662 100644 --- a/src/applications/daemon/management/PhabricatorDaemonManagementStartWorkflow.php +++ b/src/applications/daemon/management/PhabricatorDaemonManagementStartWorkflow.php @@ -19,11 +19,18 @@ final class PhabricatorDaemonManagementStartWorkflow 'By default, **phd start** will free all task leases held by '. 'the daemons. With this flag, this step will be skipped.'), ), + array( + 'name' => 'force', + 'help' => pht( + 'Start daemons even if daemons are already running.'), + ), )); } public function execute(PhutilArgumentParser $args) { - return $this->executeStartCommand($args->getArg('keep-leases')); + return $this->executeStartCommand( + $args->getArg('keep-leases'), + $args->getArg('force')); } } diff --git a/src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php b/src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php index 24cd531515..aa89f9f738 100644 --- a/src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php +++ b/src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php @@ -286,25 +286,28 @@ abstract class PhabricatorDaemonManagementWorkflow /* -( Commands )----------------------------------------------------------- */ - protected final function executeStartCommand($keep_leases = false) { + protected final function executeStartCommand($keep_leases, $force) { $console = PhutilConsole::getConsole(); - $running = $this->loadRunningDaemons(); + if (!$force) { + $running = $this->loadRunningDaemons(); - // This may include daemons which were launched but which are no longer - // running; check that we actually have active daemons before failing. - foreach ($running as $daemon) { - if ($daemon->isRunning()) { - $message = pht( - "phd start: Unable to start daemons because daemons are already ". - "running.\n". - "You can view running daemons with 'phd status'.\n". - "You can stop running daemons with 'phd stop'.\n". - "You can use 'phd restart' to stop all daemons before starting new ". - "daemons."); + // This may include daemons which were launched but which are no longer + // running; check that we actually have active daemons before failing. + foreach ($running as $daemon) { + if ($daemon->isRunning()) { + $message = pht( + "phd start: Unable to start daemons because daemons are already ". + "running.\n\n". + "You can view running daemons with 'phd status'.\n". + "You can stop running daemons with 'phd stop'.\n". + "You can use 'phd restart' to stop all daemons before starting ". + "new daemons.\n". + "You can force daemons to start anyway with --force."); - $console->writeErr("%s\n", $message); - exit(1); + $console->writeErr("%s\n", $message); + exit(1); + } } }