Strabon

changeset 418:eebc02275912

Make redeploy configurable by using command line arguments
author George Garbis <ggarbis@di.uoa.gr>
date Tue Jul 10 20:46:11 2012 +0300 (2012-07-10)
parents 5c927b88eadf
children 28ce0ecfb65b
files scripts/redeploy
line diff
     1.1 --- a/scripts/redeploy	Tue Jul 10 20:33:58 2012 +0300
     1.2 +++ b/scripts/redeploy	Tue Jul 10 20:46:11 2012 +0300
     1.3 @@ -1,20 +1,106 @@
     1.4  #! /bin/bash
     1.5  
     1.6 -echo "This script must be executed in Strabon folder"
     1.7 +# this command
     1.8 +CMD="$(basename ${0})"
     1.9  
    1.10 -while getopts po option
    1.11 -do
    1.12 -	case "$option" in
    1.13 -		o)	echo "offline"; offline="-o";;
    1.14 -		p)	echo "package"; package="true";;
    1.15 +function print_help() {
    1.16 +	echo "Usage ${CMD} [OPTIONS]"
    1.17 +	echo
    1.18 +	echo "Redeploy endpoint on tomcat"
    1.19 +	echo
    1.20 +	echo "OPTIONS"
    1.21 +	echo " -w, --webapps:       path to tomcat webapps folder (default: /var/lib/tomcat7/webapss)"
    1.22 +	echo " -t, --tomcat:        the version of the installed tomcat (default: tomcat7)"
    1.23 +	echo " -c, --catalina: 		value of CATALINA_BASE (use only if tomcat works in standalone version)"
    1.24 +	echo "                      when -c is specified -t must not be specified and vice versa"
    1.25 +	echo " -p, --postgres:      the version of the installed tomcat (default: postgresql)"
    1.26 +	echo " -e, --endpoint:      the name of the finally deployed war (default: endpoint)"
    1.27 +	echo " -b:                  not only redeploy the war but also rebuild it (mvn clean package)"
    1.28 +	echo " -o:                  mvn will build the new endpoint working in offline mode"
    1.29 +	echo " -h, --help:          print this message"
    1.30 +}
    1.31 +
    1.32 +
    1.33 +# Default values of arguments
    1.34 +webapps="/var/lib/tomcat7/webapps"
    1.35 +tomcat=""
    1.36 +catalina=""
    1.37 +postgres="postgresql"
    1.38 +endpoint="endpoint"
    1.39 +
    1.40 +# Parse arguments
    1.41 +temp=`getopt -o hbow:t:p:e:c: --long help,webapps:,tomcat:,postgres:,endpoint:,catalina-base -n 'redeploy' -- "$@"`
    1.42 +eval set -- "$temp"
    1.43 +while true; do
    1.44 +	case "$1" in
    1.45 +		-w|--webapps)	
    1.46 +				webapps=`echo $2 | sed 's#\/$##g'`; shift 2;;
    1.47 +		-t|--tomcat) 	
    1.48 +				tomcat=$2; shift 2;;
    1.49 +		-p|--postgres) 	
    1.50 +				postgres=$2; shift 2;;
    1.51 +		-e|--endpoint) 	
    1.52 +				endpoint=$2; shift 2;;
    1.53 +		-b)				
    1.54 +				build=true; shift;;
    1.55 +		-o)						
    1.56 +				offline=true; shift;;
    1.57 +		-c|--catalina-base)
    1.58 +				catalina=`echo $2 | sed 's#\/$##g'`; shift 2;;
    1.59 +		-h|--help)			
    1.60 +				print_help; exit 0;;
    1.61 +		--)
    1.62 +				shift; break;;
    1.63 +		*) 
    1.64 +				echo "Interanl error!"; exit 1;;
    1.65  	esac
    1.66  done
    1.67  
    1.68 -if [ "$package" == "true" ]; then
    1.69 -	mvn $offline clean package
    1.70 +if [ "${catalina}" != "" -a "${tomcat}" != "" ]; then
    1.71 +	echo "You cannot specify both catalina and tomcat options at the same time!"
    1.72 +	exit -1
    1.73 +elif [ "${catalina}" == "" -a "${tomcat}" == "" ]; then
    1.74 +	tomcat="/var/lib/tomcat7"
    1.75  fi
    1.76  
    1.77 -sudo cp endpoint/target/strabon-endpoint-*.war /var/lib/tomcat6/webapps/endpoint.war  &&
    1.78 +# Build package
    1.79 +if [ $build ]; then
    1.80 +	if [ $offline ]; then
    1.81 +		mvn -o clean package
    1.82 +	else
    1.83 +		mvn clean package
    1.84 +	fi
    1.85 +fi
    1.86  
    1.87 -sudo service postgresql restart &&
    1.88 -sudo service tomcat6 restart 
    1.89 +if [ ! -f endpoint/target/strabon-endpoint-*.war ]; then
    1.90 +	echo "File endpoint/target/strabon-endpoint-*.war cannot be found."
    1.91 +	echo "This script must be executed in Strabon folder"
    1.92 +	exit -1
    1.93 +fi
    1.94 +
    1.95 +if [ "`ls ${webapps}|grep war|grep -v ${endpoint}.war`" != "" ];then
    1.96 +	echo "WARNING: there are other war applications in ${webapps}"
    1.97 +fi
    1.98 +
    1.99 +#echo "Stand alone: ${tomcatStandalone}"
   1.100 +## Redeploy
   1.101 +#test -e ${tomcatStandalone}
   1.102 +#cond=$?
   1.103 +#if [ ${cond} -eq 1 ]; then
   1.104 +if [ "${catalina}" != "" ]; then
   1.105 +	${catalina}/bin/shutdown.sh && 
   1.106 +	sudo service ${postgres} stop &&
   1.107 +	sudo rm -f ${webapps}/${endpoint}.war &&
   1.108 +	sudo rm -rf ${webapps}/${endpoint} &&
   1.109 +	sudo cp endpoint/target/strabon-endpoint-*.war ${webapps}/${endpoint}.war  &&
   1.110 +	sudo service ${postgres} start &&
   1.111 +	${catalina}/bin/startup.sh  start 
   1.112 +else
   1.113 +	sudo service ${tomcat} stop && 
   1.114 +	sudo service ${postgres} stop &&
   1.115 +	sudo rm -f ${webapps}/${endpoint}.war &&
   1.116 +	sudo rm -rf ${webapps}/${endpoint} &&
   1.117 +	sudo cp endpoint/target/strabon-endpoint-*.war ${webapps}/${endpoint}.war  &&
   1.118 +	sudo service ${postgres} start &&
   1.119 +	sudo service ${tomcat}  start 
   1.120 +fi