Update tmux starting and stopping commands with option to kill tmux session (in stop command)

This commit is contained in:
DariusIII
2017-07-28 10:14:57 +02:00
parent ef736a4a25
commit 83d344342d
3 changed files with 35 additions and 10 deletions
+32 -9
View File
@@ -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);
}
}
}