Commit | Line | Data |
---|---|---|
d2462e94 | 1 | #!/bin/bash |
2 | ||
e16ccb3a | 3 | # invoked by cron as root on each web node |
d2462e94 | 4 | |
5 | exec 2>&1 | |
6 | ||
7 | # drop any tokens; use only users' cgi tokens | |
b7036601 | 8 | kdestroy > /dev/null 2>&1 |
d2462e94 | 9 | unlog |
10 | ||
b7036601 | 11 | #VERBOSE=true |
4a967ab2 | 12 | if [ -z "$VERBOSE" ]; then |
13 | VERBOSE=false | |
14 | fi | |
b7036601 | 15 | |
d8d03ff4 | 16 | LOCAL_LOG_DIR=/var/log/apache2/user |
b7036601 | 17 | KEYTAB_DIR=/etc/keytabs/user.daemon |
18 | AFS_USER_DIR=/afs/hcoop.net/user | |
19b04bd3 | 19 | ERROR=no |
b7036601 | 20 | |
d8d03ff4 | 21 | # Iterate through logs for each user |
22 | for A in $(find $LOCAL_LOG_DIR -mindepth 3 -maxdepth 3 -print); do | |
b7036601 | 23 | USER=`basename $A` |
24 | PATHBITS=`echo $USER | head -c 1`/`echo $USER | head -c 2`/$USER | |
ba4e6c35 | 25 | USER_HOME=$AFS_USER_DIR/$PATHBITS |
e16ccb3a CE |
26 | LOG_SRC=$A/apache/log/$(hostname) |
27 | LOG_DEST=$USER_HOME/.logs/apache/$(hostname) | |
b7036601 | 28 | |
be8e70a1 | 29 | # Skip deleted or empty log directories |
e16ccb3a CE |
30 | # Possible inefficiency? (ls entire directory*400+ dirs) |
31 | if test ! -d "$LOG_SRC" || ! ls "$LOG_SRC"/*/*.log >/dev/null 2>&1; then | |
d5a2aada | 32 | if test "$VERBOSE" = "true"; then |
33 | echo "Skipping $USER (deleted or empty log dir $LOG_SRC)" | |
34 | fi | |
be8e70a1 | 35 | continue |
36 | fi | |
37 | ||
ba4e6c35 | 38 | # Skip people who have unreadable log subdirectories |
e16ccb3a | 39 | # This test is broken! --clinton |
ba4e6c35 | 40 | if test -d "$USER_HOME/.logs" && \ |
41 | ! ls "$USER_HOME/.logs" >/dev/null 2>&1; then | |
d5a2aada | 42 | if test "$VERBOSE" = "true"; then |
43 | echo "Skipping $USER (unreadable log dir $USER_HOME/.logs)" | |
44 | fi | |
ba4e6c35 | 45 | continue |
46 | fi | |
47 | ||
c14f6fa4 | 48 | # Skip people who do not have keytabs |
49 | if test ! -f "$KEYTAB_DIR/$USER"; then | |
d5a2aada | 50 | if test "$VERBOSE" = "true"; then |
51 | echo "Skipping $USER (missing keytab $KEYTAB_DIR/$USER)" | |
52 | fi | |
c14f6fa4 | 53 | continue |
54 | fi | |
55 | ||
be8e70a1 | 56 | if test "$VERBOSE" = "true"; then |
b7036601 | 57 | echo |
58 | echo "==============================================================================" | |
e16ccb3a | 59 | echo "syncing logs for $USER from $LOG_SRC" |
b7036601 | 60 | echo " to $LOG_DEST ..." |
61 | fi | |
62 | ||
e16ccb3a CE |
63 | if test ! -d "$USER_HOME/.logs/apache"; then |
64 | echo "Error: $USER_HOME/.logs/apache does not exist, please make it" | |
8513bbc6 | 65 | # ERROR=yes |
66 | # We will assume that people know what they are doing when they | |
67 | # delete their ~/.logs/apache directory .... | |
e16ccb3a | 68 | # This is perhaps a bad assumption --clinton |
9c29302d | 69 | if test "$VERBOSE" = "true"; then |
70 | echo "Skipping $USER (no $LOG_DEST directory)" | |
71 | fi | |
8513bbc6 | 72 | continue |
b7036601 | 73 | else |
089cf0fa | 74 | # LOG_SRC/* is important: don't remove log files just because a vhost is gone |
75 | k5start -qtU -f $KEYTAB_DIR/$USER -- rsync -a --no-owner --no-group --delete $LOG_SRC/* $LOG_DEST/ | |
e16ccb3a | 76 | test "$VERBOSE" = "true" && echo " done." |
b7036601 | 77 | fi |
d2462e94 | 78 | done |
19b04bd3 | 79 | |
be8e70a1 | 80 | if test "$ERROR" = "yes"; then |
19b04bd3 | 81 | exit 1 |
82 | else | |
83 | exit 0 | |
84 | fi | |
85 |