1

I am running an artisan command via the scheduler on elastic beanstalk.

Elastic beanstalk cronjobs need to be passed the environment variables required for the process as follows.

* * * * * ec2-user source /opt/elasticbeanstalk/support/envvars; php /var/app/current/artisan schedule:run >> /dev/null 2>&1

Where /opt/elasticbeanstalk/support/envvars is a list of exports.

This works fine for the process running the scheduler itself, but the scheduler executes commands on separate processes and therefore the environment variables are missing.

For example

[ec2-user@ip-x-x-x-x current]$ php artisan schedule:run
Running scheduled command: '/usr/bin/php-7.0' 'artisan' rewards:notify > '/dev/null' 2>&1

Which then doesn't have access to the environment variables because the shell doesn't have a concept of a profile it seems and therefore doesn't autosource .bashrc etc.

How can I get the environment variables from the aforementioned file to be read in before my commands?

Ben Swinburne
  • 25,669
  • 10
  • 69
  • 108
  • Could you parse /opt/elasticbeanstalk/support/envvars before execution in your command classes and set the variables using putenv()? There's a slightly messy example of that in one of the answers here: https://stackoverflow.com/questions/22563862/aws-elastic-beanstalk-running-cron-d-script-missing-environment-variables – ShaunUK Aug 10 '17 at 14:50

0 Answers0