I’m trying to create a service on an Amazon Linux 2023 instance to run a mysql database queue for Laravel 10. For various reasons I cant use Supervisor so I’m using Systemd.
I’m upgrading the AMI, and from Laravel 9 to 10, so I know this has worked in the past (but its untested with SystemD).
I’ve created a service, laravel-worker.service, to execute the "artisan queue:work" command. After doing "sudo systemctl daemon-reload", "sudo systemctl start laravel-worker" it appears to start the worker and immediately finish it.
I’ve confirmed it’s not processing the queue. I can see the jobs are sitting in the database.
If I SSH in and type ‘artisan queue:work’ the jobs get processed.
Here’s the service
EDIT: I’ve tried Type=simple and oneshot with no difference.
[Unit]
Description=Laravel Queue Worker
After=network.target
[Service]
User=root
Group=root
#Type=simple
Type=oneshot
Restart=on-failure
RemainAfterExit=true
ExecStart=/usr/bin/nohup /usr/bin/php /var/www/html/artisan queue:work --sleep=3 --tries=3
TimeoutStopSec=infinity
[Install]
WantedBy=multi-user.target
Here’s the status response from ‘sudo systemctl status laravel-worker’
laravel-worker.service - Laravel Queue Worker
Loaded: loaded (/etc/systemd/system/laravel-worker.service; enabled; preset: disabled)
Active: active (exited) since Thu 2023-12-21 18:26:13 UTC; 1h 2min ago
Main PID: 621553 (code=exited, status=0/SUCCESS)
CPU: 53ms
Dec 21 18:26:13 ip-xxxxxxxxxx.us-east-2.compute.internal systemd[1]: Starting laravel-worker.service - Laravel Queue Worker...
Dec 21 18:26:13 ip-xxxxxxxxxx.us-east-2.compute.internal systemd[1]: Finished laravel-worker.service - Laravel Queue Worker.
2
Answers
Thanks to @Marcin Orlowski I got to the bottom of this. I needed to add -f after the command and set Type=simple.
For anyone looking for a solution in the future, here was my final service
The
Type=oneshot
is typically used for scripts that perform a task and then exit which might not be suitable for a continuously running service like a worker, soType=simple
seems more appropriate for your case.