restart queue service if service already exists

This commit is contained in:
Boy132 2024-06-04 13:14:54 +02:00
parent d81c9faac6
commit 0728266826

View File

@ -19,11 +19,12 @@ class QueueWorkerServiceCommand extends Command
public function handle(): void 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'; $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?')) { $fileExists = file_exists($path);
$this->line('Creation of queue worker service file aborted.'); 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; return;
} }
@ -60,13 +61,24 @@ WantedBy=multi-user.target
return; return;
} }
$result = Process::run("systemctl enable --now $serviceName.service"); if ($fileExists) {
if ($result->failed()) { $result = Process::run("systemctl restart $serviceName.service");
$this->error('Error enabling service: ' . $result->errorOutput()); 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.');
} }
} }