2 # fixscript will replace this line with code to load innshellvars
5 ## Watch the state of the system relative to the news subsystem.
6 ## As controlled by the control file, when space or inodes are almost
7 ## exhausted innd is throttled, or paused, similarly if the load is
8 ## too high - when conditions revert to normal, innd is restarted.
9 ## No logging is done here, watch for syslog reports from innd.
10 ## Written by Mike Cooper <mcooper@usc.edu>.
11 ## Extensively modified by <kre@munnari.oz.au>.
12 ## Watch a log file and send mail when it gets new output by
13 ## Steve Groom <stevo@elroy.Jpl.Nasa.Gov>
14 ## Steve's extensions merged in innwatch by
15 ## <Christophe.Wolfhugel@grasp.insa-lyon.fr>
18 LOCK=${LOCKS}/LOCK.${PROGNAME}
19 DAILY=${LOCKS}/LOCK.news.daily
20 ## Where to put the timestamp file (directory and filename).
21 TIMESTAMP=${LOCKS}/${PROGNAME}.time
23 ## Logfile to watch. Comment out if no logwatch.
24 LOGFILE=${MOST_LOGS}/news.crit
26 ## Default value in case there is no definition in inn.conf
27 : ${INNWATCHPAUSELOAD:=1500}
28 : ${INNWATCHHILOAD:=2000}
29 : ${INNWATCHLOLOAD:=1000}
30 : ${INNWATCHSPOOLSPACE:=8000}
31 : ${INNWATCHBATCHSPACE:=800}
32 : ${INNWATCHLIBSPACE:=25000}
33 : ${INNWATCHSPOOLNODES:=200}
34 : ${INNWATCHSLEEPTIME:=600}
37 while [ $# -gt 0 ] ; do
44 FILE=`expr "$1" : '-s\(.*\)'`
51 LOGFILE=`expr "$1" : '-s\(.*\)'`
58 INNWATCHSLEEPTIME=`expr "$1" : '-t\(.*\)'`
65 echo "${PROGNAME}: Unknown flag $1" 1>&2
76 if [ $# -ne 0 ] ; then
77 echo "Usage: ${PROGNAME} [flags]" 1>&2
84 shlock -p $$ -f ${LOCK} || {
85 echo "${PROGNAME}: [$$] locked by [`cat ${LOCK}`]"
89 trap 'rm -f ${LOCK} ${WATCHPID} ; exit 1' 1 3 15
90 echo "$$" > ${WATCHPID}
92 ## The reason why we turned INND off, and its, and our current state.
98 echo "${PROGNAME} waiting for INND to start (pid: $$)"
102 ## We need to remember the process ID of innd, in case one exits
103 ## But we need to wait for innd to start before we can do that
104 while PID=`cat ${SERVERPID} 2>/dev/null`; test -z "${PID}"; do
105 sleep ${INNWATCHSLEEPTIME}
109 if [ -z "${STATE}" ]; then
110 echo "${PROGNAME} state RUN interval ${INNWATCHSLEEPTIME} pid $$"
112 echo "${PROGNAME} state ${STATE} interval ${INNWATCHSLEEPTIME} pid $$"
114 if [ -z "${INND}" ]; then
119 test -n "${REASON}" && X="${X}: ${REASON}"
120 echo "INND state ${X}"
129 while { sleep ${NEXTSLEEP} & wait; } ; : ; do
130 NEXTSLEEP=${INNWATCHSLEEPTIME}
132 ## If news.daily is running, idle: we don't want to change the
133 ## status of anything while news.daily may be depending on what we
135 test -f "${DAILY}" && continue
137 ## Check to see if INND is running.
138 ## Notify NEWSMASTER if it has stopped or just restarted.
139 if ctlinnd -s -t 120 mode 2>/dev/null ; then
142 ${MAILCMD} -s "INND is now running" ${NEWSMASTER} </dev/null
147 ${MAILCMD} -s "INND is NOT running" ${NEWSMASTER} </dev/null
152 ## If innd has exited & restarted, put the new one into the
153 ## same state the old one was in
155 nPID=`cat ${SERVERPID} 2>/dev/null`
156 test -n "${nPID}" -a "${PID}" -ne "${nPID}" && {
157 test -n "${INND}" -a "${INND}" != go && ctlinnd -s "${INND}" "${REASON}"
169 LINE=`expr ${LINE} + 1`
170 test -z "$line" && continue
172 ## The first character on the line is the field delimiter,
173 ## except '#' which marks the line as a comment
174 delim=`expr "${line}" : '\(.\).*'`
175 test "X${delim}" = 'X#' && continue
177 ## Parse the line into seven fields, and assign them to local vars.
178 ## You're welcome to work out what's going on with quoting in
179 ## the next few lines if you feel inclined.
180 eval `trap '' 2; echo "${line}" \
181 | ${SED} -e "s/'/'\"'\"'/g" \
182 -e "s/[ ]*\\\\${delim}[ ]*/\\\\${delim}/g" \
183 | ${AWK} -F"${delim}" '{ print "LAB='"'"'" $2 "'"'"'", \
184 "CND='"'"'" $3 "'"'"'", \
185 "EXP='"'"'" $4 "'"'"'", \
186 "TST='"'"'" $5 "'"'"'", \
188 "CMD='"'"'" $7 "'"'"'", \
189 "CMT='"'"'" $8 "'"'"'" }'`
191 ## If there's no label, the label is the line number.
192 test -z "${LAB}" && LAB=${LINE}
194 ## Should we act on this line? We will if one (or more) of the
195 ## specified conditions is satisfied.
196 for X in a b; do # meaningless trash because we have no goto
197 if [ -z "${CND}" ]; then
202 set -$- X ${X}; shift
207 test -n "${STATE}" -a "X${STATE}" != "X${LAB}" && continue
210 test -n "${STATE}" && continue
215 test "X-${STATE}" = "X${cnd}" && continue
218 test "X${STATE}" != "X${cnd}" && continue;
221 break 2; # OK, continue with this line
223 continue 2; # No, skip it.
226 ## Evaluate the expression, if there is one, and if that works.
227 if [ -z "${EXP}" -o "${EXP}" = "${PREVEXP}" ] \
228 || { PREVEXP="${EXP}"; VALUE=`trap '' 2;eval "${EXP}"`; }; then
229 ## If innd is running, and test "succeeds", stop it.
239 if [ \( -z "${STATE}" -o "${STATE}" != "${LAB}" -o "${OK}" = y \) \
240 -a "${VALUE}" "-${TST}" "${LIM}" ] ; then
241 R="${CMT} [${PROGNAME}:${LAB}] ${VALUE} ${TST} ${LIM}"
281 ctlinnd -s "${CMD}" "${ARG}" && STATE="${O}" && INND="${CMD}"
284 ## Otherwise, if innd is not running, and reverse test succeeds
286 elif [ "${STATE}" = "${LAB}" -a \
287 \( "${CMD}" = "throttle" -o "${CMD}" = pause \) -a \
288 ! "${VALUE}" "-${TST}" "${LIM}" ] ; then
289 ctlinnd -s go "${REASON}"
294 ## If we have started innd, run all tests again quickly in
295 ## case there is some other condition that should stop it.
306 if [ -n "${LOGFILE}" -a -f "${LOGFILE}" ]; then
307 if [ ! -f ${TIMESTAMP} ]; then
310 # use ls to print most recently modified file first.
311 # If that's ${LOGFILE}, it's changed since the last pass.
312 DOIT="`ls -t ${TIMESTAMP} ${LOGFILE} | ${SED} -e 1q | grep ${LOGFILE}`"
315 # If the file has been modified more recently than the timestamp,
316 # and the file has length greater than 0, send the warning.
317 if [ -n "${DOIT}" -a -s ${LOGFILE} ]; then
326 | sed -e 's/^~/~~/' \
327 | ${MAILCMD} -s "${PROGNAME} warning: messages in ${LOGFILE}" \