Created
January 25, 2013 18:51
-
-
Save craigbro/4636853 to your computer and use it in GitHub Desktop.
A shell script for deploying an Immutant archive as if it was a regular unix daemon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# This allows the deploy/undeploy/redeploy of an Immutant archive as | |
# if it was a daemon. The start/stop/restart methods block until that | |
# operation is done, so it works as init scripts are expected too. | |
set -e | |
IMA=/sandcastle/face/face.ima | |
DEPLOYDIR=/sandcastle/immutant/jboss/standalone/deployments | |
IMAFILE=`basename $IMA` | |
DIRNAME=`dirname "$0"` | |
function die { | |
echo $1 | |
exit 1 | |
} | |
case "$1" in | |
start) | |
echo "Deploying $IMAFILE" | |
[ -f $IMA ] || die "$IMA does not exist" | |
if [ ! -f $DEPLOYDIR/$IMAFILE ]; then | |
ln -s $IMA $DEPLOYDIR/ | |
fi | |
rm -f $DEPLOYDIR/$IMAFILE.failed | |
if [ ! -f $DPELOYDIR/$IMAFILE.deployed ]; then | |
touch $DEPLOYDIR/$IMAFILE.dodeploy | |
fi | |
#wait for deployed | |
echo "Waiting for $IMAFILE to deploy..." | |
while [ ! -f $DEPLOYDIR/$IMAFILE.deployed ]; do | |
if [ -f $DEPLOYDIR/$IMAFILE.failed ]; then | |
die "Deployment of $IMAFILE failed." | |
else | |
sleep 1 | |
fi | |
done | |
echo "$IMAFILE is deployed." | |
;; | |
stop) | |
if [ -f $DEPLOYDIR/$IMAFILE.deployed ]; then | |
echo "Undeploying $IMAFILE" | |
rm $DEPLOYDIR/$IMAFILE.deployed | |
# wait for .undeployed | |
while [ ! -f $DEPLOYDIR/$IMAFILE.undeployed ]; do | |
sleep 1 | |
done | |
elif [ -f $DEPLOYDIR/$IMAFILE.failed ]; then | |
echo "$IMAFILE has failed, and is not running." | |
echo "Removing $DEPLOYDIR/$IMAFILE.failed" | |
rm $DEPLOYDIR/$IMAFILE.failed | |
else | |
echo "$IMAFILE is not deployed." | |
fi | |
;; | |
restart) | |
echo "Restaring $IMAFILE" | |
touch $DEPLOYDIR/$IMAFILE.dodeploy | |
#wait for deployed | |
sleep 5 | |
while [ -f $DEPLOYDIR/$IMAFILE.isdeploying ]; do | |
if [ -f $DEPLOYDIR/$IMAGEFILE.failed ]; then | |
die "Re-deployment of $IMAFILE failed." | |
else | |
sleep 1 | |
fi | |
done | |
echo "$IMAFILE is deployed." | |
;; | |
status) | |
if [ -f $DEPLOYDIR/$IMAFILE.deployed ]; then | |
echo "$IMAFILE is deployed" | |
elif [ -f $DEPLOYDIR/$IMAFILE.failed ]; then | |
echo "$IMAFILE deployment failed" | |
elif [ -f $DEPLOYDIR/$IMAFILE.undeployed ]; then | |
echo "$IMAFILE has been undeployed" | |
else | |
echo "$IMAFILE not deployed" | |
fi | |
;; | |
*) | |
echo "usage $0 {start|stop|restart|status}" | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment