Strabon

annotate scripts/redeploy @ 1433:612f816ca032

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