#!/var/cfengine/httpd/php/bin/php

<?php
if (PHP_SAPI != 'cli') {
    print 'Only allowed to run from the CLI';
}

/*
   NOTE Upon successful cli_task if a stampfile is present and writeable, it
   will be touched. This is legacy signaling so that the Masterfiles Policy
   Framework can try to determine if the runalerts process gets stuck and needs
   refreshed.
*/

$stampdir = '/var/cfengine/httpd/php/runalerts-stamp';

while (1 == 1) {
    print 'Checking for all alerts';
    if (
        passthru(
            '/var/cfengine/httpd/php/bin/php /var/cfengine/httpd/htdocs/public/index.php cli_tasks runalerts 300 20 all',
        )
    ) {
        if (is_writeable('$(stampdir)/runalerts_all')) {
            touch('$(stampdir)/runalerts_all');
        }
    }

    print 'Sleeping for 60 seconds';
    sleep(60);
}

