diff options
Diffstat (limited to 'projectroot/etc/init.d/logrotate')
-rw-r--r-- | projectroot/etc/init.d/logrotate | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/projectroot/etc/init.d/logrotate b/projectroot/etc/init.d/logrotate new file mode 100644 index 000000000..c10c12d33 --- /dev/null +++ b/projectroot/etc/init.d/logrotate @@ -0,0 +1,49 @@ +#!/bin/sh + +# +# /etc/init.d/logrotate - Minimal Log Rotator for /var/log/{messages,*.{log,err}} +# + +PREFIX="logrotate: " +LOGDIR="/var/log" +MAXFILES="8" +PATTERNS="*.err *.log messages" + +my_exit(){ + echo "${PREFIX}${1}" + exit $2 +} + +logrotate(){ + cd "${LOGDIR}" + # rotate backups for log files + for filename in ${PATTERNS}; do + [ -e "${filename}" ] && + echo "${PREFIX}rotation for ${filename} ... " && + for i in `seq $(( MAXFILES - 1 )) -1 1` ; do + if [ -e "${filename}.${i}" ] + then + j=$(( i + 1 )) + mv -f ${filename}.${i} ${filename}.${j} + fi + done && + mv -f ${filename} ${filename}.1 + done +} + +# +# Main +# + +[ -d "$LOGDIR" ] || my_exit "Logdir $LOGDIR missing" 1 + +case $1 in + + start|stop) + echo "${PREFIX}rotating in $LOGDIR" + logrotate + ;; + *) + echo "Usage: $0 [start|stop]" + ;; +esac |