#!/usr/bin/env bash

#"OK": 0
#"WARNING": 1
#"CRITICAL": 2
#"UNKNOWN": 3

SUPERVISOR_STATUS=$(supervisorctl status zulip-workers:zulip_deliver_enqueued_emails 2>&1)
STATUS=$(echo "$SUPERVISOR_STATUS" | awk '{ print $2 }')


case "$STATUS" in
    RUNNING)
        echo "Running"
        exit 0
        ;;
    STOPPED|STARTING|BACKOFF|STOPPING|EXITED|FATAL|UNKNOWN)
        # not "RUNNING", but a recognized supervisor status
        echo "$STATUS"
        exit 1
        ;;
    *)
        # we don't recognize the second column in this SUPERVISOR_STATUS.
        # This may be indicative of a supervisor configuration problem
        echo "$SUPERVISOR_STATUS"
        exit 3
        ;;
esac
