#!/bin/bash
#---------------------
# Testing masakari-daemons
#---------------------
set -e
DAEMONS=('masakari-host-monitor'
         'masakari-instance-monitor'
         'masakari-introspective-instance-monitor'
         'masakari-process-monitor')

ret=0

for daemon in "${DAEMONS[@]}"; do
    TIMEOUT=50
    systemctl restart $daemon
    while [ "$TIMEOUT" -gt 0 ]; do
        if pidof -x $daemon > /dev/null; then
            echo "OK"
            break
        fi
        TIMEOUT=$((TIMEOUT - 1))
        sleep 0.1
    done

    if [ "$TIMEOUT" -le 0 ]; then
        echo "ERROR: ${daemon} IS NOT RUNNING"
        ret=1
    fi
done

exit $ret
