Changed the requires file to take 'before' and 'after' parameters to declare forward and backward dependencies. Declaring 'before' will FORCE the listed module to be installed along with this one. See the docs.

This commit is contained in:
2012-08-23 21:32:27 -04:00
parent 68c32cadf3
commit 86b19b9743
5 changed files with 84 additions and 18 deletions

0
balls/entities/requires Normal file
View File

View File

@@ -1 +1,2 @@
entities after entities
before users

View File

@@ -1,2 +1 @@
entities after entities
groups

View File

@@ -47,22 +47,39 @@ function dance() {
exit 1 exit 1
fi fi
# Create the toposort of all the modules # Create the toposort of all the modules and fetch all their metadata
for module in $(disco-param keys $(hostname)/modules) # This also includes fetching modules that aren't explicitly called out in
do # our class list, but are required by 'before' statements in the requires files.
NOOP="true" disco-ball fetch $module rm -f /tmp/$$.tsort
disco-ball requires $module >> /tmp/$$.tsort disco-param keys $(hostname)/modules | tac > /tmp/$$.modules.prev
NEWBALLS=$(cat /tmp/$$.modules.prev)
while [ "$NEWBALLS" != "" ]; do
for module in $NEWBALLS
do
NOOP="true" disco-ball fetch $module
disco-ball requires $module >> /tmp/$$.tsort
cat /tmp/$$.tsort | tsort | tac > /tmp/$$.modules.new
done
NEWBALLS=$(diff /tmp/$$.modules.prev /tmp/$$.modules.new | grep "^> " | cut -d " " -f 2-)
cp /tmp/$$.modules.new /tmp/$$.modules.prev
if [ "$NEWBALLS" != "" ]; then
echo "info: Discovered dependency : ${module} : $(echo -n ${NEWBALLS} | sed s/' '/', '/g)"
fi
done done
for module in $(cat /tmp/$$.tsort | tsort | tac) echo "info: Ready to dance :"
do cat /tmp/$$.tsort | tsort | tac | sed s/"^"/"info: "/g
disco-ball spin ${module}
done # for module in $(cat /tmp/$$.tsort | tsort | tac)
# do
# disco-ball spin ${module}
# done
if [ "$REPORT" != "" ]; then if [ "$REPORT" != "" ]; then
report report
fi fi
#rm -f /tmp/$$.*
} }
$1 "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" $1 "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"

View File

@@ -31,38 +31,86 @@ function fetch_params() {
return $RETVAL return $RETVAL
} }
function params() {
if [ "$1" == "" ]; then
echo "Must pass a module name to fetch data for"
return 1
fi
mkdir -p ${DISCOROOT}/reports/$1
rm -f ${DISCOROOT}/reports/${1}/params
/usr/bin/time -f "$TIME" -o ${DISCOROOT}/reports/$1/params \
rsync -aWH ${STORAGE}/parameters/* ${DISCOROOT}/parameters/$(hostname)/
return $?
}
function fetch() { function fetch() {
if [ "$1" == "" ]; then if [ "$1" == "" ]; then
echo "Must pass a module name to fetch" echo "Must pass a module name to fetch data for"
return 1 return 1
fi fi
SRC="${SERVERURI}::${1}"
if [ "$2" != "" ]; then
SRC="$2"
fi
if [ "$NOOP" == "" ]; then if [ "$NOOP" == "" ]; then
DEST=/var/disco/testfs/real/scratchfs DEST=/var/disco/testfs/real/scratchfs
else else
DEST=/var/disco/testfs/noop/scratchfs DEST=/var/disco/testfs/noop/scratchfs
fi fi
rm -rf ${STORAGE}/${1} rm -rf ${STORAGE}/${1}
mkdir -p ${DISCOROOT}/reports/$1 mkdir -p ${DISCOROOT}/reports/$1
rm -f ${DISCOROOT}/reports/${1}/fetch rm -f ${DISCOROOT}/reports/${1}/fetch
# Sometimes there's some shell escaping voodoo and rsync doesn't like the command args some people will pass it straight on # Sometimes there's some shell escaping voodoo and rsync doesn't like the command args some people will pass it straight on
# the command line; so we wrap it in a little bash script, and everyone's happy. # the command line; so we wrap it in a little bash script, and everyone's happy.
echo ${RSYNC} ${SERVERURI}::${1}/files/* ${DEST} > /tmp/$$.sh echo ${RSYNC} --delete ${SRC}/requires ${SRC}/scripts ${SRC}/parameters ${SRC}/templates ${STORAGE}/${1} > /tmp/$$.sh
echo ${RSYNC} --delete ${SERVERURI}::${1}/requires ${SERVERURI}::${1}/scripts ${SERVERURI}::${1}/parameters ${SERVERURI}::${1}/templates ${STORAGE}/${1} >> /tmp/$$.sh
echo 'exit $?' >> /tmp/$$.sh echo 'exit $?' >> /tmp/$$.sh
/usr/bin/time -f "$TIME" -o ${DISCOROOT}/reports/${1}/fetch /tmp/$$.sh 2>/tmp/$$.errors | sed s/"^"/"info: ${1}: "/g /usr/bin/time -f "$TIME" -o ${DISCOROOT}/reports/${1}/fetch /bin/bash /tmp/$$.sh 2>/tmp/$$.errors | sed s/"^"/"info: ${1}: "/g
cat /tmp/$$.errors | grep -v "some files/attrs were not transferred" | sed s/"^"/"error: ${1}: "/g cat /tmp/$$.errors | grep -v "some files/attrs were not transferred" | sed s/"^"/"error: ${1}: "/g
RETVAL=$? RETVAL=$?
rm -f /tmp/$$.sh rm -f /tmp/$$.sh
return $RETVAL return $RETVAL
} }
function files() {
if [ "$1" == "" ]; then
echo "Must pass a module name to retrieve files for"
return 1
fi
SRC="${SERVERURI}::${1}"
if [ "$2" != "" ]; then
SRC="$2"
fi
if [ "$NOOP" == "" ]; then
DEST=/var/disco/testfs/real/scratchfs
else
DEST=/var/disco/testfs/noop/scratchfs
fi
mkdir -p ${DISCOROOT}/reports/$1
rm -f ${DISCOROOT}/reports/${1}/files
# Sometimes there's some shell escaping voodoo and rsync doesn't like the command args some people will pass it straight on
# the command line; so we wrap it in a little bash script, and everyone's happy.
echo ${RSYNC} ${SRC}/files/* ${DEST} > /tmp/$$.sh
echo 'exit $?' >> /tmp/$$.sh
/usr/bin/time -f "$TIME" -o ${DISCOROOT}/reports/${1}/files /bin/bash /tmp/$$.sh 2>/tmp/$$.errors | sed s/"^"/"info: ${1}: "/g
cat /tmp/$$.errors | grep -v "some files/attrs were not transferred" | sed s/"^"/"error: ${1}: "/g
RETVAL=$?
rm -f /tmp/$$.sh
return $RETVAL
}
function requires() function requires()
{ {
if [ "$1" == "" ]; then if [ "$1" == "" ]; then
echo "Must pass a module name for requirements" echo "Must pass a module name for requirements"
return 1 return 1
fi fi
cat ${STORAGE}/${1}/requires | sed s/"^"/"${1} "/g cat ${STORAGE}/${1}/requires 2>/dev/null |\
grep -v "^#" |\
sed -e s/"^ *after"/"${1} "/g \
-e s/"^ *before *\([a-zA-Z0-9\-_\.]*\)"/"\1 ${1}"/g
} }
function exec() { function exec() {
@@ -117,6 +165,7 @@ function template() {
function spin() { function spin() {
module=$1 module=$1
echo "info: Processing ${module}" echo "info: Processing ${module}"
NOOP="true" files $module
NOOP="true" template $module NOOP="true" template $module
if [ "$NOOP" == "" ]; then if [ "$NOOP" == "" ]; then
# We rsync all the configs and files into the 'real' scratchfs so that we can # We rsync all the configs and files into the 'real' scratchfs so that we can
@@ -146,4 +195,4 @@ function spin() {
return $? return $?
} }
$1 $2 $1 "$2" "$3" "$4" "$5" "$6" "$7" "$8"