简体   繁体   中英

Run cron job in symfony

I'm using docker for may symfony application and I need to run a cron job every minute. So basically I have a command my:command which I normally run like this: app/console my:command I tried several variations but all were unsuccessful. So my question is how can I run a cron job? Here are some of my tries:

First:

* * * * * cd /usr/lib/myProject && app/console my:command >> /usr/lib/myProject/app/logs/log1.log

Second:

* * * * * /usr/lib/myProject/app/console my:command >> /usr/lib/myProject/app/logs/log1.log

is your cronjob in your docker Image or outside? If it's outside your should check that php is already installed. You can run the command whereis php or which php to get to know the absolute path to the php binary. Then you put the path for the app/console command.

If your cronjob is inside of your docker container, you must to check that the cron daemon should run as a process. Use docker ps for it or go inside your container and execute ps awwx . If crond not already running I would suggest you take a look at supervisord. With this software you can run more than one process in one docker container.

At least posibility you can configure the cronjob outside but execute the command inside of the container. To do this you should prepand docker exec command in your crontab.

Hope it helps.

Cheers, Robin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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