comparison debian/dcc-server.cron.daily @ 2:f6716cb00029

Replace buggy stuff in deb dir, never make phone calls while working
author Peter Gervai <grin@grin.hu>
date Tue, 10 Mar 2009 14:29:12 +0100
parents
children
comparison
equal deleted inserted replaced
1:9b8d79ac0dc3 2:f6716cb00029
1 #! /bin/sh
2
3 # daily DCC cron job
4
5 # This script should be run daily or more often when there is a shortage
6 # of disk space to run dbclean to discard and compress old checksums.
7 # It also discards old DCC client log files.
8
9 #. By default it is installed in /usr/lib/dcc. Instead of being copied
10 # to a directory such as /etc/cron/daily on some systems, a symbolic link
11 # should be used.
12
13 # Copyright (c) 2004 by Rhyolite Software
14 #
15 # Permission to use, copy, modify, and distribute this software for any
16 # purpose with or without fee is hereby granted, provided that the above
17 # copyright notice and this permission notice appear in all copies.
18 #
19 # THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE DISCLAIMS ALL
20 # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
21 # OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE
22 # BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
23 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
24 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
25 # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
26 # SOFTWARE.
27 # Rhyolite Software DCC 1.2.50-1.45 $Revision: 1.1 $
28 # Generated automatically from cron-dccd.in by configure.
29
30 exec 1>&2 </dev/null
31
32 DCC_LOGGER="logger -s -p ${DCC_ERROR_LOG_FACILITY-mail.err} -t DCC"
33 DCC_HOMEDIR=/var/lib/dcc
34 DEBUG=
35 QUIET=-q
36 # check the args once to get the home directory
37 while getopts "xh:a:" c; do
38 case $c in
39 x) set -x; DEBUG=-x; QUIET=;;
40 h) DCC_HOMEDIR="$OPTARG";;
41 *) ;;
42 esac
43 done
44 . $DCC_HOMEDIR/dcc_conf
45 # deal with bash reserved $UID and old versions of dcc_conf
46 if test 0"$DCC_CONF_VERSION" -lt 2 -a -z "$DCCUID" -a ! -z "$UID"; then
47 DCCUID="$UID"
48 fi
49
50 USAGE="`basename $0`: [-x] [-h homedir] [-a args]"
51 OPTIND=1
52 while getopts "xh:a:" c; do
53 case $c in
54 x) ;;
55 h) ;;
56 a) DBCLEAN_ARGS="$DBCLEAN_ARGS $OPTARG";;
57 *) eval $DCC_LOGGER "$USAGE"; exit 1;;
58 esac
59 done
60 shift `expr $OPTIND - 1 || true`
61 if test "$#" -ne 0; then
62 eval $DCC_LOGGER "$USAGE"
63 exit 1
64 fi
65
66 # make the paths absolute and trim the per day/hour/minute business
67 LOGDIR=`echo $DCCM_LOGDIR \
68 | sed -e "s@^[DHM]?@@" -e "s@^[^/]@$DCC_HOMEDIR/&@"`
69 USERDIRS=`echo $DCCM_USERDIRS \
70 | sed -e "s@^[^/]@$DCC_HOMEDIR/&@"`
71
72 OARGS=64dDGNRPSVqi
73 DBCLEAN_ARGS="$QUIET -h $DCC_HOMEDIR $DCC_LOG_ARGS $DBCLEAN_ARGS"
74 GREY_DBCLEAN_ARGS=`echo "$DBCLEAN_ARGS" \
75 | sed -e "s/-[eEt][ ]*[^ ]\{1,\}//g" \
76 -e "s/\(-[$OARGS]\{1,\}\)[eEt][ ]*[^ ]\{1,\}/\1/g"`
77
78 # Removed old dccm log files.
79 if test ! -z "$DBCLEAN_LOGDAYS"; then
80 if test -d "$LOGDIR"; then
81 find "$LOGDIR" -follow \( -name 'msg.*' -o -name 'tmp.*' \) \
82 -mtime +$DBCLEAN_LOGDAYS \
83 | xargs /bin/rm -f
84 # remove empty subdirectories
85 find "$LOGDIR" -follow -depth -name '[0-9]*' -type d \
86 | xargs /bin/rmdir 2>/dev/null
87 fi
88 # clean per-user logs
89 if test "$USERDIRS" != "" -a -d "$USERDIRS"; then
90 find "$USERDIRS" -follow \( -name 'msg.*' -o -name 'tmp.*' \) \
91 -mtime +$DBCLEAN_LOGDAYS \
92 | xargs /bin/rm -f
93 fi
94 fi
95
96 # Notify users about new log files.
97 # The file $DCC_LIBEXEC/webuser-notify must be a script that will send
98 # a suitable message. See the example in the cgi-bin directory.
99 if test "$USERDIRS" != "" -a -d "$USERDIRS" \
100 -a -x $DCC_LIBEXEC/webuser-notify; then
101 MARKER=$USERDIRS/notify.marker
102 touch $MARKER.new
103 if test -r $MARKER; then
104 NEWER="-newer $MARKER"
105 else
106 NEWER=
107 fi
108 # Find usernames with a pending message or with a new but not newer
109 # than new log files
110 # Avoid newer than new files to ensure we generate at most
111 # one notification per log file.
112 find "$USERDIRS" -follow \( -name notify.pending \
113 -o \( -name 'msg.*' $NEWER \) \) ! -newer $MARKER.new \
114 | sed -n -e 's@.*/\([^/]*/[^/]*\)/log/msg\.[^/]*$@\1@p' \
115 -e 's@.*/\([^/]*/[^/]*\)/notify.pending$@\1@p' \
116 | sort -u \
117 | $DCC_LIBEXEC/webuser-notify $DEBUG -d "$USERDIRS"
118
119 mv -f $MARKER.new $MARKER
120 fi
121
122
123 # trim the greylist database
124 case X"$GREY_ENABLE" in
125 [oO][nN])
126 GREY_ENABLE=on
127 ;;
128 X)
129 if test ! -z "$GREY_CLIENT_ARGS"; then
130 GREY_ENABLE=on
131 fi
132 ;;
133 esac
134 if test ! -z "$GREY_SRVR_ID" -a "$GREY_ENABLE" = on; then
135 SADDR=`expr "X$GREY_DCCD_ARGS" : ".*-[$OARGS]*a[ ]*\([^ ]*\).*"`
136 if test ! -z "$SADDR"; then
137 SADDR="-a $SADDR"
138 fi
139 $DCC_LIBEXEC/dbclean -Gon -i $GREY_SRVR_ID $SADDR $GREY_DBCLEAN_ARGS
140 fi
141
142
143 # Delete old checksums from the dccd database if it seems dccd can run.
144 # For historical reasons, SRVR_ID set and DCCD_ENABLE nul
145 # turns on dccd
146 case "$DCCD_ENABLE" in
147 [oO][fF][fF]) DCCD_ENABLE=off;;
148 *) DCCD_ENABLE=on;;
149 esac
150 if test ! -z "$SRVR_ID" -a "$DCCD_ENABLE" = on; then
151 SADDR=`expr "X$DCCD_ARGS" : ".*-[$OARGS]*a[ ]*\([^ ]*\).*"`
152 if test ! -z "$SADDR"; then
153 SADDR="-a $SADDR"
154 fi
155 $DCC_LIBEXEC/dbclean -i $SRVR_ID $SADDR $DBCLEAN_ARGS
156 fi