import repository from arizona
[raven.git] / tools / misc / runvisitors.sh
1 #! /bin/bash
2
3 LOG_FN="/var/log/httpd/access_log"
4 DEST_FN="/repository/visitors/index.html"
5
6 LOCKFILE="/tmp/visitors_lock"
7
8 mutex_lock()
9 {
10    if test -r $LOCKFILE
11    then # If a lock file exists, check if the process that created it
12         # is still running.
13       PROCESS=$(cat $LOCKFILE)
14    else
15       PROCESS=" "
16    fi
17    if (ps -p $PROCESS) > /dev/null 2>&1
18    then
19       echo "The Stork initscript is already running"
20       exit 1
21    else
22       # The process is not running, create new lock file containing PID.
23       rm -f $LOCKFILE
24       echo $$ > $LOCKFILE
25       LOCKED="true"
26    fi
27 }
28
29 mutex_unlock()
30 {
31    # remove the lock file if the mutex was locked
32    if [ -n "$LOCKED" ]
33    then
34       rm -f $LOCKFILE
35       LOCKED=""
36    fi
37 }
38
39 mutex_lock
40
41 tail -n 50000 $LOG_FN > /tmp/trimmed_log
42 /usr/local/bin/visitors /tmp/trimmed_log -X --max-age 300 > $DEST_FN
43 chown apache $DEST_FN
44
45 mutex_unlock