You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@forrest.apache.org by je...@apache.org on 2002/12/07 10:22:00 UTC
cvs commit: xml-forrest/src/resources/forrestbot/scripts README.txt launch-overseer local-vars local-vars-cocoondev.org overseer refresh refresh_all update_livesite
jefft 2002/12/07 01:22:00
Added: src/resources/forrestbot/scripts README.txt launch-overseer
local-vars local-vars-cocoondev.org overseer
refresh refresh_all update_livesite
Log:
Shell scripts providing the necessary wrapper around the forrestbot to allow it
to be run from a webapp or cron
Revision Changes Path
1.1 xml-forrest/src/resources/forrestbot/scripts/README.txt
Index: README.txt
===================================================================
Forrestbot Scripts
jefft@apache.org
$Revision: 1.1 $ $Date: 2002/12/07 09:21:59 $
------------------------
This directory contains shell scripts for using the Forrestbot to generate
multiple sites. Contents are as follows:
overseer # A driver script which is used with the webapp. Invokes 'refresh' and 'update_livesite'
refresh # Main driver script. Refreshes a single site via a forrestbot script
refresh_all # Convenience wrapper for 'refresh' which regens all sites. Suitable for cron use
local-vars # Script defining local variables, with defaults. Frontend to local-vars-`uname -n`
local-vars-`uname -n` # Script containing local variable definitions. MUST BE DEFINED FOR YOUR SITE
update_livesite # WIP script to commit files to the Apache xml-site/targets/forrest module
work/ # Runtime-generated directory containing forrestbot files
In summary, if you obtain this from CVS and wish to use it locally, you must:
- Create a file defining local variables, called local-vars-<name>, where
<name> is output from `uname -n`. See local-vars-cocoondev.org for an example.
In addition, to run the 'update_livesite' scripts you need to install the
cvsutils scripts (http://www.red-bean.com/cvsutils/) and have them in your
PATH. This _may_ also be a requirement for the other scripts: check for
'cvsco' usage in 'common-scripts'.
--Jeff
1.1 xml-forrest/src/resources/forrestbot/scripts/launch-overseer
Index: launch-overseer
===================================================================
#!/bin/sh
# Convenience script for running 'overseer' from the console and watching the
# output.
. `dirname $0`/local-vars
./overseer < $WEBAPP/WEB-INF/commands > overseer.log &
echo overseer pid: $!
tail -f $WEBAPP/WEB-INF/refresh_log.txt overseer.log
1.1 xml-forrest/src/resources/forrestbot/scripts/local-vars
Index: local-vars
===================================================================
#!/bin/sh
LOCAL_VARS=`dirname $0`/local-vars-`uname -n`
if [ ! -f "$LOCAL_VARS" ]; then
echo "Please create a file local-vars-`uname -n` containing local variable definitions"
exit
fi
. $LOCAL_VARS
# Defaults
[ -z "$BASE" ] && BASE=.
[ -z "$WEBAPP" ] && WEBAPP=$BASE/../webapp
[ -z "$TIMEOUT" ] && TIMEOUT=$[20*60]
echo BASE=$BASE
echo WEBAPP=$WEBAPP
1.1 xml-forrest/src/resources/forrestbot/scripts/local-vars-cocoondev.org
Index: local-vars-cocoondev.org
===================================================================
# Env variables specific to cocoondev
export JAVA_HOME=/usr/jdk1.3.1_03
# BASE *must* be declared
BASE=/home/j/jeffturner/forrestbot
WEBAPP=/www/forrestbot.cocoondev.org/webapps/ROOT
XML_SITE=/home/j/jeffturner/xml-site
TIMEOUT=$[10*60]
1.1 xml-forrest/src/resources/forrestbot/scripts/overseer
Index: overseer
===================================================================
#!/bin/sh
# Script to process commands generated by the webapp
# It listens on stdin for single-line commands of the form:
# <action> <module>
# Eg 'refresh xml-site', 'upload xml-forrest'
. `dirname $0`/local-vars
# If you change this, remember to change it in the JSP too
REFRESH_LOG=$WEBAPP/WEB-INF/refresh_log.txt
function lookup_script()
{
echo $1-cvs.xml
}
function refresh()
{
echo "Refreshing $module"
$BASE/refresh `lookup_script $module` >> $REFRESH_LOG 2>&1
}
function upload()
{
echo "Upload $module"
$BASE/update_livesite $module >> $REFRESH_LOG 2>&1
}
IGNOREEOF=1
while true; do
read action module
case $action in
refresh)
refresh $module
;;
upload)
upload $module
;;
quit) exit
;;
'') sleep 1 ;;
*)
echo "Unknown command '$action'"
echo "Available commands are 'refresh', 'upload'."
;;
esac
done
1.1 xml-forrest/src/resources/forrestbot/scripts/refresh
Index: refresh
===================================================================
#!/bin/sh
# Regenerate a site's HTML with the forrestbot.
SCRIPT=${1}
[ -z "$SCRIPT" ] && echo >&2 "Usage: $0 <forrestbot script>" && exit 1
. `dirname $0`/local-vars
# default 20 minute timeout.
export CVS_RSH=ssh
export PATH=$JAVA_HOME/bin:$PATH
# Leaving EMAIL blank causes no email to be sent
TSTAMP=`date +%Y-%m-%d-%k-%M`
EMAIL=
LOGS=$WEBAPP/logs
DEST_DIR=$WEBAPP/sites
PATH=$PATH:$HOME/apps/bin
# Assume we're in the xml-forrest/src/resources/forrestbot/scripts
FORREST=$BASE/../../../../
# Set this to true if you want to delete any local mods to the $FORREST and
# update from CVS. Not recommended unless scripts/ is moved outside the
# xml-forrest CVS hierarchy
REGEN_FORREST=false
# Set to true to delete the work/ directory, which contains forrestbot-checked
# out CVS source. Setting to false is faster, but less safe
REGEN_WORK=true
FORRESTBOT_SCRIPTS=$FORREST/src/resources/forrestbot/samples
SHBAT=$BASE/shbat
WORK=$BASE/work
function setup()
{
if [ ! -d $FORREST ]; then
echo "$FORREST not present"
exit
fi
}
function rebuild_forrest()
{
pushd .
[ -d "$SHBAT" -a -e "$SHBAT/forrest.build.xml" ] && rm -r $SHBAT
cd $FORREST
# see www.red-bean.com/cvsutils
if [ "$REGEN_FORREST" = "true" -a `which cvsco` ]; then
cvsco
cvs up -dP
fi
./build.sh -Ddist-shbat.dir=$SHBAT
popd
}
function prepare_workdir()
{
pushd .
[ "$REGEN_WORK" = "true" -a -d "$WORK" ] && rm -r $WORK
if [ ! -d $WORK ]; then
mkdir $WORK && cd $WORK
cp -r $FORRESTBOT_SCRIPTS/* $WORK
fi
cd $WORK
[ -d build/bot ] && rm build/bot/work*.log
perl -i -pe "s:<!ENTITY email.*>:<!ENTITY email \"$EMAIL\">:g" $SCRIPT
perl -i -pe "s:<!ENTITY dest.*>:<!ENTITY dest \"$DEST_DIR\">:g" $SCRIPT
popd
}
function forrestbot()
{
cd $WORK
$SHBAT/bin/forrestbot -Dbot.config=$SCRIPT &
cmdpid=$!
# Start "watchdog" process to terminate the command
# after $timeout seconds:
( sleep $TIMEOUT; echo "Forrestbot timed out after $TIMEOUT seconds" ;
kill $cmdpid && (sleep 2; kill -1 $cmdpid) &&
(sleep 2; kill -9 $cmdpid)
) &
watchdogpid=$!
wait $cmdpid # wait for command
kill $watchdogpid >/dev/null 2>&1
}
function copy_logs()
{
mkdir -p $LOGS/old
for i in $WORK/build/bot/work*.log; do
cp $i $LOGS
cp $i $LOGS/old/`basename $i`-$TSTAMP
done
echo "Copied logs"
}
echo Running script $SCRIPT
setup
rebuild_forrest
prepare_workdir
forrestbot
copy_logs
1.1 xml-forrest/src/resources/forrestbot/scripts/refresh_all
Index: refresh_all
===================================================================
#!/bin/sh
. `dirname $0`/refresh forrestbot.conf.xml
1.1 xml-forrest/src/resources/forrestbot/scripts/update_livesite
Index: update_livesite
===================================================================
#!/bin/sh
MODULE=${1:-xml-forrest}
case $MODULE in
xml-forrest) TARGET="forrest" ;;
esac
[ -z "$TARGET" ] && echo "Unknown module: $MODULE" && exit;
. `dirname $0`/local-vars
if [ -z "$XML_SITE" ]; then
echo "Please set the XML_SITE var in local-vars-`uname -n`"
exit
fi
LIVECVS=$XML_SITE/targets/$TARGET
SRC_DIR=$BASE/webapp/sites/$MODULE
echo "Updating $LIVECVS from $SRC_DIR"
pushd .
cd $LIVECVS
cvsco
cvs up -dP
echo "Now copying $SRC_DIR/*"
cp -r -p $SRC_DIR/* .
echo "done"
NEW_FILES=`cvs up | grep '^\?' | cut -d\ -f 2`
for i in $NEW_FILES; do
MIME=`file -bi $i`
echo "New file $i has MIME type $MIME"
if [ `echo "$MIME" | grep -q 'text'` ]; then
echo "Adding $i as text"
cvsdo add $i
else
echo "Adding $i as binary"
cvs add -kb $i
fi
done
cvs up > /tmp/cvslist 2>&1
cvs ci -m "Automatic update at `date` by forrestrunner."
#cvs ci
popd
# still testing