#!/bin/sh

# arguments are:
# <initscriptname> <start|stop> <pre|post> <init script exitcode>

waitfor() {
    for i in $(seq 1 $1); do
        sleep 0.1
        test -e /omd/sites/monitor/tmp/apache/run/apache.pid || return 1 # only if apache is running, we don't want to break omd rm
        test -e $2 && return 0
    done
    return 1
}

# check return code of apache start
if [ $4 = 0 ]; then
    (waitfor 600 $OMD_ROOT/tmp/run/live && ./etc/init.d/thruk start &) >/dev/null 2>&1
fi
