#!/bin/sh

set -e

# Du a fuzz to avoid doing the cron job at
# the same time on all the barbican-common
# hosts.
MAX_DELAY=300
hostsum=$(hostname | cksum | cut -d' ' -f1)
SLEEP_TIME=$(( hostsum % $MAX_DELAY ))
sleep $SLEEP_TIME

if [ -x /usr/bin/barbican-manage ] ; then
	su -s /bin/sh -c "barbican-manage db clean --min-days 180 --clean-unassociated-projects --soft-delete-expired-secrets --log-file /var/log/barbican/barbican-clean-command.log" barbican 1>/dev/null 2>/dev/null
fi

exit 0
