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