#!/bin/bash
SERVICES=('celeryd' 'celerybeat')
  
for service in ${SERVICES[@]}; do
    if ps ax | grep -v grep | grep $service > /dev/null
    then
        echo "$service service running, everything is fine"
    else
        echo "$service is not running"
        cd /var/www/helios-server && \
        source venv/bin/activate

        if [ "$service" == "celeryd" ]; then
            python manage.py celeryd --events --loglevel=INFO --concurrency=5 -f celery.log &
        else
            python manage.py $service --logleve=INFO -f $service.log &
        fi

        echo "$service is not running!" | mail -s "$service down" root
    fi
done
exit 0

Add bash script to check if celery is running
Add bash script to check if celery is running

Celeryd is responsible for tasks and celerybeat for
periodic tasks like the one that cleans old celery_taskmeta
entries. settings.py holds the needed config for this to work:

Example:

CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
CELERY_TASK_RESULT_EXPIRES = 5184000 # 60 days

One can put this script to run in crontab:
*/10 * * * *  /<script_location>/check-services.sh >/dev/null 2>&1
