Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Upgrade rundeck 2.0.2 h2 database from earlier 2.0.x version.
#!/bin/bash
set -e
#set -x
RDECK_BASE=${RDECK_BASE:-$(pwd)}
CONFFILE=$1
H2JAR=$2
if [ -z "$CONFFILE" ] ; then
if [ -f ${RDECK_BASE}/server/config/rundeck-config.properties ] ; then
CONFFILE=${RDECK_BASE}/server/config/rundeck-config.properties
elif [ -f /etc/rundeck/rundeck-config.properties ] ; then
CONFFILE=/etc/rundeck/rundeck-config.properties
fi
fi
if [ -z "$H2JAR" ] ; then
if [ -f ${RDECK_BASE}/server/exp/webapp/WEB-INF/lib/h2-1.3.164.jar ] ; then
H2JAR=${RDECK_BASE}/server/exp/webapp/WEB-INF/lib/h2-1.3.164.jar
elif [ -f /var/lib/rundeck/exp/webapp/WEB-INF/lib/h2-1.3.164.jar ] ; then
H2JAR=/var/lib/rundeck/exp/webapp/WEB-INF/lib/h2-1.3.164.jar
fi
fi
if [ ! -f $CONFFILE ] ; then
echo "rundeck-config.properties not found at path $CONFFILE"
fi
if [ -z "$H2JAR" -o ! -f $H2JAR ] ; then
echo "h2-1.3.164.jar not found at path $H2JAR"
fi
if [ ! -f $CONFFILE -o -z "$H2JAR" -o ! -f $H2JAR ] ; then
echo "Usage: update.sh [rundeck-config-file] [h2-jar-file]"
echo "Specify the path to the rundeck-config.properties file and the h2-1.3.164.jar file"
exit 2
fi
SQLFILE=rd_202_update.sql
cat >$SQLFILE <<END
alter table EXECUTION alter column FILTER type VARCHAR(2147483647);
select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'EXECUTION';
END
H2URL=$( cat $CONFFILE | awk '/^dataSource\.url *?=/ { print $3;}' | tr -d '\n' )
SCRIPTOUT=rd_202_update.out
#URL="jdbc:h2:file:/Users/greg/rundeck2d/server/data/grailsdb;MVCC=true"
echo "Updating url $H2URL..."
java -cp $H2JAR org.h2.tools.RunScript \
-url $H2URL \
-driver org.h2.Driver \
-user sa \
-script $SQLFILE -showResults > $SCRIPTOUT
#look for expected field type in schema output
grep -q 'FILTER VARCHAR(2147483647),' $SCRIPTOUT || {
cat $SCRIPTOUT
echo
echo "FAILED: unable to update FILTER column, expected FILTER VARCHAR(2147483647)"
exit 2
}
echo "Done."
rm $SQLFILE $SCRIPTOUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment