为 Amazon Beanstalk 上的 Laravel Queue Worker 提供环境变量
Provide environment variables to Laravel Queue Worker on Amazon Beanstalk
所以我在邮件通知方面遇到了这个奇怪的问题。我在 Amazon Elastic Beanstalk 上进行了部署,我正在使用 Amazon SQS 作为排队服务。对于邮件,我使用 Mailgun。现在的问题是邮件通知排队和处理失败。
有趣的是,当我发送未排队的电子邮件通知时,它被正确发送,之后队列电子邮件也发送了一段时间,然后又开始失败。
我也在通知中添加了 SerializeModels
特征。但是,在我发送一封未排队的电子邮件之前,它不起作用。
我的 User
class 也正确实施了方法 routeNotificationForMail
并且正在返回用户的电子邮件。
有人遇到过类似的问题吗?
##编辑
所以我已经深入到问题所在,systemd
中的工作进程 运行ning 不知何故无法从文件 /opt/elasticbeanstalk/deployment/env
转换或传输环境变量。现在,当我在终端中 运行 时,队列处理得很好。但是当队列工作者重新启动时没有任何作用。
我在 laravel_worker.service
中使用 EnvironmentFile=/opt/elasticbeanstalk/deployment/env
有人知道我该怎么做吗?
所以在试探和错误之后......到处敲我的头......解决方案非常简单。
我知道为 tinker
提供环境变量的命令,所以我创建了一个包含以下内容的 shell 脚本。
#!/bin/sh
cd /var/www/html && export $(cat /opt/elasticbeanstalk/deployment/env) && php artisan queue:work
The script file was owned by the root user, so I don't have to use sudo
with cat
然后我通过systemd
服务执行脚本。
ExecStart=/usr/bin/nohup /var/www/html/worker_script.sh
通过.ebextenstions
files:
/var/www/html/worker_script.sh:
mode: "000755"
owner: root
content: |
#!/bin/sh
cd /var/www/html && export $(cat /opt/elasticbeanstalk/deployment/env) && php artisan queue:work
/etc/systemd/system/laravel_worker.service:
mode: "000755"
owner: root
group: root
content: |
# Laravel queue worker using systemd
# ----------------------------------
#
# /lib/systemd/system/queue.service
#
# run this command to enable service:
# systemctl enable queue.service
[Unit]
Description=Laravel queue worker
[Service]
EnvironmentFile=/opt/elasticbeanstalk/deployment/env
Restart=always
ExecStart=/usr/bin/nohup /var/www/html/worker_script.sh
[Install]
WantedBy=multi-user.target
All configuration files are available at https://github.com/stescacom/elastic_beanstalk_laravel_mongo_config Hope this helps someone else.
所以我在邮件通知方面遇到了这个奇怪的问题。我在 Amazon Elastic Beanstalk 上进行了部署,我正在使用 Amazon SQS 作为排队服务。对于邮件,我使用 Mailgun。现在的问题是邮件通知排队和处理失败。
有趣的是,当我发送未排队的电子邮件通知时,它被正确发送,之后队列电子邮件也发送了一段时间,然后又开始失败。
我也在通知中添加了 SerializeModels
特征。但是,在我发送一封未排队的电子邮件之前,它不起作用。
我的 User
class 也正确实施了方法 routeNotificationForMail
并且正在返回用户的电子邮件。
有人遇到过类似的问题吗?
##编辑
所以我已经深入到问题所在,systemd
中的工作进程 运行ning 不知何故无法从文件 /opt/elasticbeanstalk/deployment/env
转换或传输环境变量。现在,当我在终端中 运行 时,队列处理得很好。但是当队列工作者重新启动时没有任何作用。
我在 laravel_worker.service
EnvironmentFile=/opt/elasticbeanstalk/deployment/env
有人知道我该怎么做吗?
所以在试探和错误之后......到处敲我的头......解决方案非常简单。
我知道为 tinker
提供环境变量的命令,所以我创建了一个包含以下内容的 shell 脚本。
#!/bin/sh
cd /var/www/html && export $(cat /opt/elasticbeanstalk/deployment/env) && php artisan queue:work
The script file was owned by the root user, so I don't have to use
sudo
withcat
然后我通过systemd
服务执行脚本。
ExecStart=/usr/bin/nohup /var/www/html/worker_script.sh
通过.ebextenstions
files:
/var/www/html/worker_script.sh:
mode: "000755"
owner: root
content: |
#!/bin/sh
cd /var/www/html && export $(cat /opt/elasticbeanstalk/deployment/env) && php artisan queue:work
/etc/systemd/system/laravel_worker.service:
mode: "000755"
owner: root
group: root
content: |
# Laravel queue worker using systemd
# ----------------------------------
#
# /lib/systemd/system/queue.service
#
# run this command to enable service:
# systemctl enable queue.service
[Unit]
Description=Laravel queue worker
[Service]
EnvironmentFile=/opt/elasticbeanstalk/deployment/env
Restart=always
ExecStart=/usr/bin/nohup /var/www/html/worker_script.sh
[Install]
WantedBy=multi-user.target
All configuration files are available at https://github.com/stescacom/elastic_beanstalk_laravel_mongo_config Hope this helps someone else.