chiark / gitweb /
some fixes; debug for missing
[inn-innduct.git] / control / controlbatch.in
1 #! /bin/sh
2 # fixscript will replace this line with code to load innshellvars
3
4 ########################################################################
5 # controlbatch - Run controlchan against a batch file.
6 #
7 # Command usage:  controlbatch [feedsite batchfile]
8 # Defaults are feedsite: controlchan!, batchfile: ${BATCH}/controlchan!
9 ########################################################################
10 #
11 # This script will run controlchan against a batch file.  You can use
12 # it to clear occasional backlogs while running controls from a
13 # channel, or even skip the channel and run control messages as a file
14 # feed.
15 #
16 ########################################################################
17 #
18 # If you're doing the channel thing, you might want to put something
19 # like this in your crontab to do a cleanup in the wee hours:
20 #
21 #       00 04 * * *     @prefix@/bin/controlbatch
22 #
23 ########################################################################
24 #
25 # If you would rather skip the channel and just process controls each
26 # hour in a batch, use this newsfeeds entry instead of the "stock"
27 # version:
28 #
29 # controlchan!\
30 #       :!*,control,control.*,!control.cancel\
31 #       :Tf,Wnsm:
32 #
33 # And, a crontab entry something like this:
34 #
35 #       30 * * * *     @prefix@/bin/controlbatch
36 #
37 ########################################################################
38
39 batchlock="${LOCKS}/LOCK.controlbatch"
40 mypid=$$
41
42 # A concession to INN 1.x
43 if [ me${PATHBIN}ow = meow ] ; then
44         PATHBIN=${NEWSBIN}
45         export PATHBIN
46 fi
47
48 # See if we have no arguments and should use the defaults. If there are
49 # arguments, make sure we have enough to attempt something useful.
50 if [ me${1}ow != meow ] ; then
51         if [ me${2}ow = meow ] ; then
52                 echo "Usage: ${0} [feedsite batchfile]" >&2
53                 exit 0
54         else
55                 feedsite=${1}
56                 batchfile=${2}
57         fi
58 else
59         feedsite=controlchan\!
60         batchfile=controlchan\!
61 fi
62
63 # Check if any other copies of controlbatch are running.  If we are not
64 # alone, give up here and now.
65 ${PATHBIN}/shlock -p $mypid -f ${batchlock} || exit 0
66
67 cd ${BATCH}
68
69 if [ -s ${batchfile}.work ] ; then
70         cat ${batchfile}.work >>${batchfile}.doit
71         rm -f ${batchfile}.work
72 fi
73
74 if [ -s ${batchfile} ] ; then
75         mv ${batchfile} ${batchfile}.work
76         if ${PATHBIN}/ctlinnd -s -t30 flush ${feedsite} ; then
77                 cat ${batchfile}.work >>${batchfile}.doit
78                 rm -f ${batchfile}.work
79         fi
80 fi
81
82 if [ -s ${batchfile}.doit ] ; then
83         ${PATHBIN}/controlchan \
84                 < ${batchfile}.doit >> ${MOST_LOGS}/controlbatch.log 2>&1
85         # if you want extra assurance that nothing gets lost...
86         # cat ${batchfile}.doit >> ${batchfile}.done
87         rm -f ${batchfile}.doit
88 fi
89
90 rm -f ${batchlock}