Crontab on Linux Webapp Container

Jason Zwanepoel 66 Reputation points
2020-05-24T18:46:43.257+00:00

Hi.

I'm running a Laravel Application in my container and require the scheduler to run a command every minute as seen here.
https://laravel.com/docs/7.x/scheduling#introduction I'm quite new with container and docker as well as Azure Services.

I'm building my application trough a deployment slot on my container using Azure Dev-ops, this uses the docker file to build my application container and run it then deploy to the slot. currently stuck with being able to run my scheduler trough a cron-job or command.

Hoping you might be able to assist me.

Kind Regards

Azure Container Registry
Azure Container Registry
An Azure service that provides a registry of Docker and Open Container Initiative images.
394 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,915 questions
0 comments No comments
{count} votes

Accepted answer
  1. SnehaAgrawal-MSFT 18,366 Reputation points
    2020-05-27T17:09:51.377+00:00

    Thanks for asking question!

    For Custom Containers you may follow below steps.

    1. Enable CRON job for custom containers:
    2. To Enable cron, add the following line to Dockerfile: RUN apt-get install -yqq cron
    3. And following line in the container init script (init_container.sh)
      (crontab -l && echo "* * * * * echo 'hello from cron' >> /home/site/wwwroot/cron1.txt")|crontab
    4. In this case we will write “hello from cron” to file /home/site/wwwroot/cron1.txt every minute. You can replace this with anything else you wish to run periodically.
    5. echo 'hello from cron' >> /home/site/wwwroot/cron1.txt
    6. for crontab syntax please refer to:
    7. List item

    https://www.adminschoice.com/crontab-quick-reference

    https://crontab-generator.org/

    •For Blessed Images:

    1. Create a script file in /home directory of the App Service and trigger it via the startup command under Configuration blade.
    2. A test script which installs cron as well as create a CRON job:

      !/bin/sh

    apt-get update -qq && apt-get install cron -yqq

    service cron start

    mkdir /home/BackupLogs

    (crontab -l 2>/dev/null; echo "*/5 * * * * cp /home/LogFiles/*.log /home/BackupLogs")|crontab

    Hope this helps!

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2020-10-22T15:12:45.237+00:00

    I don't know if you resolved this, or find any other challenges, but i couldn't make the scheduler work. Using Linux Web app, added a script to install cron and configure it and didn't work.

    until... i added the full php path.

            • /usr/bin/local/php /home/site/wwwroot/artisan schedule:run

  2. Rob Lane 1 Reputation point
    2021-11-16T13:35:05.1+00:00

    When running on blessed images (PHP 8 in linux app service) you need to use the following path

    /usr/local/bin/php

    Not the

    /usr/bin/local/php mentioned above.

    So for laravel artisan it's

    E.G. /usr/local/bin/php /home/site/wwwroot/artisan migrate

    0 comments No comments