If you deploy a Python (or any) app to Azure App Service for Linux, you may find that cron jobs in /etc/cron.d/
silently stop working.
This is because App Service runs your app through a custom container with a startup.sh
as PID 1, and the cron daemon is never started.
Even if the cron
package is installed, it does nothing unless the daemon is launched.
Symptoms
- Valid cron files in
/etc/cron.d/
don’t execute. ps aux | grep cron
shows nocron
process running.systemctl
is not available (if your App Service container doesn't usesystemd
).
Debugging Steps
-
Check if cron is installed
apt-cache policy cron
-
Check if cron is running
ps aux | grep [c]ron
-
Verify cron file permissions. Must be in /etc/cron.d/ and owned by root:root, 644
Testing with a simple cron job
echo '* * * * * root date >> /tmp/testcron.log 2>&1' > /etc/cron.d/testcron
chmod 644 /etc/cron.d/testcron
chown root:root /etc/cron.d/testcron
Possible fix
Start cron manually in your startup command. Azure App Service lets you set a custom startup command in Settings → Configuration → Startup Command.
service cron start && HOME="/home/site/wwwroot" python3 app.py
The above manually starts the cron daemon and then runs your Python script – the latter is necessary because Azure won't start your Python script automatically if the Startup command is not empty. (The above assumes your Python entry point script is named app.py
.)
Alternatively, you can have a dedicated shell script that prepares your runtime, for example installs the cron jobs that you want to run – because remember, Azure won't persist anything outside /home, so your cron jobs in /etc will be lost on re-deployment.
chmod +x $APP_PATH/setup.sh && $APP_PATH/setup.sh && HOME="/home/site/wwwroot" python3 app.py