option('service-name') ?? $this->ask('Queue worker service name', 'pelican-queue'); $path = '/etc/systemd/system/' . $serviceName . '.service'; $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 service file already exists.'); return; } $user = $this->option('user') ?? $this->ask('Webserver User', 'www-data'); $group = $this->option('group') ?? $this->ask('Webserver Group', 'www-data'); $redisUsed = config('queue.default') === 'redis' || config('session.driver') === 'redis' || config('cache.default') === 'redis'; $afterRedis = $redisUsed ? ' After=redis-server.service' : ''; $basePath = base_path(); $success = File::put($path, "# Pelican Queue File # ---------------------------------- [Unit] Description=Pelican Queue Service$afterRedis [Service] User=$user Group=$group Restart=always ExecStart=/usr/bin/php $basePath/artisan queue:work --tries=3 StartLimitInterval=180 StartLimitBurst=30 RestartSec=5s [Install] WantedBy=multi-user.target "); if (!$success) { $this->error('Error creating service file'); return; } if ($fileExists) { $result = Process::run("systemctl restart $serviceName.service"); if ($result->failed()) { $this->error('Error restarting service: ' . $result->errorOutput()); 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.'); } } }