#!/bin/sh
#
# Simple logrotation for Coda server logfiles
#

vicedir=/vice
. "`codaconfedit server.conf`"

srvdir="${vicedir}/srv"
srvlog="${srvdir}/SrvLog"
srverr="${srvdir}/SrvErr"
authdir="${vicedir}/auth2"
authlog="${authdir}/AuthLog"

for i in 9 8 7 6 5 4 3 2 1 0 ; do
    j=`expr $i + 1`
    [ -f "${srvlog}-$i" ]  && mv -f "${srvlog}-$i"  "${srvlog}-$j"
    [ -f "${srverr}-$i" ]  && mv -f "${srverr}-$i"  "${srverr}-$j"
    [ -f "${authlog}-$i" ] && mv -f "${authlog}-$i" "${authlog}-$j"
done

[ -f "${srvlog}" ]  && mv -f "${srvlog}"  "${srvlog}-0"
[ -f "${srverr}" ]  && mv -f "${srverr}"  "${srverr}-0"
[ -f "${authlog}" ] && mv -f "${authlog}" "${authlog}-0"

# Tell codasrv and auth2 to reopen their logfiles
[ -f "${srvdir}"/pid ] && kill -HUP `cat "${srvdir}"/pid`  2>/dev/null
[ -f "${authdir}"/pid ] && kill -HUP `cat "${authdir}"/pid` 2>/dev/null

# alternatively use one of the following,
## run volutil in the background, just in case the server isn't running.
# volutil swaplog &
# killall -HUP codasrv
#
# and,
# killall -HUP auth2

