File: rotate-httpd

package info (click to toggle)
http-analyze 2.4-2.1
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 3,344 kB
  • ctags: 924
  • sloc: ansic: 11,678; perl: 241; sh: 215; makefile: 214
file content (67 lines) | stat: -rwxr-xr-x 2,136 bytes parent folder | download
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/ksh
#
# $Id: rotate-httpd,v 1.4 1999/05/02 13:46:37 stefan Exp $
#
# Rotate server log files and archive the old logfiles.
# Does not affect users who may be connected to the server.
#
# Copyright  1996-1999 by Stefan Stapelberg/RENT-A-GURU, <stefan@rent-a-guru.de>
#

# ANALYZE contains the name of the executable program.
ANALYZE=/usr/local/bin/http-analyze

# SRVROOT is the name of the ServerRoot directory
# where the server configurations are kept usually.
# This is also the working directory for rotate-httpd.
SRVROOT=/usr/ns-home

# CFGFILE defines the name of the config file for the
# servers to be analyzed. The config files are searched
# for in each of the directories in $SRVLIST.
CFGFILE=analyze.conf

# SRVLIST contains the names of the server_root directories
# for all virtual servers. It contains the config file
# ($CFGFILE) and the server's logfile (logs/access).
SRVLIST='httpd-80'

# This are the names of all logfiles to rotate.
LOGS='access errors secure'

# Set the date, check for year wrap.
typeset -i MON YEAR
typeset -Z2 MON

eval $(date "+MABB='%B' MON='%m' YEAR='%Y'")
((MON=$MON-1)); [ $MON -eq 0 ] && { MON="12"; ((YEAR=$YEAR-1)); }
LOGDIR="log$YEAR"

# Change into server root, save current logfiles of all
# servers as `logYYYY/access.MM'. Restart the server to
# re-initialize logging.

cd $SRVROOT || { echo "panic: can't cd into $SRVROOT" 1>&2; exit 1; }

for server in $SRVLIST; do
	(cd $server/logs
	    [ ! -d "$LOGDIR" ] && { mkdir $LOGDIR; }
	    for file in $LOGS; do
		[ -f $file ] && { mv $file $LOGDIR/$file.$MON; }
		echo "$server/logs/$file saved in $LOGDIR/$file.$MON" 1>&2
	    done)
	# Restart the server. Netscape servers provide a script `restart'.
	# For other servers you probably need to send them a SIGHUP using
	# the kill(1) or killall(1) command, for example:
	# killall -SIGHUP ns-httpd
	$server/restart
done

# Now run http-analyze. For each server, a configuration file
# must exist under the ServerRoot.

for server in $SRVLIST; do
	(cd $server; [ -s $CFGFILE ] && \
	 { $ANALYZE -m -c $CFGFILE logs/$LOGDIR/access.$MON; \
	   $ANALYZE -m -c $CFGFILE; })
done