Skip to content

Commit

Permalink
Squash 2041 - Try Kyle's updated script for healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
MackHalliday committed Nov 21, 2024
1 parent 5b49d6a commit f17fb56
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions scripts/check_celery.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
#!/bin/sh
#! /bin/sh

set -e

function get_celery_pids {
# get the PIDs of the process whose parent is the main celery process, saved in celery.pid
# print only pid and their command, get the ones with "celery" in their name
# and keep only these PIDs
grep_string="run_celery.notify_celery\ worker"
celery_pid_count=$(ps aux | grep -E run_celery.notify_celery\ worker | grep -v grep | wc -l)

set +o pipefail # so grep returning no matches does not premature fail pipe
APP_PIDS=$(pstree -p `cat /tmp/celery.pid` | sed 's/\(.*\)-celery(\(\d*\))/\2/')
echo "Here are the APP_PIDS: ${APP_PIDS}"
set -o pipefail # pipefail should be set everywhere else
}

function ensure_celery_is_running {
if [ "${APP_PIDS}" = "" ]; then
echo "There are no celery processes running, this container is bad"
exit 1
fi

for APP_PID in ${APP_PIDS}; do
kill -0 ${APP_PID} 2&>/dev/null || return 1
done
}

get_celery_pids

ensure_celery_is_running
if [ $celery_pid_count -ne 17 ]; then
echo -e "There are an incorrect number of Celery PIDs: $celery_pid_count"
exit 1
else
echo "Celery health check okay"
fi

0 comments on commit f17fb56

Please sign in to comment.