Strabon

annotate scripts/redeploy @ 528:ee19ee42b46f

fix in redeploy script
author George Garbis <ggarbis@di.uoa.gr>
date Mon Jul 30 22:13:58 2012 +0300 (2012-07-30)
parents eebc02275912
children b95784675cc7
rev   line source
ggarbis@264 1 #! /bin/bash
ggarbis@264 2
ggarbis@418 3 # this command
ggarbis@418 4 CMD="$(basename ${0})"
ggarbis@264 5
ggarbis@418 6 function print_help() {
ggarbis@418 7 echo "Usage ${CMD} [OPTIONS]"
ggarbis@418 8 echo
ggarbis@418 9 echo "Redeploy endpoint on tomcat"
ggarbis@418 10 echo
ggarbis@418 11 echo "OPTIONS"
ggarbis@418 12 echo " -w, --webapps: path to tomcat webapps folder (default: /var/lib/tomcat7/webapss)"
ggarbis@418 13 echo " -t, --tomcat: the version of the installed tomcat (default: tomcat7)"
ggarbis@418 14 echo " -c, --catalina: value of CATALINA_BASE (use only if tomcat works in standalone version)"
ggarbis@418 15 echo " when -c is specified -t must not be specified and vice versa"
ggarbis@418 16 echo " -p, --postgres: the version of the installed tomcat (default: postgresql)"
ggarbis@418 17 echo " -e, --endpoint: the name of the finally deployed war (default: endpoint)"
ggarbis@418 18 echo " -b: not only redeploy the war but also rebuild it (mvn clean package)"
ggarbis@418 19 echo " -o: mvn will build the new endpoint working in offline mode"
ggarbis@418 20 echo " -h, --help: print this message"
ggarbis@418 21 }
ggarbis@418 22
ggarbis@418 23
ggarbis@418 24 # Default values of arguments
ggarbis@418 25 webapps="/var/lib/tomcat7/webapps"
ggarbis@418 26 tomcat=""
ggarbis@418 27 catalina=""
ggarbis@418 28 postgres="postgresql"
ggarbis@418 29 endpoint="endpoint"
ggarbis@418 30
ggarbis@418 31 # Parse arguments
ggarbis@418 32 temp=`getopt -o hbow:t:p:e:c: --long help,webapps:,tomcat:,postgres:,endpoint:,catalina-base -n 'redeploy' -- "$@"`
ggarbis@418 33 eval set -- "$temp"
ggarbis@418 34 while true; do
ggarbis@418 35 case "$1" in
ggarbis@418 36 -w|--webapps)
ggarbis@418 37 webapps=`echo $2 | sed 's#\/$##g'`; shift 2;;
ggarbis@418 38 -t|--tomcat)
ggarbis@418 39 tomcat=$2; shift 2;;
ggarbis@418 40 -p|--postgres)
ggarbis@418 41 postgres=$2; shift 2;;
ggarbis@418 42 -e|--endpoint)
ggarbis@418 43 endpoint=$2; shift 2;;
ggarbis@418 44 -b)
ggarbis@418 45 build=true; shift;;
ggarbis@418 46 -o)
ggarbis@418 47 offline=true; shift;;
ggarbis@418 48 -c|--catalina-base)
ggarbis@418 49 catalina=`echo $2 | sed 's#\/$##g'`; shift 2;;
ggarbis@418 50 -h|--help)
ggarbis@418 51 print_help; exit 0;;
ggarbis@418 52 --)
ggarbis@418 53 shift; break;;
ggarbis@418 54 *)
ggarbis@418 55 echo "Interanl error!"; exit 1;;
ggarbis@264 56 esac
ggarbis@264 57 done
ggarbis@264 58
ggarbis@418 59 if [ "${catalina}" != "" -a "${tomcat}" != "" ]; then
ggarbis@418 60 echo "You cannot specify both catalina and tomcat options at the same time!"
ggarbis@418 61 exit -1
ggarbis@418 62 elif [ "${catalina}" == "" -a "${tomcat}" == "" ]; then
ggarbis@528 63 tomcat="tomcat7"
ggarbis@264 64 fi
ggarbis@264 65
ggarbis@418 66 # Build package
ggarbis@418 67 if [ $build ]; then
ggarbis@418 68 if [ $offline ]; then
ggarbis@418 69 mvn -o clean package
ggarbis@418 70 else
ggarbis@418 71 mvn clean package
ggarbis@418 72 fi
ggarbis@418 73 fi
ggarbis@264 74
ggarbis@418 75 if [ ! -f endpoint/target/strabon-endpoint-*.war ]; then
ggarbis@418 76 echo "File endpoint/target/strabon-endpoint-*.war cannot be found."
ggarbis@418 77 echo "This script must be executed in Strabon folder"
ggarbis@418 78 exit -1
ggarbis@418 79 fi
ggarbis@418 80
ggarbis@418 81 if [ "`ls ${webapps}|grep war|grep -v ${endpoint}.war`" != "" ];then
ggarbis@418 82 echo "WARNING: there are other war applications in ${webapps}"
ggarbis@418 83 fi
ggarbis@418 84
ggarbis@418 85 #echo "Stand alone: ${tomcatStandalone}"
ggarbis@418 86 ## Redeploy
ggarbis@418 87 #test -e ${tomcatStandalone}
ggarbis@418 88 #cond=$?
ggarbis@418 89 #if [ ${cond} -eq 1 ]; then
ggarbis@418 90 if [ "${catalina}" != "" ]; then
ggarbis@418 91 ${catalina}/bin/shutdown.sh &&
ggarbis@418 92 sudo service ${postgres} stop &&
ggarbis@418 93 sudo rm -f ${webapps}/${endpoint}.war &&
ggarbis@418 94 sudo rm -rf ${webapps}/${endpoint} &&
ggarbis@418 95 sudo cp endpoint/target/strabon-endpoint-*.war ${webapps}/${endpoint}.war &&
ggarbis@418 96 sudo service ${postgres} start &&
ggarbis@418 97 ${catalina}/bin/startup.sh start
ggarbis@418 98 else
ggarbis@418 99 sudo service ${tomcat} stop &&
ggarbis@418 100 sudo service ${postgres} stop &&
ggarbis@418 101 sudo rm -f ${webapps}/${endpoint}.war &&
ggarbis@418 102 sudo rm -rf ${webapps}/${endpoint} &&
ggarbis@418 103 sudo cp endpoint/target/strabon-endpoint-*.war ${webapps}/${endpoint}.war &&
ggarbis@418 104 sudo service ${postgres} start &&
ggarbis@418 105 sudo service ${tomcat} start
ggarbis@418 106 fi