From 83d344342d7cd7d6abb503569f364b7b154069cd Mon Sep 17 00:00:00 2001 From: DariusIII Date: Fri, 28 Jul 2017 10:14:57 +0200 Subject: [PATCH] Update tmux starting and stopping commands with option to kill tmux session (in stop command) --- Changelog | 1 + app/Console/Commands/TmuxUIStart.php | 3 +- app/Console/Commands/TmuxUIStop.php | 41 ++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/Changelog b/Changelog index d5dea33b6..11afd365b 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2017-07-28 DariusIII + * Chg: Update tmux starting and stopping commands with option to kill tmux session (in stop command) * Chg: Add Tmux Model for future usage 2017-07-27 DariusIII * Chg: Add new console command to start and stop tmux (tmux-ui:start and tmux-ui:stop) diff --git a/app/Console/Commands/TmuxUIStart.php b/app/Console/Commands/TmuxUIStart.php index 19487abd9..9d6269286 100644 --- a/app/Console/Commands/TmuxUIStart.php +++ b/app/Console/Commands/TmuxUIStart.php @@ -19,7 +19,8 @@ class TmuxUIStart extends Command * * @var string */ - protected $description = 'Start tmux processing'; + protected $description = 'Start the processing of tmux scripts. This is functionally equivalent to setting the +\'tmux running\' setting in admin.'; /** * Create a new command instance. diff --git a/app/Console/Commands/TmuxUIStop.php b/app/Console/Commands/TmuxUIStop.php index bdbc8c962..c89dc716a 100644 --- a/app/Console/Commands/TmuxUIStop.php +++ b/app/Console/Commands/TmuxUIStop.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use App\Models\Tmux; use Illuminate\Console\Command; use Symfony\Component\Process\Process; @@ -12,14 +13,15 @@ class TmuxUIStop extends Command * * @var string */ - protected $signature = 'tmux-ui:stop'; + protected $signature = 'tmux-ui:stop {type}'; /** * The console command description. * * @var string */ - protected $description = 'Stop tmux processing'; + protected $description = 'Stop the processing of tmux scripts. This is functionally equivalent to unsetting the +\'tmux running\' setting in admin. Usage: tmux-ui:stop false (does not kill tmux session), while using true will kill current tmux session'; /** * Create a new command instance. @@ -37,16 +39,37 @@ class TmuxUIStop extends Command * @return mixed * @throws \Symfony\Component\Process\Exception\LogicException * @throws \Symfony\Component\Process\Exception\RuntimeException + * @throws \RuntimeException */ public function handle() { - $process = new Process('php misc/update/nix/tmux/stop.php'); - $process->run(function ($type, $buffer) { - if (Process::ERR === $type) { - echo 'ERR > '.$buffer; - } else { - echo $buffer; + if ($this->argument('type') === 'false' || $this->argument('type') === 'true') { + $process = new Process('php misc/update/nix/tmux/stop.php'); + $process->run(function ($type, $buffer) { + if (Process::ERR === $type) { + echo 'ERR > ' . $buffer; + } else { + echo $buffer; + } } - }); + ); + + if ($this->argument('type') === 'true') { + + $sessionName = Tmux::value('tmux_session'); + $tmuxSession = new Process('tmux kill-session -t ' . $sessionName); + $this->info('Killing active tmux session: ' . $sessionName); + $tmuxSession->run(function ($type, $buffer) { + if (Process::ERR === $type) { + echo 'ERR > ' . $buffer; + } else { + echo $buffer; + } + } + ); + } + }else { + $this->error($this->description); + } } }