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