comparison misc/stop-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 # stop dccd
4
5 # This script assumes that it is being run by root or the DCC user, probably
6 # while the system is stopping.
7
8 # Copyright (c) 2008 by Rhyolite Software, LLC
9 #
10 # This agreement is not applicable to any entity which sells anti-spam
11 # solutions to others or provides an anti-spam solution as part of a
12 # security solution sold to other entities, or to a private network
13 # which employs the DCC or uses data provided by operation of the DCC
14 # but does not provide corresponding data to other users.
15 #
16 # Permission to use, copy, modify, and distribute this software without
17 # changes for any purpose with or without fee is hereby granted, provided
18 # that the above copyright notice and this permission notice appear in all
19 # copies and any distributed versions or copies are either unchanged
20 # or not called anything similar to "DCC" or "Distributed Checksum
21 # Clearinghouse".
22 #
23 # Parties not eligible to receive a license under this agreement can
24 # obtain a commercial license to use DCC by contacting Rhyolite Software
25 # at sales@rhyolite.com.
26 #
27 # A commercial license would be for Distributed Checksum and Reputation
28 # Clearinghouse software. That software includes additional features. This
29 # free license for Distributed ChecksumClearinghouse Software does not in any
30 # way grant permision to use Distributed Checksum and Reputation Clearinghouse
31 # software
32 #
33 # THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL
34 # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
35 # OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC
36 # BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
37 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
38 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
39 # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
40 # SOFTWARE.
41 # Rhyolite Software DCC 1.3.103-1.28 $Revision$
42 # @configure_input@
43
44 exec 1>&2 </dev/null
45
46 LOGGER_TAG=stop-dccd
47 DCC_LOGGER="@DCC_LOGGER@"
48 DCC_HOMEDIR=@prefix@
49 CDCC_QUIET='>/dev/null 2>&1'
50 VERBOSE=
51 DEBUG=
52 GREY=
53 SYSSTOP=stop
54 DB_NM=dcc_db
55 # check the args once to get the home directory
56 while getopts ":xvGSCh:u:i:n:" c; do
57 case $c in
58 x) set -x; DEBUG=-x; VERBOSE=-v; CDCC_QUIET=;;
59 v) VERBOSE=-v;;
60 h) DCC_HOMEDIR="$OPTARG";;
61 *) ;;
62 esac
63 done
64 . $DCC_HOMEDIR/dcc_conf
65
66 USAGE="`basename $0`: [-xvGSC] [-h homedir] [-u UID] [-i id]"
67 OPTIND=1
68 while getopts "xvGSCh:u:i:n:" c; do
69 case $c in
70 x) ;;
71 v) ;;
72 G) GREY=yes DB_NM=grey_db;;
73 S) SYSSTOP="system stop";;
74 C) SYSSTOP="clean stop";;
75 h) ;;
76 u) DCCUID="$OPTARG";;
77 i) SRVR_ID="$OPTARG"; GREY_SRVR_ID="$OPTARG";;
78 n) ;; # obsolete
79 *) eval $DCC_LOGGER "$USAGE"; exit 1;;
80 esac
81 done
82 shift `expr $OPTIND - 1 || true`
83 if test "$#" -ne 0; then
84 eval $DCC_LOGGER "$USAGE"
85 exit 1
86 fi
87
88 if test "$DCC_HOMEDIR" != @prefix@; then
89 CDCC_ARGS="-h $DCC_HOMEDIR"
90 fi
91
92 if test -n "$GREY"; then
93 if test -z "$GREY_SRVR_ID" \
94 -a -n "`grep '# auto local greylist server-ID' $DCC_HOMEDIR/ids`" \
95 -a -n "`grep '^32702' $DCC_HOMEDIR/ids`"; then
96 GREY_SRVR_ID=32702
97 fi
98 SRVR_ID="$GREY_SRVR_ID"
99 DCCD_ARGS="$GREY_DCCD_ARGS"
100 CDCC_ARGS=" $CDCC_ARGS 'grey on'"
101 fi
102
103 if test -z "$SRVR_ID"; then
104 if test X"$DEBUG" = "X-x"; then
105 echo "SRVR_ID not set in $DCC_HOMEDIR/dcc_conf"
106 fi
107 exit
108 fi
109
110 # talk where the current server should be listening
111 SRVR_ADDR=`expr X"$DCCD_ARGS" : '.*-a[ ]*\([^ , ]*\)'`
112 SRVR_PORT=`expr X"$DCCD_ARGS" : '.*-a[ ]*[^ , ]*,\([^ , ]*\)'`
113 if test -n "$SRVR_ADDR"; then
114 CDCC_ARGS="$CDCC_ARGS 'server $SRVR_ADDR'"
115 fi
116 if test -n "$SRVR_PORT"; then
117 CDCC_ARGS="$CDCC_ARGS 'port $SRVR_PORT'"
118 fi
119
120 CDCC0="@bindir@/cdcc $CDCC_ARGS 'id $SRVR_ID'"
121 CDCC="$CDCC0 $CDCC_QUIET"
122
123 # stop a current dbclean
124 if test -s $DCC_HOMEDIR/$DB_NM.lock; then
125 kill `cat $DCC_HOMEDIR/$DB_NM.lock` >/dev/null 2>&1
126 fi
127
128 # stop the current daemon, including giving it time to shut down gracefully
129 # After telling the daemon to stop, keep telling the daemon to politely
130 # stop flooding until it stops answering or we run out of patience.
131 # Then tell it to pull the plug.
132 if eval "$CDCC '$SYSSTOP' 'sleep 0.5'"; then
133 LCNT=0
134 while eval "$CDCC 'flood list' 'sleep 0.5'" ; do
135 LCNT=`expr $LCNT + 1`
136 # Pull the plug on the floods after 5 seconds
137 if test "$LCNT" -ge 10; then
138 if test "$VERBOSE" = "-v"; then
139 if test "$LCNT" -eq 10; then
140 eval "$CDCC0 'flood list'"
141 fi
142 fi
143 eval "$CDCC 'flood halt' 'sleep 0.5'"
144 fi
145 # give up after another second to let the daemon close the file
146 if test "$LCNT" -gt 12; then
147 break;
148 fi
149 done
150 fi
151
152 set +x
153 if test X"$DEBUG" = "X-x"; then
154 echo "The final cdcc command should have failed, since that is how"
155 echo "this script knows that dccd has stopped."
156 fi