#!/bin/bash

/usr/bin/id

POLL_SCRIPTS=${POLL_SCRIPTS:-"poll_adei_data.php poll_HV_data.php"}
POLL_INTERVAL=${POLL_INTERVAL:-60}

if [ ${POLL_INTERVAL} -gt 0 ]; then
    for SCRIPT_NAME in ${POLL_SCRIPTS}; do
        (
            while true; do
                [ -f ${SCRIPT_NAME} ] && \
                    echo "Polling data: $(date) [${SCRIPT_NAME}]" && \
                    php ${SCRIPT_NAME}
                sleep ${POLL_INTERVAL}
            done
        ) &
    done
fi

echo "Starting server process"
/usr/sbin/apache2ctl -D FOREGROUND $@ || exit $?
