#!/bin/sh
# managed by puppet
#
# Due to bug in logrotate, it always returns 0. Use grep for detect errors;
# exit code 1 is considered a success as no errors were found.

if ! pgrep -x logrotate &>/dev/null; then
    nice ionice -c3 /usr/sbin/logrotate /etc/logrotate.d/fuel.nodaily >& /tmp/logrotate
    grep -q error /tmp/logrotate
    EXITVALUE=$?
else
    /usr/bin/logger -t logrotate "WARNING another logrotate instance is already running, exiting"
    exit 1
fi

if [ $EXITVALUE != 1 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE] (1 was expected)"
    exit 1
fi

exit 0
