Mercurial > notdcc
comparison misc/start-dccm.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 # start dccm | |
4 | |
5 # This script assumes that it is being run by root or the DCC user, probably | |
6 # while the system is starting. It should be run before sendmail is started | |
7 # to avoid complaints from sendmail about the socket not existing. | |
8 # See the misc/rcDCC script. | |
9 | |
10 # Copyright (c) 2008 by Rhyolite Software, LLC | |
11 # | |
12 # This agreement is not applicable to any entity which sells anti-spam | |
13 # solutions to others or provides an anti-spam solution as part of a | |
14 # security solution sold to other entities, or to a private network | |
15 # which employs the DCC or uses data provided by operation of the DCC | |
16 # but does not provide corresponding data to other users. | |
17 # | |
18 # Permission to use, copy, modify, and distribute this software without | |
19 # changes for any purpose with or without fee is hereby granted, provided | |
20 # that the above copyright notice and this permission notice appear in all | |
21 # copies and any distributed versions or copies are either unchanged | |
22 # or not called anything similar to "DCC" or "Distributed Checksum | |
23 # Clearinghouse". | |
24 # | |
25 # Parties not eligible to receive a license under this agreement can | |
26 # obtain a commercial license to use DCC by contacting Rhyolite Software | |
27 # at sales@rhyolite.com. | |
28 # | |
29 # A commercial license would be for Distributed Checksum and Reputation | |
30 # Clearinghouse software. That software includes additional features. This | |
31 # free license for Distributed ChecksumClearinghouse Software does not in any | |
32 # way grant permision to use Distributed Checksum and Reputation Clearinghouse | |
33 # software | |
34 # | |
35 # THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL | |
36 # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | |
37 # OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC | |
38 # BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES | |
39 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
40 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | |
41 # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |
42 # SOFTWARE. | |
43 # Rhyolite Software DCC 1.3.103-1.72 $Revision$ | |
44 # @configure_input@ | |
45 | |
46 exec 1>&2 </dev/null | |
47 | |
48 ARGV0=dccm | |
49 LOGGER_TAG=start-dccm | |
50 DCC_LOGGER="@DCC_LOGGER@" | |
51 DCC_HOMEDIR=@prefix@ | |
52 QUIET=yes | |
53 # check the args once to get the home directory | |
54 while getopts ":xvh:r:u:c:a:l:L:R:w:" c; do | |
55 case $c in | |
56 x) set -x;; | |
57 v) QUIET=;; | |
58 h) DCC_HOMEDIR="$OPTARG";; | |
59 *) ;; | |
60 esac | |
61 done | |
62 if test ! -s $DCC_HOMEDIR/dcc_conf; then | |
63 eval $DCC_LOGGER "cannot find $DCC_HOMEDIR/dcc_conf" | |
64 fi | |
65 . $DCC_HOMEDIR/dcc_conf | |
66 if test 0"$DCC_CONF_VERSION" -lt 2; then | |
67 # deal with bash reserved $UID and old versions of dcc_conf | |
68 if test -z "$DCCUID" -a -n "$UID"; then | |
69 DCCUID="$UID" | |
70 fi | |
71 if test -z "$DCC_RUNDIR" -a -n "$DCCM_RUNDIR"; then | |
72 DCC_RUNDIR="$DCCM_RUNDIR" | |
73 fi | |
74 fi | |
75 | |
76 if test "$DCC_HOMEDIR" != @prefix@; then | |
77 DCCM_ARGS="-h$DCC_HOMEDIR $DCCM_ARGS" | |
78 fi | |
79 | |
80 # convert old `dccm -G` to `dccm -Gon` | |
81 DCCM_ARGS=`echo "$DCCM_ARGS" \ | |
82 | sed -e 's/-\([VdbxANQW]\{1,\}\)G/-\1 -G/g' \ | |
83 -e 's/-G\([^- ]\)/-G -\1/g' \ | |
84 -e 's/-G/-Gon/g' -e 's/-G[ ]*on[ ]*on/-Gon/g'` | |
85 if test -n "$GREY_CLIENT_ARGS"; then | |
86 if test X`expr "X$GREY_CLIENT_ARGS" : '.*\(-G\)'` = X; then | |
87 GREY_CLIENT_ARGS="-G$GREY_CLIENT_ARGS" | |
88 fi | |
89 DCCM_ARGS="$GREY_CLIENT_ARGS $DCCM_ARGS" | |
90 fi | |
91 | |
92 if test -n "$DCCM_USERDIRS"; then | |
93 DCCM_ARGS="-U$DCCM_USERDIRS $DCCM_ARGS" | |
94 fi | |
95 | |
96 | |
97 USAGE="`basename $0`: [-xv] [-h homedir] [-r rundir] [-u UID] [-a args] \ | |
98 [-l logdir] [-L log-at] [-R reject_at] [-w whiteclnt]" | |
99 OPTIND=1 | |
100 while getopts "xvh:r:u:c:a:l:L:R:w:" c; do | |
101 case $c in | |
102 x) ;; | |
103 v) ;; | |
104 h) ;; | |
105 r) DCC_RUNDIR="$OPTARG";; | |
106 u) DCCUID="$OPTARG";; | |
107 c) X=`expr "X$OPTARG" : '\(X[-._a-zA-Z0-9]*\)'` | |
108 if test "$X" = X -o "$X" != "X$OPTARG"; then | |
109 eval $DCC_LOGGER "illegal -c $OPTARG" | |
110 else | |
111 ARGV0="$OPTARG" | |
112 fi;; | |
113 a) DCCM_ARGS="$DCCM_ARGS $OPTARG";; | |
114 l) DCCM_LOGDIR="$OPTARG";; | |
115 L) DCCM_LOG_AT="$OPTARG";; | |
116 R) DCCM_REJECT_AT="$OPTARG";; | |
117 w) DCCM_WHITECLNT="$OPTARG";; | |
118 *) eval $DCC_LOGGER "$USAGE"; exit 1;; | |
119 esac | |
120 done | |
121 shift `expr $OPTIND - 1 || true` | |
122 if test "$#" -ne 0; then | |
123 eval $DCC_LOGGER "$USAGE" | |
124 exit 1 | |
125 fi | |
126 | |
127 if test -n "$DCC_RUNDIR" -a "$DCC_RUNDIR" != @dcc_rundir@; then | |
128 DCCM_ARGS="-R$DCC_RUNDIR $DCCM_ARGS" | |
129 fi | |
130 if test -n "$DCCM_LOGDIR"; then | |
131 # add extra quotes for '?' not present in dcc_conf | |
132 if expr "$DCCM_LOGDIR" : '[DHM]?' >/dev/null; then | |
133 DCCM_ARGS="'-l$DCCM_LOGDIR' $DCCM_ARGS" | |
134 else | |
135 DCCM_ARGS="-l$DCCM_LOGDIR $DCCM_ARGS" | |
136 fi | |
137 fi | |
138 CKS="$REP_ARGS" | |
139 if test -n "$DCCM_LOG_AT$DCCM_REJECT_AT"; then | |
140 for CK in ${DCCM_CKSUMS:=CMN} $DCCM_XTRA_CKSUMS; do | |
141 CKS="$CKS -t$CK,$DCCM_LOG_AT,$DCCM_REJECT_AT" | |
142 done | |
143 fi | |
144 if test -n "$DCCM_WHITECLNT"; then | |
145 CKS="$CKS -w$DCCM_WHITECLNT" | |
146 fi | |
147 DCCM_ARGS="$CKS $DNSBL_ARGS $DCC_LOG_ARGS $DCCM_ARGS" | |
148 | |
149 | |
150 # stop an existing dccm | |
151 # signal the process group because on Linux systems it does not work | |
152 # to signal the main process. See `man sigwait` on a Linux system. | |
153 PID=`cat $DCC_RUNDIR/$ARGV0.pid 2>/dev/null` | |
154 if test -n "$PID"; then | |
155 if `kill -15 $PID 2>/dev/null`; then | |
156 CNT=0 | |
157 while test $CNT -lt 6; do | |
158 if `/bin/kill -15 $PID 2>/dev/null`; then | |
159 if test -z "$QUIET"; then | |
160 if test $CNT -eq 0; then | |
161 echo " stopping dccm PID $PID " | tr -d '\012' | |
162 else | |
163 echo "." | tr -d '\012' | |
164 fi | |
165 fi | |
166 sleep 1 | |
167 CNT=`expr $CNT + 1` | |
168 else | |
169 break | |
170 fi | |
171 done | |
172 /bin/kill -9 $PID 2>/dev/null | |
173 if test $CNT -ne 0 -a -z "$QUIET"; then | |
174 echo | |
175 fi | |
176 fi | |
177 fi | |
178 | |
179 # assume unset DCCD_ENABLE is "on" for upward compatibility | |
180 case "$DCCM_ENABLE" in | |
181 [oO][fF][fF]) exit 0;; | |
182 esac | |
183 if test ! -x $DCC_LIBEXEC/dccm; then | |
184 eval $DCC_LOGGER "cannot start dccm because it has not been installed" | |
185 exit 1 | |
186 fi | |
187 | |
188 if test ! -d $DCC_RUNDIR; then | |
189 mkdir $DCC_RUNDIR | |
190 fi | |
191 | |
192 if test "$ARGV0" != dccm -a ! -s $DCC_LIBEXEC/$ARGV0; then | |
193 ln -s dccm $DCC_LIBEXEC/$ARGV0 | |
194 fi | |
195 | |
196 # first try to use `su -` to set limits | |
197 # fall back to -I for systems where su requires a valid shell in | |
198 # /etc/passwd but where the dcc user does not have one | |
199 if test -n "$DCCUID" -a X"$DCCUID" != X"$USER"; then | |
200 if test -d $DCC_RUNDIR; then | |
201 chown $DCCUID $DCC_RUNDIR | |
202 fi | |
203 if @DCC_SU@ $DCCUID -c date >/dev/null 2>&1; then | |
204 @DCC_SU@ $DCCUID -c "$DCC_LIBEXEC/$ARGV0 $DCCM_ARGS" | |
205 exit | |
206 fi | |
207 DCCM_ARGS="-I$DCCUID $DCCM_ARGS" | |
208 fi | |
209 eval $DCC_LIBEXEC/$ARGV0 $DCCM_ARGS |