繁体   English   中英

如何在 Elastic Beanstalk 上运行 Laravel 数据库队列?

[英]How do I run a Laravel database queue on Elastic Beanstalk?

I am new to AWS EB but was able to set up a PHP 8.0 running on 64bit Amazon Linux 2/3.3.9 Laravel API.

我在数据库队列中有一些作业,我想使用php artisan queue:listen运行。 我关注了这个Stack Exchange 问题,但是当我推送我的代码时,脚本没有运行,因为作业没有执行

我可以手动将 SSH 放入 EC2 实例中,并使用这个问题/opt/elasticbeanstalk/deployment/env中手动设置 env 变量。 然后,当我运行php artisan queue:listen时,它可以工作!

如何设置我的脚本,以便它们在 EC2/EB 实例启动并且队列上的作业运行时运行?

PS:我的环境配置工作正常,数据库配置工作正常

这是我当前的脚本设置:

./.ebextensions/01-setup.config

 container_commands: 01-no_dev: command: "composer.phar install --optimize-autoloader --no-dev" 02-config_clear: command: "php artisan config:clear" 03-view_clear: command: "php artisan view:clear" 04-route_cache: command: "php artisan route:cache" 05-view_cache: command: "php artisan view:cache" 06-migrate: command: "php artisan migrate --force" leader_only: true 07-queue_service_restart: command: "systemctl restart laravel_worker" files: /opt/elasticbeanstalk/tasks/taillogs.d/laravel-logs.conf: content: /var/app/current/storage/logs/laravel.log group: root mode: "000755" owner: root /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] User=nginx Group=nginx Restart=always ExecStart=/usr/bin/nohup /usr/bin/php /var/www/html/artisan queue:work //is this line correct??? [Install] WantedBy=multi-user.target

\.platform\nginx\conf.d\elasticbeanstalk\laravel.conf

 location / { try_files $uri $uri/ /index.php?$query_string; gzip_static on; }

./.ebextensions/cron-linux.config

 files: "/etc/cron.d/schedule_run": mode: "000644" owner: root group: root content: | * * * * * root. /opt/elasticbeanstalk/deployment/env && /usr/bin/php /var/app/current/artisan schedule:run 1>> /dev/null 2>&1 commands: remove_old_cron: command: "rm -f /etc/cron.d/*.bak"

如果您的脚本/应用程序依赖于不是 in.env 但作为 os 环境变量加载的变量,则默认情况下您的 cron 将无法访问它们。

除非您在启动 cron 之前使用以下命令导出: env >> /etc/environment

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM