Yuvipanda has submitted this change and it was merged.

Change subject: Add legacy support for tomcat webservices
......................................................................


Add legacy support for tomcat webservices

Bug: T98442
Change-Id: I5d1f25c180177f23f824d493901f51e76a5bf88f
---
M debian/changelog
A scripts/deprecated-tomcat-starter
M setup.py
M toollabs/webservice/services/__init__.py
A toollabs/webservice/services/tomcatservice.py
M tox.ini
6 files changed, 156 insertions(+), 2 deletions(-)

Approvals:
  Yuvipanda: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/debian/changelog b/debian/changelog
index e2453ee..4efce92 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+toollabs-webservice (0.3) trusty; urgency=low
+
+  * Add support for tomcat webservice
+
+ -- Yuvi Panda <[email protected]>  Mon, 25 Apr 2016 11:30:00 +0530
+
 toollabs-webservice (0.2) trusty; urgency=low
 
   * Write out a version number in service.manifest file
diff --git a/scripts/deprecated-tomcat-starter 
b/scripts/deprecated-tomcat-starter
new file mode 100755
index 0000000..60aeeea
--- /dev/null
+++ b/scripts/deprecated-tomcat-starter
@@ -0,0 +1,132 @@
+#! /bin/bash
+#
+#  Copyright © 2013 Marc-André Pelletier <[email protected]>
+#
+#  Permission to use, copy, modify, and/or distribute this software for any
+#  purpose with or without fee is hereby granted, provided that the above
+#  copyright notice and this permission notice appear in all copies.
+#
+#  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+#  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+#  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+#  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+#  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+#  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+#  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+# Part of this code is derived from catalina.sh distributed with Tomcat:
+#
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#
+# COPIED IN WITH MINOR MODIFICATION FROM ORIGINAL SOURCE CREDITED ABOVE.
+# THIS SHOULD DIE ONCE PEOPEL STOP USING THE TOMCAT WEBSERVICE TYPE,
+# AND SWITCH TO ALTERNATIVES THAT WILL BE PROVIDED AFTERWARDS.
+# AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+tool="$1"
+port="${PORT}" 
+prefix=$(/bin/cat /etc/wmflabs-project)
+user="$prefix.$tool"
+home=$(getent passwd $user | cut -d : -f 6 | sed -e 's/\/$//')
+tomcat="$home/public_tomcat"
+if [ "$(getent group $user | cut -d : -f 1)" != "$user" ]; then
+  echo "$0: $1 does not appear to be a tool" >&2
+  exit 1
+fi
+
+if [ "$home" = "" -o ! -d "$tomcat" ]; then
+  echo "$1 does not have a public_tomcat" >&2
+  exit 1
+fi
+
+conf="$tomcat/conf/server.xml"
+if [ ! -r "$conf" ]; then
+  echo "Unable to read $conf" >&2
+  exit 1
+fi
+
+if [ $(/usr/bin/xmlstarlet sel -t -v "count(/Server/Service/Connector)" 
"$conf") != "1" ]; then
+  echo "$conf must declare exactly one <Connrector> element" >&2
+  exit 1
+fi
+
+/usr/bin/xmlstarlet ed -u "/Server/@port" -v "-1" "$conf" |
+  /usr/bin/xmlstarlet ed -u "/Server/Service/Connector/@port" -v "$port" 
>"$conf.run"
+
+export CATALINA_BASE="/data/project/$tool/public_tomcat"
+export CATALINA_HOME=/usr/share/tomcat7
+export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
+
+if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
+  . "$CATALINA_BASE/bin/setenv.sh"
+elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
+  . "$CATALINA_HOME/bin/setenv.sh"
+fi
+
+if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then
+  . "$CATALINA_HOME"/bin/setclasspath.sh
+else
+  echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh"
+  echo "This file is needed to run this program"
+  exit 1
+fi
+
+# Add on extra jar files to CLASSPATH
+if [ ! -z "$CLASSPATH" ] ; then
+  CLASSPATH="$CLASSPATH":
+fi
+CLASSPATH="$CLASSPATH""$CATALINA_HOME"/bin/bootstrap.jar
+
+if [ -z "$CATALINA_OUT" ] ; then
+  CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
+fi
+
+if [ -z "$CATALINA_TMPDIR" ] ; then
+  # Define the java.io.tmpdir to use for Catalina
+  CATALINA_TMPDIR=/tmp
+fi
+
+# Add tomcat-juli.jar to classpath
+# tomcat-juli.jar can be over-ridden per instance
+if [ -r "$CATALINA_BASE/bin/tomcat-juli.jar" ] ; then
+  CLASSPATH=$CLASSPATH:$CATALINA_BASE/bin/tomcat-juli.jar
+else
+  CLASSPATH=$CLASSPATH:$CATALINA_HOME/bin/tomcat-juli.jar
+fi
+
+# Set juli LogManager config file if it is present and an override has not 
been issued
+if [ -z "$LOGGING_CONFIG" ]; then
+  if [ -r "$CATALINA_BASE"/conf/logging.properties ]; then
+    
LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
+  else
+    # Bugzilla 45585
+    LOGGING_CONFIG="-Dnop"
+  fi
+fi
+
+if [ -z "$LOGGING_MANAGER" ]; then
+  JAVA_OPTS="$JAVA_OPTS 
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
+else
+  JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER"
+fi
+
+JAVA_OPTS="$JAVA_OPTS 
-Dorg.apache.catalina.security.SecurityListener.UMASK=002"
+
+eval exec /usr/bin/java \"$LOGGING_CONFIG\" $JAVA_OPTS $CATALINA_OPTS \
+  -Djava.endorsed.dirs=\"$JAVA_ENDORSED_DIRS\" -classpath \"$CLASSPATH\" \
+  -Dcatalina.base=\"$CATALINA_BASE\" \
+  -Dcatalina.home=\"$CATALINA_HOME\" \
+  -Djava.io.tmpdir=\"$CATALINA_TMPDIR\" \
+  org.apache.catalina.startup.Bootstrap -config "$conf.run" start
diff --git a/setup.py b/setup.py
index d91c81e..2d1d5b1 100644
--- a/setup.py
+++ b/setup.py
@@ -9,6 +9,7 @@
     scripts=[
         'scripts/webservice-runner',
         'scripts/webservice-new',
+        'scripts/deprecated-tomcat-starter',
     ],
     description='Infrastructure for running webservices on tools.wmflabs.org',
     install_requires=[
diff --git a/toollabs/webservice/services/__init__.py 
b/toollabs/webservice/services/__init__.py
index 7389b2c..65701ba 100644
--- a/toollabs/webservice/services/__init__.py
+++ b/toollabs/webservice/services/__init__.py
@@ -3,8 +3,9 @@
 from toollabs.webservice.services.pythonwebservice import PythonWebService
 from toollabs.webservice.services.lighttpdwebservice import 
LighttpdPlainWebService, LighttpdWebService, \
     LighttpdPreciseWebService
+from toollabs.webservice.services.tomcatservice import TomcatWebService
 
 
 webservice_classes = {cls.NAME: cls
-                      for cls in [JSWebService, PythonWebService, 
GenericWebService,
+                      for cls in [JSWebService, PythonWebService, 
GenericWebService, TomcatWebService,
                                   LighttpdWebService, 
LighttpdPreciseWebService, LighttpdPlainWebService]}
diff --git a/toollabs/webservice/services/tomcatservice.py 
b/toollabs/webservice/services/tomcatservice.py
new file mode 100644
index 0000000..a2b070f
--- /dev/null
+++ b/toollabs/webservice/services/tomcatservice.py
@@ -0,0 +1,14 @@
+from toollabs.webservice.services import GenericWebService
+
+
+class TomcatWebService(GenericWebService):
+    NAME = 'tomcat'
+    """
+    Deprecated but backwards compatible tomcat server.
+
+    Just calls the old tomcat-starter code, which does the
+    actual starting.
+    """
+    def __init__(self, tool, extra_args=None):
+        super(GenericWebService, self).__init__(tool, extra_args)
+        self.extra_args = '/usr/bin/deprecated-tomcat-starter ' + 
self.tool.name
diff --git a/tox.ini b/tox.ini
index df9e594..caea4c3 100644
--- a/tox.ini
+++ b/tox.ini
@@ -12,6 +12,6 @@
 basepython = python2.7
 
 [testenv:flake8-bin]
-commands = flake8 --filename=* scripts/
+commands = flake8 --filename=webservice-* scripts/
 deps = flake8
 basepython = python2.7

-- 
To view, visit https://gerrit.wikimedia.org/r/285142
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5d1f25c180177f23f824d493901f51e76a5bf88f
Gerrit-PatchSet: 6
Gerrit-Project: operations/software/tools-webservice
Gerrit-Branch: master
Gerrit-Owner: Yuvipanda <[email protected]>
Gerrit-Reviewer: Yuvipanda <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to