0

I'm a newbie developer and I am messing around with Symfony and AWS. I have a Symfony app deployed via elastic beanstalk and I am trying to add a cron job every minute.

Basically I want the cron job to execute a Symfony command I created : update-pings, that is supposed to update some fields in my RDS DB.

I'm using a 02-crons.config file in my ./ebextensions directory that looks like this (greatly inspired from AWS documentation https://aws.amazon.com/fr/premiumsupport/knowledge-center/cron-job-elastic-beanstalk/ ) :

files:
  "/etc/cron.d/mycron":
    mode: "000644"
    owner: root
    group: root
    content: |
      * * * * * root php /var/app/current/bin/console app:update-pings


commands:
  remove_old_cron:
    command: "rm -f /etc/cron.d/mycron.bak"

Well, first of all, this is not working, the fields in the DB are not updating. So i connected in SSH to my EC2 instance to see what's happening.

The mycron file in /etc/cron.d/was correctly created with * * * * * root php /var/app/current/bin/console app:update-pingsinside of it.

Now, I tried replacing the content of this file by a simple * * * * * root echo test >> /tmp/cron_temp, this is working perfectly, a line with 'test' is added in my cron_temp file every minute

I tried running the initial command php /var/app/current/bin/console app:update-pingsmanually on the instance, works perfectly as ec2-user

When I switch to root user using sudo su -, the command still works. But when I try to run it with sudo, it fails, not sure if that's any relevant :

In EnvVarProcessor.php line 171:
Environment variable not found: "DATABASE_DBNAME".

I believe there is something I'm missing with linux users/rights, but I'm a total newbie with that and cannot find what's going on

Any ideas ? Thanks a lot in advance ! :)

Edit 1 : I'm know logging the sterr of the commande into a file and I get the same environment variable error as when I try to run the command manually with sudo

In EnvVarProcessor.php line 171:
Environment variable not found: "DATABASE_DBNAME".

The command works fine without sudo though

jarias
  • 1
  • 1
  • That missing environment variable might be a clue. I would modify your cron command to output stderr to a file so you can see what went wrong. (https://stackoverflow.com/questions/2342826/how-can-i-pipe-stderr-and-not-stdout) – jlucier May 29 '20 at 17:15
  • Thx, I logged the error to a file with 2>> and I get the same Environment variable error as when I manually run the command with sudo. ```In EnvVarProcessor.php line 171: Environment variable not found: "DATABASE_DBNAME".``` – jarias May 30 '20 at 09:09

0 Answers0