diff --git a/app/Console/Commands/Environment/QueueWorkerServiceCommand.php b/app/Console/Commands/Environment/QueueWorkerServiceCommand.php index 3fe3da4c9..68f2c6750 100644 --- a/app/Console/Commands/Environment/QueueWorkerServiceCommand.php +++ b/app/Console/Commands/Environment/QueueWorkerServiceCommand.php @@ -19,11 +19,12 @@ class QueueWorkerServiceCommand extends Command public function handle(): void { - $serviceName = $this->option('service-name') ?? $this->ask('Queue worker Service name', 'pelican-queue'); + $serviceName = $this->option('service-name') ?? $this->ask('Queue worker service name', 'pelican-queue'); $path = '/etc/systemd/system/' . $serviceName . '.service'; - if (file_exists($path) && !$this->option('overwrite') && !$this->confirm('The service file already exists. Do you want to overwrite it?')) { - $this->line('Creation of queue worker service file aborted.'); + $fileExists = file_exists($path); + if ($fileExists && !$this->option('overwrite') && !$this->confirm('The service file already exists. Do you want to overwrite it?')) { + $this->line('Creation of queue worker service file aborted because serive file already exists.'); return; } @@ -60,13 +61,24 @@ WantedBy=multi-user.target return; } - $result = Process::run("systemctl enable --now $serviceName.service"); - if ($result->failed()) { - $this->error('Error enabling service: ' . $result->errorOutput()); + if ($fileExists) { + $result = Process::run("systemctl restart $serviceName.service"); + if ($result->failed()) { + $this->error('Error restarting service: ' . $result->errorOutput()); - return; + return; + } + + $this->line('Queue worker service file updated successfully.'); + } else { + $result = Process::run("systemctl enable --now $serviceName.service"); + if ($result->failed()) { + $this->error('Error enabling service: ' . $result->errorOutput()); + + return; + } + + $this->line('Queue worker service file created successfully.'); } - - $this->line('Queue worker service file created successfully.'); } }