summaryrefslogtreecommitdiffstats
path: root/projectroot/etc/init.d/logrotate
blob: c10c12d33e94080a1dcbf7c20729f41c803b989b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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