AWS Elastic Beanstalk:运行 Cron.d 脚本,缺少环境变量
我正在尝试运行由 cron 脚本(在 cron.d 中)触发的 PHP 脚本.该脚本已正确触发,但缺少存储在 $_SERVER 超全局变量中的 Elastic Beanstalk环境变量".该脚本目前以用户root"身份运行,但它不在具有环境变量的同一环境中.变量设置正确,如果我从完整的 shell 运行脚本,它运行得很好.
I'm trying to run a PHP script that is triggered by a cron script (in cron.d). The script is triggered properly but it is missing the Elastic Beanstalk "Environment Variables" that are stored in the $_SERVER superglobal. The script is being run as the user "root" for now, but it's not in the same environment that has the environment variables. The variables are set correctly, if I run the script from a full shell it runs just fine.
这些变量的导出"在哪里?他们在哪里设置?我在/etc/apache/conf.d/aws_env.conf 中找到了 Apache 的 SetEnvs.我在用户的 .bashrc、.bash_profile 等文件中找不到任何内容.有解决方法吗?有更好的方法吗?
Where are the "exports" for these variables? Where do they get set? I found the SetEnvs for Apache in /etc/apache/conf.d/aws_env.conf. I can't find anything in the user's .bashrc, .bash_profile, etc. Is there a workaround? A better way to do this?
谢谢.
推荐答案
我刚刚发现这个,使用
grep -r "export MY_VAR" /
亚马逊似乎不时移动文件位置.当前位置是:
Amazon seems to move the file location from time to time. Current location is:
/opt/elasticbeanstalk/support/envvars
所以我想我会在调用我的 php 脚本之前在我的脚本中包含 (source [file path]) .似乎仍然是一种时髦的做事方式.我仍在寻找更好的解决方案.
So I think I'll just include (source [file path]) that in my script before calling my php script. Still seems like a funky way to do things. I'm still in for better solutions.
我通过 cron 触发的 bash 脚本运行 PHP.所以要设置环境,我会做这样的事情:
I was running PHP via bash script triggered by cron. So to setup the environment, I would do something like this:
#!/bin/bash
source /opt/elasticbeanstalk/support/envvars
php -f my-script.php
有关 PHP 解决方案,请参阅下面@userid53 的回答.
See @userid53's answer below for PHP solution.
相关文章