1 | <?php |
||
2 | |||
3 | namespace App\Console\Commands; |
||
4 | |||
5 | use App\Models\Settings; |
||
6 | use Blacklight\Tmux; |
||
7 | use Illuminate\Console\Command; |
||
8 | use Illuminate\Support\Facades\Process; |
||
9 | |||
10 | class TmuxUIStart extends Command |
||
11 | { |
||
12 | /** |
||
13 | * The name and signature of the console command. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $signature = 'tmux-ui:start'; |
||
18 | |||
19 | /** |
||
20 | * The console command description. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $description = 'Start the processing of tmux scripts.'; |
||
25 | |||
26 | /** |
||
27 | * Execute the console command. |
||
28 | */ |
||
29 | public function handle(): void |
||
30 | { |
||
31 | $tmux = new Tmux; |
||
32 | $tmux_session = Settings::settingValue('tmux_session') ?? 0; |
||
33 | |||
34 | // Set running value to on. |
||
35 | $tmux->startRunning(); |
||
36 | |||
37 | // check if session exists |
||
38 | $session = Process::run("tmux list-session | grep $tmux_session"); |
||
39 | if ($session->exitCode() === 1) { |
||
40 | $this->info('Starting the tmux server and monitor script'); |
||
41 | Process::forever()->tty()->run('php '.app()->/* @scrutinizer ignore-call */ path().'/../misc/update/tmux/run.php')->output(); |
||
42 | } else { |
||
43 | $this->error("tmux session: '".$tmux_session."' is already running, aborting."); |
||
44 | exit(); |
||
0 ignored issues
–
show
|
|||
45 | } |
||
46 | } |
||
47 | } |
||
48 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.