#! /bin/sh
#
# DFSG cron script to rotate the vboxgetty logfiles.

# if no vboxgettys configured, stop asap

[ -f /etc/isdn/vboxgetty.conf ] || exit 0

# if package removed but not purged, also stop

[ -x /usr/sbin/vboxd ] || exit 0

# If the expected log dir doesn't exist, quit also

[ -d /var/log/vbox   ] || exit 0

cd /var/log/vbox
for LOG in vboxgetty-ttyI*.log
do
        if [ -s $LOG ]; then
		savelog -p -c 4 $LOG >/dev/null
	fi
done

# kill current vboxgettys so that they start logging to new logfiles
# (init takes care of restarting them, as they are listed in /etc/inittab)

# start-stop-daemon --stop --quiet  --exec /usr/sbin/vboxgetty
for i in /var/run/vboxgetty-ttyI*.pid; do
    if [ -s "$i" ]; then
        kill `cat $i 2>/dev/null` >/dev/null 2>&1
    fi
done

exit 0
