Skip to content

Instantly share code, notes, and snippets.

@fvanderbiest
Created October 20, 2015 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fvanderbiest/d93c6c7d2e58425c2b2e to your computer and use it in GitHub Desktop.
Save fvanderbiest/d93c6c7d2e58425c2b2e to your computer and use it in GitHub Desktop.
incrond script monitoring geoserver's global.xml
#!/bin/sh
# author: Landry Breuil
# ensure all atomic ops are over when post'ing via REST ?
sleep 10
LOG_FILE=/srv/log/tomcat/geoserver/datasync.$(date +%F_%T)
# Close STDOUT file descriptor
exec 1<&-
# Close STDERR FD
exec 2<&-
# Open STDOUT as $LOG_FILE file for read and write.
exec 1<>$LOG_FILE
# Redirect STDERR to STDOUT
exec 2>&1
date
cd /data/webapps/geoserver
if [ -n "$(/usr/bin/git status --porcelain)" ] ; then
updateseq=$(grep updateSequence global.xml |sed -e 's#.*ce>\(.*\)</up.*#\1#')
find * \! -user tomcat -print0 | xargs -0 -r chown tomcat
git add .
env HOME=/root git commit --author 'Incron <root@ids.host>' -m "auto-update: ${updateseq}"
if [ $? -ne 0 ] ; then
echo "failed to git-commit !"
cat $LOG_FILE | mail -s '[geoserver-auto-update] failed to commit' admin@fqdn
exit 7
fi
date
git push origin 2.5
if [ $? -ne 0 ] ; then
echo "failed to push !"
cat $LOG_FILE | mail -s '[geoserver-auto-update] failed to push' admin@fqdn
exit 2
fi
date
rsync -a --stats --delete data slave:/data/webapps/geoserver
if [ $? -ne 0 ] ; then
echo "failed to rsync data !"
cat $LOG_FILE | mail -s '[geoserver-auto-update] failed to rsync data' admin@fqdn
exit 3
fi
date
ssh slave "cd /data/webapps/geoserver && git reset --hard origin/2.5 && git pull origin 2.5"
if [ $? -ne 0 ] ; then
echo "failed to git pull on slave: $?"
cat $LOG_FILE | mail -s '[geoserver-auto-update] failed to git pull on slave' admin@fqdn
exit 4
fi
ssh slave "find /data/webapps/geoserver/* \! -user tomcat -print0 | xargs -0 -r chown tomcat"
if [ $? -ne 0 ] ; then
echo "failed to fix ownership on slave: $?"
cat $LOG_FILE | mail -s '[geoserver-auto-update] failed to fix ownership on slave' admin@fqdn
exit 5
fi
date
curl -sI -u login:pass -XPOST http://slave:8280/wxs/rest/reload
if [ $? -ne 0 ] ; then
echo "failed to curl /rest/reload on slave: $?"
cat $LOG_FILE | mail -s '[geoserver-auto-update] failed to curl /rest/reload on slave' admin@fqdn
exit 6
fi
date
cat $LOG_FILE | mail -s "[geoserver-auto-update] update sequence ${updateseq}" admin@fqdn
else
echo "nothing to commit ??"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment