laravel - 使用 restart=on-failure 时,Laravel systemd 队列作业停止
问题描述
我们有一个用于队列的 Laravel SystemD 作业,例如发送通知电子邮件。
现在我们注意到,当电子邮件发送不起作用时,SystemD 作业会停止。
这就是我们的服务定义的样子:
/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
该网站https://www.freedesktop.org/software/systemd/man/systemd.service.html#Restart=指出,失败时不会“成功”重新启动。
如果我们仔细观察服务状态,我们会发现 Laravel 队列实际上以“0”退出代码退出:
# 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.
有一个简单的解决方法:我们可以切换到“Restart=always”,但我想阐明这个事实并找出 Laravel 的原因——如果出现错误——返回零退出代码。此外,我们担心“Restart=always”可能会导致不必要的副作用。
解决方案
推荐阅读
- java - 如何使视图与图片中的视图重叠
- javascript - 自定义“g-signin2”样式按钮
- javascript - 我在使用 formik 时遇到调度问题“TypeError: Cannot read property 'then' of undefined”
- pandas - 自定义行和列选择熊猫
- django - 如何从我的前端向 django 请求添加变量?
- xamarin - Xamarin Forms 5 - 下载图像以供将来使用
- git - 如何在 Azure DevOps 中查看用户跨多个存储库的提交?
- acumatica - 如何从 Acumatica 的批准屏幕 (EP503010) 中删除“我的批准”选项卡?
- resharper - CLion 和 ReSharper 之间的同步设置
- elasticsearch - 如何区分elasticsearch的结果