comparison misc/cron-dccd.in @ 0:c7f6b056b673

First import of vendor version
author Peter Gervai <grin@grin.hu>
date Tue, 10 Mar 2009 13:49:58 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c7f6b056b673
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 @libexecdir@. 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 # cron tab entry like this can be used:
14 # 15 2 * * * @libexecdir@/cron-dccd
15 # It is best to choose different times for each of your DCC servers so
16 # that your servers are not all busy cleaning their databases at once.
17
18 # -x turn on debugging
19 # -F do not follow symbolic links because they are used to share
20 # per-user directories
21 # -h dir override DCC home directory @prefix@
22 # -a args for dbclean in addition to DBCLEAN_ARGS in @prefix@/dcc_conf
23
24 # Copyright (c) 2008 by Rhyolite Software, LLC
25 #
26 # This agreement is not applicable to any entity which sells anti-spam
27 # solutions to others or provides an anti-spam solution as part of a
28 # security solution sold to other entities, or to a private network
29 # which employs the DCC or uses data provided by operation of the DCC
30 # but does not provide corresponding data to other users.
31 #
32 # Permission to use, copy, modify, and distribute this software without
33 # changes for any purpose with or without fee is hereby granted, provided
34 # that the above copyright notice and this permission notice appear in all
35 # copies and any distributed versions or copies are either unchanged
36 # or not called anything similar to "DCC" or "Distributed Checksum
37 # Clearinghouse".
38 #
39 # Parties not eligible to receive a license under this agreement can
40 # obtain a commercial license to use DCC by contacting Rhyolite Software
41 # at sales@rhyolite.com.
42 #
43 # A commercial license would be for Distributed Checksum and Reputation
44 # Clearinghouse software. That software includes additional features. This
45 # free license for Distributed ChecksumClearinghouse Software does not in any
46 # way grant permision to use Distributed Checksum and Reputation Clearinghouse
47 # software
48 #
49 # THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL
50 # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
51 # OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC
52 # BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
53 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
54 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
55 # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
56 # SOFTWARE.
57 # Rhyolite Software DCC 1.3.103-1.81 $Revision$
58 # @configure_input@
59
60 exec 1>&2 </dev/null
61 # English messages so grep can suppress them;
62 # simple collating sequence for sort
63 # sane gcc error messages
64 LC_ALL=C; export LC_ALL
65
66
67 LOGGER_TAG=cron-dccd
68 DCC_LOGGER="@DCC_LOGGER@"
69 DCC_HOMEDIR=@prefix@
70 DEBUG=
71 QUIET=-q
72 FOLLOW=-follow
73 # check the args once to get the home directory
74 while getopts ":xFh:a:" c; do
75 case $c in
76 x) set -x; DEBUG=-x; QUIET=;;
77 h) DCC_HOMEDIR="$OPTARG";;
78 *) ;;
79 esac
80 done
81 . $DCC_HOMEDIR/dcc_conf
82 # deal with bash reserved $UID and old versions of dcc_conf
83 if test 0"$DCC_CONF_VERSION" -lt 2 -a -z "$DCCUID" -a -n "$UID"; then
84 DCCUID="$UID"
85 fi
86
87 USAGE="`basename $0`: [-xF] [-h homedir] [-a args]"
88 OPTIND=1
89 while getopts "xFh:a:" c; do
90 case $c in
91 x) ;;
92 F) FOLLOW=;;
93 h) ;;
94 a) DBCLEAN_ARGS="$DBCLEAN_ARGS $OPTARG";;
95 *) eval $DCC_LOGGER "$USAGE"; exit 1;;
96 esac
97 done
98 shift `expr $OPTIND - 1 || true`
99 if test "$#" -ne 0; then
100 eval $DCC_LOGGER "$USAGE"
101 exit 1
102 fi
103
104 DCCD_GETOPTS="64dVbfFQi:n:h:a:I:q:G:t:W:K:T:u:C:L:R:"
105 DBCLEAN_GETOPTS="64dfFNRPSVqWi:a:h:G:s:e:E:t:L:"
106
107 DBCLEAN_ARGS="$QUIET -h $DCC_HOMEDIR $DCC_LOG_ARGS $DBCLEAN_ARGS"
108
109 # remove -e, -E, and -t from args for `dbclean -Gon`
110 set -f
111 GREY_DBCLEAN_ARGS=
112 OPTIND=1
113 while getopts "$DBCLEAN_GETOPTS" c $DBCLEAN_ARGS; do
114 case $c in
115 [eEt:?]) ;;
116 *) GREY_DBCLEAN_ARGS="$GREY_DBCLEAN_ARGS -$c $OPTARG";;
117 esac
118 done
119
120 # find addresses that dccd is using
121 ADDR=
122 OPTIND=1
123 while getopts "$DCCD_GETOPTS" c $DCCD_ARGS; do
124 case $c in
125 [46a]) ADDR="$ADDR -$c $OPTARG";;
126 *) ;;
127 esac
128 done
129 DBCLEAN_ARGS="$ADDR $DBCLEAN_ARGS"
130
131 ADDR=
132 OPTIND=1
133 while getopts "$DCCD_GETOPTS" c $GREY_DCCD_ARGS; do
134 case $c in
135 [46a]) ADDR="$ADDR -$c $OPTARG";;
136 *) ;;
137 esac
138 done
139 GREY_DBCLEAN_ARGS="$ADDR $GREY_DBCLEAN_ARGS"
140 set +f
141
142
143 # make the paths absolute and trim the per day/hour/minute business
144 DCCM_LOGDIR=`echo $DCCM_LOGDIR \
145 | sed -e 's@["'"']*@@g" -e "s@[DHM]?@@" -e "s@^[^/]@$DCC_HOMEDIR/&@"`
146 DCCM_USERDIRS=`echo $DCCM_USERDIRS \
147 | sed -e "s@^[^/]@$DCC_HOMEDIR/&@"`
148 DCCIFD_LOGDIR=`echo $DCCIFD_LOGDIR \
149 | sed -e 's@["'"']*@@g" -e "s@[DHM]?@@" -e "s@^[^/]@$DCC_HOMEDIR/&@"`
150 DCCIFD_USERDIRS=`echo $DCCIFD_USERDIRS \
151 | sed -e "s@^[^/]@$DCC_HOMEDIR/&@"`
152 LOGDIRS=
153 if test -n "$DCCM_LOGDIR" -a -d "$DCCM_LOGDIR"; then
154 LOGDIRS="$DCCM_LOGDIR"
155 fi
156 if test "$LOGDIRS" != "$DCCIFD_LOGDIR" -a -n "$DCCIFD_LOGDIR" \
157 -a -d "$DCCIFD_LOGDIR"; then
158 LOGDIRS="$LOGDIRS $DCCIFD_LOGDIR"
159 fi
160 USERDIRS=
161 if test -n "$DCCM_USERDIRS" -a -d "$DCCM_USERDIRS"; then
162 USERDIRS="$DCCM_USERDIRS"
163 fi
164 if test -n "$DCCIFD_USERDIRS" -a -d "$DCCIFD_USERDIRS"; then
165 # $DCCM_USERDIRS is often an initial substring of $DCCIFD_USERDIRS
166 if expr "$DCCIFD_USERDIRS" : "$DCCM_USERDIRS" >/dev/null; then :
167 else
168 USERDIRS="$USERDIRS $DCCIFD_USERDIRS"
169 fi
170 fi
171
172 # trim the greylist database
173 case X"$GREY_ENABLE" in
174 [oO][nN])
175 GREY_ENABLE=on
176 ;;
177 X)
178 if test -n "$GREY_CLIENT_ARGS"; then
179 GREY_ENABLE=on
180 fi
181 ;;
182 esac
183 if test -z "$GREY_SRVR_ID"; then
184 if test -n "`grep '# auto local greylist server-ID' $DCC_HOMEDIR/ids`" \
185 -a -n "`grep '^32702' $DCC_HOMEDIR/ids`"; then
186 GREY_SRVR_ID=32702
187 fi
188 fi
189 if test -n "$GREY_SRVR_ID" -a "$GREY_ENABLE" = on; then
190 if $DCC_LIBEXEC/dbclean -Gon -i $GREY_SRVR_ID $GREY_DBCLEAN_ARGS; then :
191 else
192 # assume EX_DCC_RESTART=79
193 if test $? -eq 79; then
194 eval $DCC_LOGGER "running dbclean -S and restarting greylist server"
195 $DCC_LIBEXEC/dbclean -S -Gon -i $GREY_SRVR_ID $GREY_DBCLEAN_ARGS
196 $DCC_LIBEXEC/start-grey
197 fi
198 fi
199 fi
200
201
202 # Delete old checksums from the dccd database if it seems dccd can run.
203 # For historical reasons, SRVR_ID set and DCCD_ENABLE null
204 # also turns on dccd.
205 case "$DCCD_ENABLE" in
206 [oO][fF][fF]) DCCD_ENABLE=off;;
207 *) DCCD_ENABLE=on;;
208 esac
209 if test -n "$SRVR_ID" -a "$DCCD_ENABLE" = on; then
210 if $DCC_LIBEXEC/dbclean -i $SRVR_ID $SADDR $DBCLEAN_ARGS; then :
211 else
212 # assume EX_DCC_RESTART=79
213 if test $? -eq 79; then
214 eval $DCC_LOGGER "running dbclean -S and restarting DCC server"
215 $DCC_LIBEXEC/dbclean -S -i $SRVR_ID $SADDR $DBCLEAN_ARGS
216 $DCC_LIBEXEC/start-dccd
217 fi
218 fi
219 fi
220
221
222 # Remove old dccm and dccifd log files.
223 if test -n "$DBCLEAN_LOGDAYS" -a -n "$LOGDIRS$USERDIRS"; then
224 ( find $LOGDIRS $USERDIRS $FOLLOW -type f \
225 \( \( -name 'msg.*' -mtime +$DBCLEAN_LOGDAYS \) \
226 -o \( -name 'tmp.*' -mtime +1 \) \) -print \
227 | @DCC_XARGS@ /bin/rm
228 find $LOGDIRS $USERDIRS $FOLLOW -depth -type d \
229 \( -name '[0-9]' -o -name '[0-9][0-9]' \
230 -o -name '[0-9][0-9][0-9]' \) -print \
231 | @DCC_XARGS@ /bin/rmdir
232 ) 2>&1 | grep -v 'No such file or directory' \
233 | grep -v 'Directory not empty'
234 fi
235
236 # Notify users about new log files.
237 # The file $DCC_LIBEXEC/webuser-notify must be a script that will send
238 # a suitable message. See the example in the cgi-bin directory.
239 if test -n "$USERDIRS" -a -x $DCC_LIBEXEC/webuser-notify; then
240 for DIR in $USERDIRS; do
241 MARKER=$DIR/notify.marker
242 if test -r $MARKER; then
243 NEWER="-newer $MARKER"
244 else
245 NEWER=
246 fi
247 rm -f $MARKER.new
248 touch $MARKER.new
249
250 # Find usernames with a pending message or with a new but not newer
251 # than new log file. Avoid newer than new files to ensure we
252 # generate at most one notification per log file.
253 (cd $DIR; find . $FOLLOW -type f \( -name notify.pending \
254 -o \( $NEWER -name 'msg.*' \) \) \
255 ! -newer $MARKER.new -print ) \
256 | sed -n -e 's@\./\(.*\)/log/msg\..*@\1@p' \
257 -e 's@\./\(.*\)/log/[0-9/]*/msg\..*@\1@p' \
258 -e 's@\./\(.*\)/notify.pending$@\1@p' \
259 | sort -u \
260 | $DCC_LIBEXEC/webuser-notify $DEBUG -d "$DIR"
261
262 mv -f $MARKER.new $MARKER
263 done
264 fi
265
266
267 # encourage local DCC clients to switch back
268 @bindir@/cdcc -q rtt >/dev/null 2>&1