1 #!/usr/bin/rc -p 2 # ===================================================================== 3 # queue-run: run a number of TW batch operations. 4 # 5 # Copyright (c) 2007,2008,2009,2010 Carlo Strozzi 6 # 7 # This program is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; version 2 dated June, 1991. 10 # 11 # This program is distributed in the hope that it will be useful, 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 # GNU General Public License for more details. 15 # 16 # You should have received a copy of the GNU General Public License 17 # along with this program; if not, write to the Free Software 18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 # 20 # ===================================================================== 21 22 # ===================================================================== 23 # Program initialization 24 # ===================================================================== 25 26 CSA_PGM = ($CSA_PGM `{basename $0}) 27 if (~ $CSA ()) { 28 echo $CSA_PGM($#CSA_PGM)^:' $CSA not set, cannot continue' >[1=2] 29 exit 1 30 } 31 32 . $CSA || exit 1 33 34 # Even if $CSA exists and parses correctly it may not be what I expect. 35 # So the purpose of the first csaPrintMsg() is twofold: it tells that 36 # the program has started and causes it to exit if the function is 37 # undefined. 38 39 csaPrintMsg 0060 $CSA_PGM($#CSA_PGM) || exit $status 40 41 # ===================================================================== 42 # Local variables and functions 43 # ===================================================================== 44 45 # NONE 46 47 # ===================================================================== 48 # Main program 49 # ===================================================================== 50 51 cd $CSA_ROOT/var || csaExit.fault 0033 $CSA_ROOT/var 52 53 ~ $1 () && * = pingback # compatibility default 54 55 # Prevent multiple instances of this program from overlapping. 56 # This program may take a while to complete, so no PLS must be 57 # done by the TW program that write to this queue, not to have 58 # them hanging or exit with timeout errors. Furthermore, it 59 # is probably wise NOT to use 'csaLock' here, as we want to take 60 # as much time as needed, without any timeouts from either old(1) 61 # or a dot-locking program, but we do not want to be stopped by 62 # any stale locks either. 63 64 #csaLock $CSA_ROOT/var/tw-pingback-queue || csaExit.fault 65 swu-shlock -f $CSA_ROOT/var/tw-pingback-queue.lock -p $pid || 66 csaExit.fault 0007 $status $CSA_ROOT/var/tw-pingback-queue 67 68 csaTrapFile $CSA_ROOT/var/tw-pingback-queue.lock 69 70 switch ($1) { 71 72 case pingback 73 74 # Quit silently if nothing to do. 75 csaIsFullPath --quiet --exists $CSA_ROOT/var/tw-pingback-queue || 76 csaExit 0 77 # This is necessary both to flush the input queue and 78 # to do without PLS. Note that I do not test for errors from 79 # either mv(1) or cat(1) below, not to exit if there's nothing 80 # new to do but there may still be a tw-pingback-queue.rc from 81 # a previous run that had failed. 82 83 mv tw-pingback-queue tw-pingback-queue.tmp 84 85 # Wait for web processes to flush any data to tw-pingback-queue.tmp . 86 sleep 5 87 88 # Append new stuff to the old work file, as if it is still there 89 # is means that the previous pingback batch did not complete and we 90 # are going to retry it now. 91 92 cat tw-pingback-queue.tmp >> tw-pingback-queue.rc 93 94 rc -x tw-pingback-queue.rc >> log/tw-pingback-queue.log >[2=1] || 95 csaExit.fault 0003 tw-pingback-queue.rc 96 97 rm -f tw-pingback-queue.rc || csaExit.fault 0003 rm 98 99 case notify-page-updates 100 101 csaAwkCmd notifyUpdates.awk 102 103 # Take each tw-page-updated- and process it in turn, 104 # making sure that any tw-page-updated-*.tmp files are skipped. 105 106 for (i in tw-page-updated-[1-9]*[0-9]) { 107 108 ~ $i *'*'* && break # no expansion means nothing to do 109 110 # This is necessary both to flush the input queue 111 # and to do without PLS. 112 mv $i $i.tmp || csaExit.fault 0003 mv 113 114 # Wait for web processes to flush any data 115 # to tw-page-updated- . 116 sleep 5 117 118 $CSA_RESULT -- $i.tmp || csaExit.fault 0003 AWK 119 120 echo -n $CSA_TIME_LOG $i' ' >> $CSA_LOGDIR/tw-notify.log 121 head -n 1 $i.tmp >> $CSA_LOGDIR/tw-notify.log 122 123 rm -f $i.tmp || csaExit.fault 0003 rm 124 } 125 126 case notify-thread-updates 127 128 csaAwkCmd notifyUpdates.awk 129 130 # Take each tw-thread-updated- and process it in turn, 131 # making sure that any tw-thread-updated-*.tmp files are skipped. 132 133 for (i in tw-thread-updated-[1-9]*[0-9]) { 134 135 ~ $i *'*'* && break # no expansion means nothing to do 136 137 # This is necessary both to flush the input queue 138 # and to do without PLS. 139 mv $i $i.tmp || csaExit.fault 0003 mv 140 141 # Wait for web processes to flush any data 142 # to tw-thread-updated- . 143 sleep 5 144 145 $CSA_RESULT -- $i.tmp || csaExit.fault 0003 AWK 146 147 echo -n $CSA_TIME_LOG $i' ' >> $CSA_LOGDIR/tw-notify.log 148 head -n 1 $i.tmp >> $CSA_LOGDIR/tw-notify.log 149 150 rm -f $i.tmp || csaExit.fault 0003 rm 151 } 152 } 153 154 csaExit.ok # mandatory ! 155 156 # End of program.