Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.6 kB
3
Indexable
Never
#!/bin/bash

# Get the container ID of the running container
containerid=$(docker ps -aqf "name=analytics_v")

# Check if the webserver and scheduler processes are running
webserver_running=$(docker exec $containerid ps -ef | grep "airflow webserver" | grep -v grep | wc -l)
scheduler_running=$(docker exec $containerid ps -ef | grep "airflow scheduler" | grep -v grep | wc -l)

# If both processes are running, kill them and restart them
if [ $webserver_running -gt 0 ] && [ $scheduler_running -gt 0 ]; then
  echo "Both webserver and scheduler are up...killing processes and restarting both services"
  docker exec $containerid pkill -f "airflow webserver"
  docker exec $containerid pkill -f "airflow scheduler"
  docker exec $containerid airflow webserver -D
  docker exec $containerid airflow scheduler -D
# If neither process is running, start both of them
elif [ $webserver_running -eq 0 ] && [ $scheduler_running -eq 0 ]; then
  echo "Both webserver and scheduler are down...starting both webserver and scheduler"
  docker exec $containerid airflow webserver -D
  docker exec $containerid airflow scheduler -D
# If only the webserver process is running, start the scheduler
elif [ $webserver_running -gt 0 ] && [ $scheduler_running -eq 0 ]; then
  echo "Webserver is up and scheduler is down...starting scheduler"
  docker exec $containerid airflow scheduler -D
# If only the scheduler process is running, start the webserver
elif [ $webserver_running -eq 0 ] && [ $scheduler_running -gt 0 ]; then
  echo "Webserver is down and scheduler is up...starting webserver"
  docker exec $containerid airflow webserver -D
fi