From f4fe3c9184262c4212810ba7a1cfd3477a6fa2c3 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Sat, 10 Aug 2024 07:17:08 +0800 Subject: [PATCH] Add command to restart supervisor in clear-caches-all command --- app/Console/Commands/ClearCachesAll.php | 5 ++ app/Console/Commands/RestartSupervisor.php | 67 ++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 app/Console/Commands/RestartSupervisor.php diff --git a/app/Console/Commands/ClearCachesAll.php b/app/Console/Commands/ClearCachesAll.php index 9f76333..a4ab10d 100644 --- a/app/Console/Commands/ClearCachesAll.php +++ b/app/Console/Commands/ClearCachesAll.php @@ -72,6 +72,11 @@ class ClearCachesAll extends Command } else { $this->error("Composer install failed:\n" . implode("\n", $output)); } + + // run command RestartSupervisor + $output = []; + $returnVar = null; + exec('php artisan supervisor:restart 2>&1', $output, $returnVar); $this->info("All caches have been cleared."); } diff --git a/app/Console/Commands/RestartSupervisor.php b/app/Console/Commands/RestartSupervisor.php new file mode 100644 index 0000000..8b69f49 --- /dev/null +++ b/app/Console/Commands/RestartSupervisor.php @@ -0,0 +1,67 @@ +error($errorMessage); + Log::error($errorMessage); + return 1; + } + + // Restart all Supervisor services + $output = shell_exec('supervisorctl restart all 2>&1'); + + // Log and display the output + Log::info("supervisorctl restart all executed with output: {$output}"); + $this->info("Supervisor services restarted. Output: {$output}"); + + return 0; + } catch (Exception $e) { + $this->error("An error occurred: " . $e->getMessage()); + Log::error("Error in RestartSupervisor command: " . $e->getMessage()); + return 1; + } + } +}