AWS Elastic Beanstalk: Running Cron.d script, missing Environment Variables

前端 未结 9 1160
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 10:39

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 Variab

相关标签:
9条回答
  • 2021-01-17 11:17

    While searching for solutions to the same problem I ran into this blog post: http://sebgoo.blogspot.nl/2013/10/elastic-beanstalk-cron-command-and-rds.html. To summarize, you can load the Elastic Beanstalk environment variables using the opt/elasticbeanstalk/support/envvars file:

    0 3 * * * . /opt/elasticbeanstalk/support/envvars; some_command
    

    Hope this helps!

    0 讨论(0)
  • 2021-01-17 11:21

    I just found this, using

    grep -r "export MY_VAR" /
    

    EDIT: Amazon seems to move the file location from time to time. Current location is:

    /opt/elasticbeanstalk/support/envvars
    

    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.

    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
    

    See @userid53's answer below for PHP solution.

    0 讨论(0)
  • 2021-01-17 11:22

    In case you need something similar for CodeIgniter:

    * * * * * root . /opt/elasticbeanstalk/support/envvars && /usr/bin/php /var/www/html/index.php controller method
    

    Example:

    * * * * * root . /opt/elasticbeanstalk/support/envvars && /usr/bin/php /var/www/html/index.php tasks pushNotification
    

    A more descriptive alternative:

    * * * * * root source /opt/elasticbeanstalk/support/envvars && /usr/bin/php /var/www/html/index.php tasks pushNotification
    
    0 讨论(0)
提交回复
热议问题