We have a Laravel SystemD job for the queue, which for example sends out notification email.
Now we noticed, that the SystemD job is stopped when a email delivery did not work.
This is how our service definition looks like:
/etc/systemd/system # cat example.com-queue.service
[Unit]
Description=Laravel queue worker
[Service]
User=www-data
Group=www-data
Restart=on-failure
ExecStart=/usr/bin/php /var/www/html/example.com/web/artisan queue:work --daemon
[Install]
WantedBy=multi-user.target
The website https://www.freedesktop.org/software/systemd/man/systemd.service.html#Restart= states, that on-failure does not restart "on success".
If we look closer at the service state, we see that the Laravel Queue is actually exiting with a "0" exit code:
# systemctl status example.com-queue.service
● example.com-queue.service - Laravel queue worker
Loaded: loaded (/etc/systemd/system/example.com-queue.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sat 2021-08-14 15:11:18 CEST; 2 days ago
Process: 2417820 ExecStart=/usr/bin/php /var/www/html/example.com/web/artisan queue:work --daemon (code=exited, status=0/SUCCESS)
Aug 14 15:11:08 example php[2417820]: [2021-08-14 15:11:08][16768] Processing: App\Notifications\UploadSuccess
Aug 14 15:11:18 example php[2417820]: [2021-08-14 15:11:18][16768] Failed: App\Notifications\UploadSuccess
Aug 14 15:11:18 example systemd[1]: example.com-queue.service: Succeeded.
There is a easy fix: We could switch to "Restart=always", but I want to shed light on the fact and find out why Laravel - in case of an error - returns a zero exit code. Also we are afraid that "Restart=always" might cause unwanted side effects.