2 # fixscript will replace this line with code to load innshellvars
4 # @(#) $Id: actsyncd.in 6490 2003-10-18 05:49:04Z rra $
5 # @(#) Under RCS control in /usr/local/news/src/inn/local/RCS/actsyncd.sh,v
7 # actsyncd - actsync daemon
10 # actsyncd [-x] config_file [debug_level [debug_outfmt]]
12 # -x xexec instead of reload
13 # config_file name of file used to determine how to run actsync
14 # debug_level force no action and use -v debug_level
15 # debug_outfmt change -o a1 output to -o debug_outfmt for debug
17 # By: Landon Curt Noll chongo@toad.com (chongo was here /\../\)
19 # Copyright (c) Landon Curt Noll, 1993.
20 # All rights reserved.
22 # Permission to use and modify is hereby granted so long as this
23 # notice remains. Use at your own risk. No warranty is implied.
29 LOCK="${LOCKS}/LOCK.actsyncd"
30 # where actsync is located
31 ACTSYNC="${PATHBIN}/actsync"
32 # exit value of actsync if unable to get an active file
39 -x|-r) shift ;; # no longer relevant
43 1) cfg="$1"; DEBUG=; DEBUG_FMT=; ;;
44 2) cfg="$1"; DEBUG="$2"; DEBUG_FMT=; ;;
45 3) cfg="$1"; DEBUG="$2"; DEBUG_FMT="$3"; ;;
46 *) echo "usage: $0 [-x] config_file [debug_level [debug_outfmt]]" 1>&2;
49 if [ ! -s "$cfg" ]; then
50 echo "$0: config_file not found or empty: $ign" 1>&2
56 host="`sed -n -e 's/^host=[ ]*//p' $cfg | tail -1`"
57 if [ -z "$host" ]; then
58 echo "$0: no host specified in $cfg" 1>&2
61 flags="`sed -n -e 's/^flags=[ ]*//p' $cfg | tail -1`"
62 if [ -z "$flags" ]; then
63 echo "$0: no flags specified in $cfg" 1>&2
66 ign="`sed -n -e 's/^ignore_file=[ ]*//p' $cfg | tail -1`"
67 if [ -z "$ign" ]; then
68 echo "$0: no ignore file specified in $cfg" 1>&2
71 ftp="`sed -n -e 's/^ftppath=[ ]*//p' $cfg | tail -1`"
72 spool="`sed -n -e 's/^spool=[ ]*//p' $cfg | tail -1`"
73 if [ -z "$spool" ]; then
75 #echo "$0: no spool directory specified in $cfg" 1>&2
78 if [ ! -f "$ign" ]; then
81 if [ ! -s "$ign" ]; then
82 echo "$0: ignore_file not found or empty: $ign" 1>&2
86 # force -o c mode (overrides any -o argument in the command line)
88 if [ -z "$DEBUG" ]; then
90 # standard actsyncd output mode
93 # DEBUG processing, if debug_level was given
97 if [ ! -z "$ftp" ]; then
98 echo "$0: cannot use DEBUG mode with ftp (yet)" >&2
102 # force -v level as needed
103 flags="$flags -v $DEBUG"
105 # force -o level but reject -o x modes
106 if [ ! -z "$DEBUG_FMT" ]; then
108 x*) echo "$0: do not use any of the -o x debug_outfmt modes!" 1>&2;
110 *) flags="$flags -o $DEBUG_FMT" ;;
114 # execute actsync directly
115 echo "DEBUG: will execute $ACTSYNC -i $ign $flags $host" 1>&2
116 eval "$ACTSYNC -i $ign $flags $host"
118 echo "DEBUG: exit status $status" 1>&2
124 shlock -p $$ -f "${LOCK}" || {
125 echo "$0: Locked by `cat '${LOCK}'`" 1>&2
132 workdir="${TMPDIR}/actsyncd"
133 ctlinndcmds="cc_commands"
135 cleanup="$SED -e 's/^/ /' < $out; cd ${origdir}; rm -rf '$workdir' '$LOCK'"
136 trap "eval $cleanup; exit 123" 1 2 3 15
150 # Try to sync off of the host. If unable to connect/sync then retry
151 # up to 9 more times waiting 6 minutes between each try.
153 echo "=-= `date` for $host" >>$out 2>&1
154 for loop in 1 2 3 4 5 6 7 8 9 10; do
156 # get the active file to compare against
159 /*) cp $host active; status=$? ;;
160 .*) cp $origdir/$host active; status=$? ;;
162 if [ -z "$ftp" ]; then
163 port=`expr "$host" : '.*:\(.*\)'`
164 if [ -n "$port" ]; then
166 host=`expr "$host" : '\(.*\):.*'`
168 echo "getlist -h $host $port" >>$out
169 if getlist -h $host $port > active 2>>$out; then
175 echo "$GETFTP ftp://$host/$ftp" >>$out
176 $GETFTP ftp://$host/$ftp >>$out 2>&1
178 if [ "$status" -ne 0 ]; then
183 echo "$GZIP -d active" >>$out
184 if $GZIP -d active >>$out 2>&1; then
191 echo "$UNCOMPRESS active" >>$out
192 if $UNCOMPRESS active >>$out 2>&1; then
204 if [ "$status" -ne "$NOSYNC" ]; then
208 if [ "$status" -ne 0 ]; then
209 echo "FATAL: `date` for $host exit $status" >>$out
214 echo "$ACTSYNC -i $ign $flags ./active" >>$out
215 eval "$ACTSYNC -i $ign $flags ./active >$ctlinndcmds 2>>$out"
217 if [ $? -ne 0 ]; then
218 echo "FATAL: `date` for $host actsync balked" >>$out
223 if [ ! -s $ctlinndcmds ]; then
224 echo "No changes need to be made" >>$out
226 echo "=-= `date` for $host, updating active" >>$out
227 echo "mod-active $ctlinndcmds" >>$out
228 mod-active $ctlinndcmds >>$out 2>&1
230 if [ $? -ne 0 ]; then
231 echo "FATAL: `date` for $host mod-active FAILED" >>$out
237 # normal exit - all done
239 echo "=-= `date` for $host, end" >>$out
244 # failed to get the remote active file
245 echo "=-= `date` for $host failed to connect/sync, retrying" >>$out
254 echo "FATAL: `date` for $host failed to connect/sync 10 times" >>$out 2>&1