Score:-1

ubuntu 20.04 cronjob at restart not working

cn flag

I have a bash file that just stops the existing docker container. The script works fine when I run it manually but it is not working on my crontab. I need to execute the bash script when I start my pc.

Crontab:(not working on start)

@reboot /var/www/airflow/stop_airflow.sh

Bash content (stop_airflow.sh)

#!/bin/bash
cd /var/www/airflow && docker-compose stop

Terminal Execution:

bash /var/www/airflow/stop_airflow.sh

Outputs:

Stopping airflow_airflow-worker_1    ... done 
Stopping airflow_flower_1            ... done 
Stopping airflow_airflow-webserver_1 ... done 
Stopping airflow_airflow-scheduler_1 ... done 
Stopping airflow_redis_1             ... done 
Stopping airflow_postgres_1          ... done
Always Sunny avatar
cn flag
yes, it is 20.04 but why down votes?
bac0n avatar
cn flag
Does your script have exec bit `+x`?
Always Sunny avatar
cn flag
yes it has the `+x`
bac0n avatar
cn flag
Isn't docker managed by systemd?
Score:1
it flag

Jobs run through cron aren't run in the same runtime environment that you have on your desktop. None of your PATH changes, or other environment variable settings from ~/.bashrc are automatically propagated to your cron job. For example, there's no $DISPLAY, so GUI programs need special treatment (read man xhost). In your case, your script is probably looking for, and not finding docker-compose in your $PATH.

One can set environment variables for all one's cron jobs in the crontab file Read man 5 crontab.

Look at the results of echo "=== id ===";id;echo "=== set ===";set;echo "=== env ===";env | sort;echo "=== alias ===";alias in each of your environments.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.