Author: tchemit Date: 2014-02-19 22:29:07 +0100 (Wed, 19 Feb 2014) New Revision: 39 Url: http://forge.codelutin.com/projects/adminsys/repository/revisions/39 Log: add demo-tools scripts Added: demo-tools/ demo-tools/tomcat/ demo-tools/tomcat/apache-demo-ng demo-tools/tomcat/check-get-tomcat.sh demo-tools/tomcat/deploy.cgi demo-tools/tomcat/deploy.html demo-tools/tomcat/deploy.sh demo-tools/tomcat/tomcat-crondaily demo-tools/tomcat/tomcat-default demo-tools/tomcat/tomcat-init.d Added: demo-tools/tomcat/apache-demo-ng =================================================================== --- demo-tools/tomcat/apache-demo-ng (rev 0) +++ demo-tools/tomcat/apache-demo-ng 2014-02-19 21:29:07 UTC (rev 39) @@ -0,0 +1,179 @@ +<VirtualHost *:80> + ServerName demo-ng.codelutin.com + ServerAlias demo.codelutin.com + ServerAlias *.demo.codelutin.com + ServerAlias *.demo-ng.codelutin.com + ServerAlias demo-ng.* + ServerAlias *.demo-ng.* + ServerAlias demo.* + ServerAlias *.demo.* + + DocumentRoot /var/local/demo/app/ + + <Directory /var/local/demo/app/> + # ce repertoire n'est pas accessible, il faut connaitre directement + # les sous repertoires + Options ExecCGI FollowSymLinks + AllowOverride None + Order Deny,Allow + Allow from All + AddHandler cgi-script .cgi + </Directory> + + <Directory /var/local/demo/app/*/> + # le repertoire des applictions permet a chaque application de + # modifier sa configuration via le fichier .apache.conf inclus en + # fin de fichier. Chaque application peut aussi mettre un fichier + # index.html pour presenter l'application + Options All + AllowOverride All + Order Deny,Allow + Allow from All + </Directory> + + <Directory /var/local/demo/app/*/*/> + # Le repertoire contenant les war, conf, log, db, ... n'est pas + # accessible depuis le web + Options None + # en fait ce n'est pas une vrai interdiction, car ca marche pas :( + # c'est simplement une interdiction de lister les fichiers, mais si + # on connait le nom d'un fichier on peut le recuperer. + # (TODO: trouver la bonne config) +# Order Deny,Allow +# Deny from All + </Directory> + + <Files ".apache.conf"> + # on interdit la recuperation des fichiers inclus (.apache.conf) + Order Deny,Allow + Deny from All + </Files> + + + + # Possible values include: debug, info, notice, warn, error, crit, alert, emerg. + LogLevel warn + ErrorLog ${APACHE_LOG_DIR}/demo-ng-error.log + CustomLog ${APACHE_LOG_DIR}/demo-ng-access.log combined + + # inclusion des fichiers de configuration pour chaque application, soit + # globalement pour toutes les demo (latest, staging, stable) soit + # individuellement + # l'inclusion avec un * pour un repertoire n'est pas possible, on fait + # donc en perl :( + <Perl> + foreach $file (glob '/var/local/demo/app/*/.apache.conf') { + push @Include, $file; + } + foreach $file (glob '/var/local/demo/app/*/*/.apache.conf') { + push @Include, $file; + } + </Perl> + + # les proxy en dernier pour permettre a chaque projet de le surcharger + + # pour ne pas servir de proxy a la terre entiere + ProxyRequests off + + ProxyPassMatch ^/(.*)-stable/?(.*)$ ajp://localhost:18971/$1-stable/$2 + ProxyPassMatch ^/(.*)-staging/?(.*)$ ajp://localhost:18972/$1-staging/$2 + ProxyPassMatch ^/(.*)-latest/?(.*)$ ajp://localhost:18973/$1-latest/$2 + +# ProxyPassMatch ^/(.*)/(latest|staging|stable)(/?.*)$ http://www.codelutin.com/$1$3 + +</VirtualHost> + +<VirtualHost *:443> + ServerName demo-ng.codelutin.com + ServerAlias demo.codelutin.com + ServerAlias *.demo.codelutin.com + ServerAlias *.demo-ng.codelutin.com + ServerAlias demo-ng.* + ServerAlias *.demo-ng.* + ServerAlias demo.* + ServerAlias *.demo.* + + DocumentRoot /var/local/demo/app/ + + <IfModule mod_ssl.c> + SSLEngine on + SSLCertificateFile /etc/ssl/certs/wildcard.codelutin.com.crt + SSLCertificateKeyFile /etc/ssl/private/wildcard.codelutin.com.key + SSLCACertificateFile /etc/ssl/certs/GandiStandardSSLCA.pem + SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown + SSLVerifyClient None + </IfModule> + + + <Directory /var/local/demo/app/> + # ce repertoire n'est pas accessible, il faut connaitre directement + # les sous repertoires + Options ExecCGI FollowSymLinks + AllowOverride None + Order Deny,Allow + Allow from All + AddHandler cgi-script .cgi + </Directory> + + <Directory /var/local/demo/app/*/> + # le repertoire des applictions permet a chaque application de + # modifier sa configuration via le fichier .apache.conf inclus en + # fin de fichier. Chaque application peut aussi mettre un fichier + # index.html pour presenter l'application + Options All + AllowOverride All + Order Deny,Allow + Allow from All + </Directory> + + <Directory /var/local/demo/app/*/*/> + # Le repertoire contenant les war, conf, log, db, ... n'est pas + # accessible depuis le web + Options None + # en fait ce n'est pas une vrai interdiction, car ca marche pas :( + # c'est simplement une interdiction de lister les fichiers, mais si + # on connait le nom d'un fichier on peut le recuperer. + # (TODO: trouver la bonne config) +# Order Deny,Allow +# Deny from All + </Directory> + + <Files ".apache.conf"> + # on interdit la recuperation des fichiers inclus (.apache.conf) + Order Deny,Allow + Deny from All + </Files> + + + + # Possible values include: debug, info, notice, warn, error, crit, alert, emerg. + LogLevel warn + ErrorLog ${APACHE_LOG_DIR}/demo-ng-error.log + CustomLog ${APACHE_LOG_DIR}/demo-ng-access.log combined + + # inclusion des fichiers de configuration pour chaque application, soit + # globalement pour toutes les demo (latest, staging, stable) soit + # individuellement + # l'inclusion avec un * pour un repertoire n'est pas possible, on fait + # donc en perl :( + <Perl> + foreach $file (glob '/var/local/demo/app/*/.apache.conf') { + push @Include, $file; + } + foreach $file (glob '/var/local/demo/app/*/*/.apache.conf') { + push @Include, $file; + } + </Perl> + + # les proxy en dernier pour permettre a chaque projet de le surcharger + + # pour ne pas servir de proxy a la terre entiere + ProxyRequests off + + ProxyPassMatch ^/(.*)-stable/?(.*)$ ajp://localhost:18971/$1-stable/$2 + ProxyPassMatch ^/(.*)-staging/?(.*)$ ajp://localhost:18972/$1-staging/$2 + ProxyPassMatch ^/(.*)-latest/?(.*)$ ajp://localhost:18973/$1-latest/$2 + +# ProxyPassMatch ^/(.*)/(latest|staging|stable)(/?.*)$ http://www.codelutin.com/$1$3 + +</VirtualHost> Added: demo-tools/tomcat/check-get-tomcat.sh =================================================================== --- demo-tools/tomcat/check-get-tomcat.sh (rev 0) +++ demo-tools/tomcat/check-get-tomcat.sh 2014-02-19 21:29:07 UTC (rev 39) @@ -0,0 +1,91 @@ +#!/bin/sh + +# +# USAGE: check-get-tomcat.sh [debug] +# +# verifie s'il y a ou non une nouvelle version tomcat par rapport a celle installee +# si c'est le cas: +# - telecharge le fichier +# - le decompresse +# - le met en place pour les diffentes instances souhaite +# - affiche le chemin des nouvelles instances mise en place si besoin +# +# l'administrateur devra alors faire un +# - /etc/init.d/tomcat stop [6|7] +# - /etc/init.d/tomcat start [6|7] +# + +DEBUG=false +MIRROR=http://mirrors.linsrv.net/apache/tomcat +TARGET_DIR=/opt/repository +LINK_DIR=/opt + +if [ "$1" = "debug" ]; then + export DEBUG=true +fi + +debug () { + if [ "$DEBUG" = "true" ]; then + echo "$1" + fi +} + +getFileURL () { + local RELEASE=$2 + local VERSION=${2%%.*} + local result="$MIRROR/tomcat-$VERSION/v$RELEASE/bin/apache-tomcat-$RELEASE.tar.gz" + debug "getFileURL: $result" + eval $1=\$result +} + +# get the last release for specified tomcat version +# @param $1 returned value +# @param $2 tomcat version 6, 7 or 8 +getLastRelease () { + local VERSION=$2 + local result=$(curl -s http://mirrors.linsrv.net/apache/tomcat/tomcat-$VERSION/ |grep "href=.v" |sed -re 's/.*>v([0-9]+.[0-9]+.[0-9]+).*/\1/') + debug "last version is $result" + eval $1=\$result +} + +getCurrentRelease () { + local VERSION=$2 + local LINK=$(readlink $LINK_DIR/apache-tomcat-$VERSION) + local DIR=$(basename $LINK) + local result=${DIR##*-} + debug "getCurrentRelease: $result" + eval $1="$result" +} + +installRelease () { + local RELEASE=$1 + local VERSION=${RELEASE%%.*} + local URL + getFileURL URL $RELEASE + mkdir -p $TARGET_DIR + curl -s "$URL" | tar --no-same-owner -C "$TARGET_DIR" -xz + + local DIR=$(basename $URL .tar.gz) + local UNPACK_DIR=$TARGET_DIR/$DIR + local LINK=$LINK_DIR/${DIR%%.*} + rm -f $LINK + ln -s $UNPACK_DIR $LINK + + echo "new release installed in $LINK -> $UNPACK_DIR" +} + +update () { + local VERSION=$1 + local CURRENT_RELEASE + local LAST_RELEASE + + getCurrentRelease CURRENT_RELEASE $VERSION + getLastRelease LAST_RELEASE $VERSION + + if [ "$CURRENT_RELEASE" != "$LAST_RELEASE" ]; then + installRelease $LAST_RELEASE + fi +} + +update 6 +update 7 Property changes on: demo-tools/tomcat/check-get-tomcat.sh ___________________________________________________________________ Added: svn:executable + * Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: demo-tools/tomcat/deploy.cgi =================================================================== --- demo-tools/tomcat/deploy.cgi (rev 0) +++ demo-tools/tomcat/deploy.cgi 2014-02-19 21:29:07 UTC (rev 39) @@ -0,0 +1,127 @@ +#!/usr/bin/env python + +print "Content-Type: text/plain" # plain is following +print # blank line, end of headers + +import os +import sys +import cgi +import cgitb +import shutil +import time +import subprocess + +cgitb.enable() + +form = cgi.FieldStorage() + +def mkdirForFile(file): + dir = os.path.dirname(file) + if not os.path.exists(dir): + os.makedirs(dir) + +def copy(filein, filename): + mkdirForFile(filename) + fileout = open(filename, "w") + shutil.copyfileobj(filein, fileout) + fileout.close() + +TODAY=time.strftime('%Y%m%d') + +# APP_NAME +APP_NAME=form.getvalue("APP_NAME") +if not APP_NAME: + print "<h1>APP_NAME mandatory</h1>" + +# TOMCAT_INSTANCE +TOMCAT_INSTANCE=form.getvalue("TOMCAT_INSTANCE") +TOMCAT_INSTANCE_UNIVERSE=['latest', 'staging', 'stable'] + +if not TOMCAT_INSTANCE in TOMCAT_INSTANCE_UNIVERSE: + print "<h1>TOMCAT_INSTANCE must be in %s but was <strong>%s</strong></h1>" % (TOMCAT_INSTANCE_UNIVERSE, TOMCAT_INSTANCE) + sys.exit() + +# TARGET_DIR (where to install application) +TARGET_DIR="/var/local/demo/app/%s/%s" % (APP_NAME, TOMCAT_INSTANCE) + +# WAR_NAME (name of war to deploy in tomcat) +WAR_LINK="%s/%s-%s.war" % (TARGET_DIR, APP_NAME, TOMCAT_INSTANCE) + +# VERSION_FILE (contains the last version of tomcat used for this application, not exist at first deploy for an application) +VERSION_FILE="%s/.tomcat" % (TARGET_DIR) + +# TOMCAT_VERSION +TOMCAT_VERSION=form.getvalue("TOMCAT_VERSION") +if not TOMCAT_VERSION: + if os.path.exists(VERSION_FILE): + f = open(VERSION_FILE, "r") + TOMCAT_VERSION=f.read() + f.close() + else: + TOMCAT_VERSION=7 +else: + TOMCAT_VERSION_UNIVERSE = ['6','7'] + if not TOMCAT_VERSION in TOMCAT_VERSION_UNIVERSE: + print "<h1>TOMCAT_VERSION must be in %s but was <strong>%s</strong></h1>" % (TOMCAT_VERSION_UNIVERSE, TOMCAT_VERSION) + sys.exit() + + mkdirForFile(VERSION_FILE) + f = open(VERSION_FILE, "w") + f.write(TOMCAT_VERSION) + f.close() + +# TOMCAT_HOME +TOMCAT_HOME='/var/local/demo/tomcat/tomcat-%s-%s' % (TOMCAT_VERSION, TOMCAT_INSTANCE) + +# APP_WAR_FILE war to deploy in tomcat +APP_WAR_FILE=None +if "APP_WAR" in form and form["APP_WAR"].done != -1: + APP_WAR=form["APP_WAR"] + filename = os.path.basename(APP_WAR.filename) + if os.path.splitext(filename)[1] != ".war": + print "<h1>Only war file can be uploaded as war</h1>" + sys.exit() + filepath = "%s/war/%s-%s" % (TARGET_DIR, TODAY, filename) + copy(APP_WAR.file, filepath) + if os.path.exists(WAR_LINK): + os.unlink(WAR_LINK) + os.symlink(filepath, WAR_LINK) + APP_WAR_FILE="%s -> %s" % (WAR_LINK, filepath) + +#TODO tchemit 17/10/2013, Deal other extra download files + +# APP_CONF_FILE (configuration file to place on root directory of the tomcat instance) +APP_CONF_FILE=None + +if "APP_CONF" in form and form["APP_CONF"].done != -1: + APP_CONF=form["APP_CONF"] + filename = os.path.basename(APP_CONF.filename) + + # tchemit 18/10/2013, no need to check the extension, some app don't have a such thing... + # fileextension = os.path.splitext(filename)[1] + # if not fileextension in [".properties", ".conf", ".config"]: + # print "<h1>Only file with exension (.properties, .conf, .config) can be uploaded as config file</h1>" + # sys.exit() + filepath = "%s/conf/%s-%s" % (TARGET_DIR, TODAY, filename) + copy(APP_CONF.file, filepath) + CONF_LINK = "%s/%s" % (TARGET_DIR, filename) + if os.path.exists(CONF_LINK): + os.unlink(CONF_LINK) + os.symlink(filepath, CONF_LINK) + APP_CONF_FILE="%s -> %s" % (CONF_LINK, filepath) + +print "<h1>Deploy summary</h1>\n<ul>\n<li>application %s</li>\n<li>tomcat %s %s</li>\n<li>war %s</li>\n<li>conf %s</li>\n</ul>" % (APP_NAME, TOMCAT_VERSION, TOMCAT_INSTANCE, APP_WAR_FILE, APP_CONF_FILE) + +# create link du fichier de conf dans le $HOME_TOMCAT +# copy du war dans le $HOME_TOMCAT +# move du war dans $HOME_TOMCAT/webapps +#devnull = open(os.devnull, 'w') + +# logger for deploy.sh script +logger = open("/tmp/deploy.sh-%s-%s-%s.log" % (TOMCAT_VERSION, TOMCAT_INSTANCE, APP_NAME), 'w') + +subprocess.check_call(['/opt/script-tools/tomcat/deploy.sh %s %s %s' % (TOMCAT_HOME, WAR_LINK, CONF_LINK)], shell=True, executable='/bin/bash', stdout=logger, stderr=logger) + +# DO NOT REMOVE THIS, USED BY SOME CLIENT TO CHECK DEPLOY WAS OK" +print "<h1>Deploy success</h1>" +# DO NOT REMOVE THIS, USED BY SOME CLIENT TO CHECK DEPLOY WAS OK" Property changes on: demo-tools/tomcat/deploy.cgi ___________________________________________________________________ Added: svn:executable + * Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: demo-tools/tomcat/deploy.html =================================================================== --- demo-tools/tomcat/deploy.html (rev 0) +++ demo-tools/tomcat/deploy.html 2014-02-19 21:29:07 UTC (rev 39) @@ -0,0 +1,28 @@ +<html> +<body> +<form action="deploy.cgi" method="post" enctype="multipart/form-data"> +<p> +*APP_NAME:<input name="APP_NAME"/> +</p><p> +TOMCAT_VERSION: met a jour la version du tomcat cible, si None est choisi la +derniere version choisi est reutilise et par defaut tomcat 7 est +utilise<br/> +<input type="radio" name="TOMCAT_VERSION" value="" checked> None +<input type="radio" name="TOMCAT_VERSION" value="6"> 6 +<input type="radio" name="TOMCAT_VERSION" value="7"> 7 +</p> +</p> +*TOMCAT_INSTANCE: +<input type="radio" name="TOMCAT_INSTANCE" value="stable"> stable +<input type="radio" name="TOMCAT_INSTANCE" value="staging"> staging +<input type="radio" name="TOMCAT_INSTANCE" value="latest" checked> latest +</p><p> +APP_WAR:<input type="file" name="APP_WAR"/> +</p><p> +APP_CONF:<input type="file" name="APP_CONF"/> +</p><p> +<input type="submit"/> +</p> +</form> +</body> +</html> Property changes on: demo-tools/tomcat/deploy.html ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: demo-tools/tomcat/deploy.sh =================================================================== --- demo-tools/tomcat/deploy.sh (rev 0) +++ demo-tools/tomcat/deploy.sh 2014-02-19 21:29:07 UTC (rev 39) @@ -0,0 +1,77 @@ +#!/bin/bash + +if [ "$#" -lt 2 ]; then + echo "Usage: $0 \$TOMCAT_HOME file.war [conf.properties]" + exit 1 +fi + +TOMCAT_HOME=$1 +WAR_LINK=$2 +CONF_LINK=$3 + +if [ -n "$CONF_LINK" ]; then + ln -fs $CONF_LINK $TOMCAT_HOME +fi + +APP_HOME=$(dirname $WAR_LINK) +WAR_NAME=$(basename $WAR_LINK) +CONTEXT=$(basename $WAR_NAME .war) + +echo "Based on ${WAR_LINK}, APP_HOME=${APP_HOME}, WAR_NAME=${WAR_NAME} and CONTEXT=${CONTEXT}" + + + + +# +# Undeploy war +# +if [ -f $TOMCAT_HOME/webapps/$WAR_NAME ] +then + rm $TOMCAT_HOME/webapps/$WAR_NAME -f +fi + +# +# wait until war is gone from tomcat +# +i=0 +while [ -d $TOMCAT_HOME/webapps/$CONTEXT -a $i -lt 60 ]; do + i=$(($i + 1)) + echo "Waiting for app $CONTEXT to be undeployed... (since ${i}s)" + sleep 1 +done + +# +# Context undeployed or not, make sure the folder is removed +# +rm $TOMCAT_HOME/webapps/$CONTEXT -rf + + +# +# after-deploy hook +# +UNDEPLOY_SCRIPT=$APP_HOME/scripts/after-undeploy.sh +if [ -f $UNDEPLOY_SCRIPT ] +then + echo "Applying undeploy script: ${UNDEPLOY_SCRIPT}..." + $UNDEPLOY_SCRIPT +fi + +# +# before deploy hook +# +DEPLOY_SCRIPT=$APP_HOME/scripts/before-deploy.sh +if [ -f $DEPLOY_SCRIPT ] +then + echo "Applying deploy script: ${DEPLOY_SCRIPT}..." + $DEPLOY_SCRIPT +fi + +# +# deploy new war +# + +# on copie puis on move pour que le war arrive instantanement dans webapps et +# qu'il n'y ait pas de probleme de deploiement d'un fichier pas encore entier + +cp -fL $WAR_LINK $TOMCAT_HOME +mv $TOMCAT_HOME/$WAR_NAME $TOMCAT_HOME/webapps Property changes on: demo-tools/tomcat/deploy.sh ___________________________________________________________________ Added: svn:executable + * Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: demo-tools/tomcat/tomcat-crondaily =================================================================== --- demo-tools/tomcat/tomcat-crondaily (rev 0) +++ demo-tools/tomcat/tomcat-crondaily 2014-02-19 21:29:07 UTC (rev 39) @@ -0,0 +1,21 @@ +#!/bin/sh + +NAME=tomcat +DEFAULT=/etc/default/$NAME + +# The following variables can be overwritten in $DEFAULT + +# Default for number of days to keep old log files in /var/log/tomcatN/ +LOGFILE_DAYS=14 + +# End of variables that can be overwritten in $DEFAULT + +# overwrite settings from default file +if [ -f "$DEFAULT" ]; then + . "$DEFAULT" +fi + +if [ -d /var/log/$NAME ]; then + find /var/log/$NAME/ -name \*.log -mtime +$LOGFILE_DAYS -print0 \ + | xargs --no-run-if-empty -0 rm -- +fi Property changes on: demo-tools/tomcat/tomcat-crondaily ___________________________________________________________________ Added: svn:executable + * Added: demo-tools/tomcat/tomcat-default =================================================================== --- demo-tools/tomcat/tomcat-default (rev 0) +++ demo-tools/tomcat/tomcat-default 2014-02-19 21:29:07 UTC (rev 39) @@ -0,0 +1,8 @@ +TOMCAT_USER=www-data +TOMCAT_GROUP=www-data +JAVA_HOME=/opt/jdk +JAVA_OPTS="-Djava.awt.headless=true -XX:+UseConcMarkSweepGC -Dfile.encoding=UTF-8" +JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=400m -Xms512m -Xmx1024m -XX:-UseGCOverheadLimit" +JTOMCAT_SECURITY=no +LOGFILE_DAYS=30 +JVM_TMP=/tmp/tomcat-temp Added: demo-tools/tomcat/tomcat-init.d =================================================================== --- demo-tools/tomcat/tomcat-init.d (rev 0) +++ demo-tools/tomcat/tomcat-init.d 2014-02-19 21:29:07 UTC (rev 39) @@ -0,0 +1,356 @@ +#!/bin/bash +# +# /etc/init.d/tomcat -- startup script for the Tomcat servlet engine +# +# Written by Miquel van Smoorenburg <miquels@cistron.nl>. +# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>. +# Modified for Tomcat by Stefan Gybas <sgybas@debian.org>. +# Modified for Tomcat6 by Thierry Carrez <thierry.carrez@ubuntu.com>. +# Modified for Tomcat7 by Ernesto Hernandez-Novich <emhn@itverx.com.ve>. +# Additional improvements by Jason Brittain <jason.brittain@mulesoft.com>. +# Modified for Multiple Tomcat instance by Benjamin POUSSIN <poussin@codelutin.com>. +# +### BEGIN INIT INFO +# Provides: tomcat +# Required-Start: $local_fs $remote_fs $network +# Required-Stop: $local_fs $remote_fs $network +# Should-Start: $named +# Should-Stop: $named +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start Tomcat. +# Description: Start the Tomcat servlet engine. +### END INIT INFO + +set -e + +PATH=/bin:/usr/bin:/sbin:/usr/sbin +NAME=tomcat +DESC="Tomcat servlet engine" +DEFAULT=/etc/default/$NAME +JVM_TMP=/tmp/tomcat-$NAME-tmp + +if [ `id -u` -ne 0 ]; then + echo "You need root privileges to run this script" + exit 1 +fi + +# Make sure tomcat is started with system locale +if [ -r /etc/default/locale ]; then + . /etc/default/locale + export LANG +fi + +. /lib/lsb/init-functions + +if [ -r /etc/default/rcS ]; then + . /etc/default/rcS +fi + + +# The following variables can be overwritten in $DEFAULT + +# Run Tomcat 7 as this user ID and group ID +TOMCAT_USER=www-data +TOMCAT_GROUP=www-data + +# this is a work-around until there is a suitable runtime replacement +# for dpkg-architecture for arch:all packages +# this function sets the variable OPENJDKS +find_openjdks() +{ + for jvmdir in /usr/lib/jvm/java-7-openjdk-* + do + if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-7-openjdk-common" ] + then + OPENJDKS=$jvmdir + fi + done + for jvmdir in /usr/lib/jvm/java-6-openjdk-* + do + if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-6-openjdk-common" ] + then + OPENJDKS="${OPENJDKS} ${jvmdir}" + fi + done +} + +OPENJDKS="" +find_openjdks +# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not +# defined in $DEFAULT) +JDK_DIRS="/opt/jdk /usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun" + +# Look for the right JVM to use +for jdir in $JDK_DIRS; do + if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then + JAVA_HOME="$jdir" + fi +done +export JAVA_HOME + +# Directory where the Tomcat 6 binary distribution resides +CATALINA_HOME=/usr/share/$NAME + +# Directory for per-instance configuration files and webapps +CATALINA_BASE=/var/lib/$NAME + +# Use the Java security manager? (yes/no) +TOMCAT_SECURITY=no + +# Default Java options +# Set java.awt.headless=true if JAVA_OPTS is not set so the +# Xalan XSL transformer can work without X11 display on JDK 1.4+ +# It also looks like the default heap size of 64M is not enough for most cases +# so the maximum heap size is set to 128M +if [ -z "$JAVA_OPTS" ]; then + JAVA_OPTS="-Djava.awt.headless=true -Xmx128M" +fi + +SECURITY="" +if [ "$TOMCAT_SECURITY" = "yes" ]; then + SECURITY="-security" +fi + +# End of variables that can be overwritten in $DEFAULT + +# overwrite settings from default file +if [ -f "$DEFAULT" ]; then + . "$DEFAULT" +fi + +# BP create function for variable +define_variable () { + + if [ ! -f "$CATALINA_HOME/bin/bootstrap.jar" ]; then + log_failure_msg "$NAME is not installed" + exit 1 + fi + + POLICY_CACHE="$CATALINA_BASE/work/catalina.policy" + + if [ -z "$CATALINA_TMPDIR" ]; then + CATALINA_TMPDIR="$JVM_TMP" + fi + + # Set the JSP compiler if set in the tomcat.default file + if [ -n "$JSP_COMPILER" ]; then + JAVA_OPTS="$JAVA_OPTS -Dbuild.compiler=\"$JSP_COMPILER\"" + fi + + # Define other required variables + CATALINA_PID="/var/run/$NAME.pid" + CATALINA_SH="$CATALINA_HOME/bin/catalina.sh" +} + +# Look for Java Secure Sockets Extension (JSSE) JARs +if [ -z "${JSSE_HOME}" -a -r "${JAVA_HOME}/jre/lib/jsse.jar" ]; then + JSSE_HOME="${JAVA_HOME}/jre/" +fi + +catalina_sh() { + # Escape any double quotes in the value of JAVA_OPTS + JAVA_OPTS="$(echo $JAVA_OPTS | sed 's/\"/\\\"/g')" + + AUTHBIND_COMMAND="" + if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then + JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true" + AUTHBIND_COMMAND="/usr/bin/authbind --deep /bin/bash -c " + fi + + # Define the command to run Tomcat's catalina.sh as a daemon + # set -a tells sh to export assigned variables to spawned shells. + TOMCAT_SH="set -a; JAVA_HOME=\"$JAVA_HOME\"; source \"$DEFAULT\"; \ + CATALINA_HOME=\"$CATALINA_HOME\"; \ + CATALINA_BASE=\"$CATALINA_BASE\"; \ + JAVA_OPTS=\"$JAVA_OPTS\"; \ + CATALINA_PID=\"$CATALINA_PID\"; \ + CATALINA_TMPDIR=\"$CATALINA_TMPDIR\"; \ + LANG=\"$LANG\"; JSSE_HOME=\"$JSSE_HOME\"; \ + cd \"$CATALINA_BASE\"; \ + \"$CATALINA_SH\" $@" + + if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then + TOMCAT_SH="'$TOMCAT_SH'" + fi + + # Run the catalina.sh script as a daemon + set +e + touch "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out + chown $TOMCAT_USER "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out + start-stop-daemon --start -b -u "$TOMCAT_USER" -g "$TOMCAT_GROUP" \ + -c "$TOMCAT_USER" -d "$CATALINA_TMPDIR" -p "$CATALINA_PID" \ + -x /bin/bash -- -c "$AUTHBIND_COMMAND $TOMCAT_SH" + status="$?" + set +a -e + return $status +} + +# BP create function for action +do_action () { +case "$1" in + start) + if [ -z "$JAVA_HOME" ]; then + log_failure_msg "no JDK found - please set JAVA_HOME" + exit 1 + fi + + if [ ! -d "$CATALINA_BASE/conf" ]; then + log_failure_msg "invalid CATALINA_BASE: $CATALINA_BASE" + exit 1 + fi + + log_daemon_msg "Starting $NAME" "$NAME" + if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ + --user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \ + >/dev/null; then + + # Regenerate POLICY_CACHE file + umask 022 + if [ -d /etc/tomcat/policy.d/ ]; then + echo "// AUTO-GENERATED FILE from /etc/tomcat/policy.d/" \ + > "$POLICY_CACHE" + echo "" >> "$POLICY_CACHE" + cat $CATALINA_BASE/conf/policy.d/*.policy \ + >> "$POLICY_CACHE" + fi + + # Remove / recreate JVM_TMP directory + rm -rf "$JVM_TMP" + mkdir -p "$JVM_TMP" || { + log_failure_msg "could not create JVM temporary directory" + exit 1 + } + chown $TOMCAT_USER "$JVM_TMP" + + catalina_sh start $SECURITY + sleep 5 + if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ + --user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \ + >/dev/null; then + if [ -f "$CATALINA_PID" ]; then + rm -f "$CATALINA_PID" + fi + log_end_msg 1 + else + log_end_msg 0 + fi + else + log_progress_msg "(already running)" + log_end_msg 0 + fi + ;; + stop) + log_daemon_msg "Stopping $NAME" "$NAME" + + set +e + if [ -f "$CATALINA_PID" ]; then + start-stop-daemon --stop --pidfile "$CATALINA_PID" \ + --user "$TOMCAT_USER" \ + --retry=TERM/20/KILL/5 >/dev/null + if [ $? -eq 1 ]; then + log_progress_msg "$NAME is not running but pid file exists, cleaning up" + elif [ $? -eq 3 ]; then + PID="`cat $CATALINA_PID`" + log_failure_msg "Failed to stop $NAME (pid $PID)" + exit 1 + fi + rm -f "$CATALINA_PID" + rm -rf "$JVM_TMP" + else + log_progress_msg "(not running)" + fi + log_end_msg 0 + set -e + ;; + status) + set +e + start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ + --user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \ + >/dev/null 2>&1 + if [ "$?" = "0" ]; then + + if [ -f "$CATALINA_PID" ]; then + log_success_msg "$NAME is not running, but pid file exists." + exit 1 + else + log_success_msg "$NAME is not running." + exit 3 + fi + else + log_success_msg "$NAME is running with pid `cat $CATALINA_PID`" + fi + set -e + ;; + restart|force-reload) + if [ -f "$CATALINA_PID" ]; then + do_action stop + sleep 1 + fi + do_action start + ;; + try-restart) + if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ + --user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \ + >/dev/null; then + do_action start + fi + ;; + *) + log_failure_msg "Usage: $0 {start|stop|restart|try-restart|force-reload|status} {6|7|all} {stable|staging|latest|all}" + exit 1 + ;; +esac +} + +if [ "$#" -lt 1 ]; then + log_failure_msg "Usage: $0 {start|stop|restart|try-restart|force-reload|status} {6|7|all (default)} {stable|staging|latest|all (default)}" + exit 1 +fi + +# ACTION +ACTION=$1 +# 6|7|all +TOMCAT_VERSION=${2:-all} +TOMCAT_VERSION=${TOMCAT_VERSION/all/6 7} +# stable|staging|latest|all +TOMCAT_INSTANCE=${3:-all} +TOMCAT_INSTANCE=${TOMCAT_INSTANCE/all/stable staging latest} + +stable=1 +staging=2 +latest=3 + +for v in $TOMCAT_VERSION; do + for i in $TOMCAT_INSTANCE; do + +#echo "version to test : $v" +#echo "instance to test : $i" + + NAME=tomcat-$v-$i + CATALINA_HOME=/opt/apache-tomcat-$v + CATALINA_BASE=/var/local/demo/tomcat/tomcat-$v-$i + JVM_TMP=/tmp/tomcat-$v-$i-tmp + TOMCAT_WRITABLE_DIR="$CATALINA_BASE/webapps $CATALINA_BASE/work $CATALINA_BASE/logs" + + # creation du repertoire CATALINA_BASE si besoin + mkdir -p $TOMCAT_WRITABLE_DIR + if [ ! -d "$CATALINA_BASE/conf" ]; then + cp -a $CATALINA_HOME/conf $CATALINA_BASE + # TODO faire modif port, user et utf + sed -i "s/8005/180$v${!i}/g" $CATALINA_BASE/conf/server.xml + sed -i "s/8080/188$v${!i}/g" $CATALINA_BASE/conf/server.xml + sed -i "s/8443/184$v${!i}/g" $CATALINA_BASE/conf/server.xml + sed -i "s/8009/189$v${!i}/g" $CATALINA_BASE/conf/server.xml + fi + chown -R root.$TOMCAT_GROUP $CATALINA_BASE + chmod -R g+r $CATALINA_BASE + chmod -R g+w $TOMCAT_WRITABLE_DIR + + define_variable +#echo "$ACTION $CATALINA_HOME $CATALINA_BASE $CATALINA_SH" + do_action $ACTION + done +done + +exit 0 Property changes on: demo-tools/tomcat/tomcat-init.d ___________________________________________________________________ Added: svn:executable + *