This is an automated email from the ASF dual-hosted git repository. bhaisaab pushed a commit to branch CLOUDSTACK-10012 in repository https://gitbox.apache.org/repos/asf/cloudstack.git
commit 5594e22319efb9e3bc3828c9e657410af25b5e09 Author: Marc-Aurèle Brothier <m...@brothier.org> AuthorDate: Fri Jul 28 08:17:56 2017 +0200 CLOUDSTACK-10012: Introduce Embedded Jetty with shaded jar - Changes packaging to shaded jar - Introduced embedded jetty - Updates jetty dependencies version 9.2 (java 7+) - Initial changes to debian config files - Initial removal of tomcat dependency - Introduce ServerDaemon class with customizations --- client/pom.xml | 233 ++++++++++++++++----- client/src/org/apache/cloudstack/ServerDaemon.java | 205 ++++++++++++++++++ debian/cloudstack-management.install | 13 -- debian/cloudstack-management.postinst | 20 -- debian/control | 2 +- debian/rules | 10 +- packaging/debian/init/cloud-management | 111 ++++------ pom.xml | 36 ++++ 8 files changed, 460 insertions(+), 170 deletions(-) diff --git a/client/pom.xml b/client/pom.xml index 2b52833..3b854e6 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -13,7 +13,7 @@ <modelVersion>4.0.0</modelVersion> <artifactId>cloud-client-ui</artifactId> <name>Apache CloudStack Client UI</name> - <packaging>war</packaging> + <packaging>jar</packaging> <parent> <groupId>org.apache.cloudstack</groupId> <artifactId>cloudstack</artifactId> @@ -29,39 +29,83 @@ <dependencies> <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-servlet</artifactId> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-servlets</artifactId> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-jmx</artifactId> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-util</artifactId> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-webapp</artifactId> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-annotations</artifactId> + </dependency> + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <scope>runtime</scope> + </dependency> + <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-framework-spring-module</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-framework-spring-lifecycle</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-storage-volume-solidfire</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-storage-volume-cloudbyte</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-server</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-acl-static-role-based</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-acl-dynamic-role-based</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> @@ -72,146 +116,175 @@ <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-dedicated-resources</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-api-limit-account-based</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-api-discovery</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-user-authenticator-ldap</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-user-authenticator-md5</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-user-authenticator-pbkdf2</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-user-authenticator-plaintext</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-user-authenticator-saml2</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-user-authenticator-sha256salted</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-metrics</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-network-nvp</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-network-contrail</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-network-palo-alto</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-network-netscaler</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> - <groupId>org.apache.cloudstack</groupId> + <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-network-ovs</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-network-elb</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-network-bigswitch</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-network-ssp</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-network-internallb</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-network-vxlan</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-network-opendaylight</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-network-vcs</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-network-vsp</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-hypervisor-xenserver</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-hypervisor-baremetal</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-hypervisor-ucs</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-hypervisor-ovm</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-hypervisor-ovm3</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-hypervisor-kvm</artifactId> <version>${project.version}</version> + <scope>runtime</scope> <exclusions> <exclusion> <groupId>org.mortbay.jetty</groupId> @@ -223,46 +296,55 @@ <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-hypervisor-hyperv</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-storage-allocator-random</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-planner-user-dispersing</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-planner-skip-heurestics</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-planner-user-concentrated-pod</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-planner-implicit-dedication</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-explicit-dedication</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-host-allocator-random</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-outofbandmanagement-driver-ipmitool</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> @@ -273,16 +355,19 @@ <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-mom-rabbitmq</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-mom-inmemory</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-mom-kafka</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> @@ -293,126 +378,151 @@ <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-framework-ipc</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-framework-quota</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-framework-rest</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-engine-api</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-engine-components-api</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-engine-network</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-engine-orchestration</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-engine-schema</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-engine-storage</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-engine-storage-cache</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-controller-secondary-storage</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-engine-storage-image</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-engine-storage-datamotion</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-engine-storage-snapshot</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-engine-storage-volume</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-storage-volume-default</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-storage-image-default</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-storage-image-s3</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-storage-image-swift</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-syslog-alerts</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-snmp-alerts</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-host-anti-affinity</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-api-solidfire-intg-test</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-network-globodns</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-database-quota</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.cloudstack</groupId> @@ -442,34 +552,17 @@ </executions> </plugin> <plugin> - <groupId>com.googlecode.todomap</groupId> - <artifactId>maven-jettygzip-plugin</artifactId> - <version>0.0.4</version> - <configuration> - <webappDirectory>${project.build.directory}/generated-webapp</webappDirectory> - <outputDirectory>${project.build.directory}/generated-webapp</outputDirectory> - </configuration> - <executions> - <execution> - <phase>prepare-package</phase> - <goals> - <goal>process</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-war-plugin</artifactId> - <version>2.5</version> + <artifactId>maven-jar-plugin</artifactId> <configuration> - <webXml>./target/generated-webapp/WEB-INF/web.xml</webXml> - <warSourceDirectory>./target/generated-webapp</warSourceDirectory> <archive> <manifest> - <addDefaultImplementationEntries>true</addDefaultImplementationEntries> + <mainClass>org.apache.cloudstack.ServerDaemon</mainClass> </manifest> <manifestEntries> + <X-Git-Branch>${git.branch}</X-Git-Branch> + <X-Git-Tag>${git.tag}</X-Git-Tag> + <X-Git-Revision>${git.revision}</X-Git-Revision> <Implementation-Revision>${git.revision}</Implementation-Revision> <Implementation-Branch>${git.branch}</Implementation-Branch> </manifestEntries> @@ -515,15 +608,6 @@ </configuration> </plugin> <plugin> - <groupId>org.apache.tomcat.maven</groupId> - <artifactId>tomcat7-maven-plugin</artifactId> - <configuration> - <path>/client</path> - <tomcatWebXml>${basedir}/WEB-INF/web.xml</tomcatWebXml> - <warSourceDirectory>${project.build.directory}/generated-webapp/</warSourceDirectory> - </configuration> - </plugin> - <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> @@ -534,36 +618,20 @@ </goals> <configuration> <target> - <copy todir="${basedir}/target/generated-webapp/WEB-INF/classes/scripts"> + <copy todir="${project.build.directory}/classes/scripts"> <fileset dir="${basedir}/../scripts"/> </copy> <!-- CLOUDSTACK-1304 --> <chmod perm="755" - file="${basedir}/target/generated-webapp/WEB-INF/classes/scripts/**" type="both"/> - <copy todir="${basedir}/target/generated-webapp/WEB-INF/"> + file="${project.build.directory}/classes/scripts/**" type="both"/> + <copy todir="${project.build.directory}/classes/META-INF/webapp/WEB-INF/"> <fileset dir="${basedir}/WEB-INF/"> <include name="web.xml"/> </fileset> </copy> - <copy todir="${basedir}/target/generated-webapp"> + <copy todir="${project.build.directory}/classes/META-INF/webapp"> <fileset dir="${basedir}/../ui"/> </copy> - <copy overwrite="true" todir="${basedir}/target/generated-webapp/WEB-INF/classes"> - <fileset dir="${basedir}/tomcatconf"> - <include name="*.in"/> - </fileset> - <globmapper from="*.in" to="*"/> - <filterchain> - <filterreader classname="org.apache.tools.ant.filters.ReplaceTokens"> - <param type="propertiesfile" value="${cs.replace.properties}"/> - </filterreader> - </filterchain> - </copy> - <copy overwrite="true" todir="${basedir}/target/generated-webapp/WEB-INF/classes"> - <fileset dir="${basedir}/tomcatconf"> - <exclude name="*.in"/> - </fileset> - </copy> <copy overwrite="true" todir="${basedir}/target/utilities/bin"> <fileset dir="${basedir}/../setup/bindir"> <include name="*.in"/> @@ -675,11 +743,10 @@ <outputDirectory>${project.build.directory}/pythonlibs</outputDirectory> </artifactItem> <artifactItem> - <groupId>org.jasypt</groupId> - <artifactId>jasypt</artifactId> - <version>1.9.2</version> + <groupId>org.bouncycastle</groupId> + <artifactId>bcprov-jdk15on</artifactId> <overWrite>false</overWrite> - <outputDirectory>${project.build.directory}/pythonlibs</outputDirectory> + <outputDirectory>${project.build.directory}</outputDirectory> </artifactItem> </artifactItems> </configuration> @@ -697,6 +764,58 @@ </execution> </executions> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.0.0</version> + <executions> + <execution> + <id>rebuild-war</id> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <createDependencyReducedPom>false</createDependencyReducedPom> + <artifactSet> + <includes> + <include>*:*</include> + </includes> + <excludes> + <exclude>junit:junit</exclude> + <exclude>org.bouncycastle:bcprov-jdk15on</exclude> + </excludes> + </artifactSet> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" /> + <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> + <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + <mainClass>org.apache.cloudstack.ServerDaemon</mainClass> + </transformer> + <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> + <resource>META-INF/spring.handlers</resource> + </transformer> + <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> + <resource>META-INF/spring.schemas</resource> + </transformer> + </transformers> + <filters> + <filter> + <artifact>*:*</artifact> + <excludes> + <exclude>META-INF/VERSION.txt</exclude> + <exclude>META-INF/LICENSE.txt</exclude> + <exclude>META-INF/*.SF</exclude> + <exclude>META-INF/*.DSA</exclude> + <exclude>META-INF/*.RSA</exclude> + <exclude>META-INF/MANIFEST.MF</exclude> + </excludes> + </filter> + </filters> + </configuration> + </execution> + </executions> + </plugin> </plugins> </build> <profiles> diff --git a/client/src/org/apache/cloudstack/ServerDaemon.java b/client/src/org/apache/cloudstack/ServerDaemon.java new file mode 100644 index 0000000..fb213e3 --- /dev/null +++ b/client/src/org/apache/cloudstack/ServerDaemon.java @@ -0,0 +1,205 @@ +// +// 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. +// +package org.apache.cloudstack; + +import org.apache.commons.daemon.Daemon; +import org.apache.commons.daemon.DaemonContext; +import org.eclipse.jetty.jmx.MBeanContainer; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.NCSARequestLog; +import org.eclipse.jetty.server.NetworkTrafficServerConnector; +import org.eclipse.jetty.server.RequestLog; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.HandlerCollection; +import org.eclipse.jetty.server.handler.HandlerList; +import org.eclipse.jetty.server.handler.RequestLogHandler; +import org.eclipse.jetty.util.thread.QueuedThreadPool; +import org.eclipse.jetty.util.thread.ThreadPool; +import org.eclipse.jetty.webapp.Configuration; +import org.eclipse.jetty.webapp.WebAppContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.lang.management.ManagementFactory; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +/*** + * Daemon server class to start the embedded server, either through JSVC or directly inside a JAR. + * Parameter to configure the jetty server are: + * - jetty.port: to start jetty on the specific port (default: 8080) + * - jetty.host: to bind to specific interface (default: null = all) + * - jetty.requestlog: path to log file for requests (default: request.log) + */ +public class ServerDaemon implements Daemon { + private static final Logger logger = LoggerFactory.getLogger(ServerDaemon.class); + private static final String WEB_XML = "META-INF/webapp/WEB-INF/web.xml"; + private static final String REQUEST_LOG = "request.log"; + + private Server jettyServer; + private int port; + private String bindInterface; + private String requestLogFile; + private String webAppLocation; + + public static void main(String... anArgs) throws Exception { + ServerDaemon csServer = new ServerDaemon(); + csServer.init(null); + csServer.start(); + csServer.join(); + } + + @Override + public void init(DaemonContext context) { + Properties props = System.getProperties(); + setPort(Integer.parseInt(props.getProperty("port", "8080"))); + setBindInterface(props.getProperty("host")); + setWebAppLocation(props.getProperty("webapp")); + setRequestLogFile(props.getProperty("requestlog", REQUEST_LOG)); + StringBuilder sb = new StringBuilder("Initializing server daemon on "); + sb.append(bindInterface == null ? "*" : bindInterface); + sb.append(":"); + sb.append(port); + logger.info(sb.toString()); + } + + @Override + public void start() throws Exception { + jettyServer = new Server(createThreadPool()); + + // Setup JMX + MBeanContainer mbeanContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer()); + jettyServer.addBean(mbeanContainer); + + NetworkTrafficServerConnector connector = createConnector(); + jettyServer.addConnector(connector); + + // This webapp will use jsps and jstl. We need to enable the + // AnnotationConfiguration in order to correctly + // set up the jsp container + Configuration.ClassList classlist = Configuration.ClassList + .setServerDefault( jettyServer ); + classlist.addBefore( + "org.eclipse.jetty.webapp.JettyWebXmlConfiguration", + "org.eclipse.jetty.annotations.AnnotationConfiguration" ); + + + + jettyServer.setHandler(createHandlers()); + jettyServer.setStopAtShutdown(true); + + jettyServer.start(); + } + + public void join() throws InterruptedException { + jettyServer.join(); + } + + @Override + public void stop() throws Exception { + jettyServer.stop(); + } + + @Override + public void destroy() { + jettyServer.destroy(); + } + + public void setPort(int port) { + this.port = port; + } + + public void setBindInterface(String bindInterface) { + this.bindInterface = bindInterface; + } + + public void setRequestLogFile(String requestLogFile) { + this.requestLogFile = requestLogFile; + } + + public void setWebAppLocation(String webAppLocation) { + this.webAppLocation = webAppLocation; + } + + private ThreadPool createThreadPool() { + QueuedThreadPool threadPool = new QueuedThreadPool(); + threadPool.setMinThreads(10); + threadPool.setMaxThreads(100); + return threadPool; + } + + private NetworkTrafficServerConnector createConnector() { + NetworkTrafficServerConnector connector = new NetworkTrafficServerConnector(jettyServer); + connector.setPort(port); + connector.setHost(bindInterface); + return connector; + } + + private HandlerCollection createHandlers() { + WebAppContext webapp = new WebAppContext(); + webapp.setContextPath("/client"); + + if (webAppLocation == null) { + webapp.setWar(getShadedWarUrl()); + } else { + webapp.setWar(webAppLocation); + } + + List<Handler> handlers = new ArrayList<>(); + handlers.add(webapp); + + HandlerList contexts = new HandlerList(); + contexts.setHandlers(handlers.toArray(new Handler[0])); + + RequestLogHandler log = new RequestLogHandler(); + log.setRequestLog(createRequestLog()); + + HandlerCollection result = new HandlerCollection(); + result.setHandlers(new Handler[]{log, contexts}); + + return result; + } + + private RequestLog createRequestLog() { + NCSARequestLog log = new NCSARequestLog(); + File logPath = new File(requestLogFile); + File parentFile = logPath.getParentFile(); + if (parentFile != null) { + parentFile.mkdirs(); + } + + log.setFilename(logPath.getPath()); + log.setAppend(true); + log.setLogTimeZone("GMT"); + log.setLogLatency(true); + return log; + } + + private URL getResource(String aResource) { + return Thread.currentThread().getContextClassLoader().getResource(aResource); + } + + private String getShadedWarUrl() { + String urlStr = getResource(WEB_XML).toString(); + return urlStr.substring(0, urlStr.length() - 15); + } +} diff --git a/debian/cloudstack-management.install b/debian/cloudstack-management.install index 9c3f04e..353813d 100644 --- a/debian/cloudstack-management.install +++ b/debian/cloudstack-management.install @@ -15,25 +15,12 @@ # specific language governing permissions and limitations # under the License. -/etc/cloudstack/management/catalina.policy -/etc/cloudstack/management/catalina.properties -/etc/cloudstack/management/logging.properties /etc/cloudstack/management/ehcache.xml -/etc/cloudstack/management/server-ssl.xml -/etc/cloudstack/management/server-nonssl.xml -/etc/cloudstack/management/server7-ssl.xml -/etc/cloudstack/management/server7-nonssl.xml -/etc/cloudstack/management/classpath.conf /etc/cloudstack/management/db.properties -/etc/cloudstack/management/tomcat6-ssl.conf -/etc/cloudstack/management/tomcat6-nonssl.conf -/etc/cloudstack/management/tomcat6.conf /etc/cloudstack/management/web.xml /etc/cloudstack/management/environment.properties /etc/cloudstack/management/java.security.ciphers /etc/cloudstack/management/log4j-cloud.xml -/etc/cloudstack/management/tomcat-users.xml -/etc/cloudstack/management/context.xml /etc/default/cloudstack-management /etc/init.d/cloudstack-management /etc/security/limits.d/cloudstack-limits.conf diff --git a/debian/cloudstack-management.postinst b/debian/cloudstack-management.postinst index 5c9a7fa..4caeab4 100644 --- a/debian/cloudstack-management.postinst +++ b/debian/cloudstack-management.postinst @@ -58,26 +58,6 @@ if [ "$1" = configure ]; then chmod 0640 ${CONFDIR}/${DBPROPS} chgrp cloud ${CONFDIR}/${DBPROPS} - if [ -d "/usr/share/tomcat7" ]; then - rm -f /usr/share/cloudstack-management/bin - rm -f /usr/share/cloudstack-management/lib - ln -s /usr/share/tomcat7/bin /usr/share/cloudstack-management/bin - ln -s /usr/share/tomcat7/lib /usr/share/cloudstack-management/lib - invoke-rc.d tomcat7 stop || true - if [ ! -f "/etc/cloudstack/management/server.xml" ]; then - ln -s /etc/cloudstack/management/server7-nonssl.xml /etc/cloudstack/management/server.xml - fi - elif [ -d "/usr/share/tomcat6" ]; then - rm -f /usr/share/cloudstack-management/bin - rm -f /usr/share/cloudstack-management/lib - ln -s /usr/share/tomcat6/bin /usr/share/cloudstack-management/bin - ln -s /usr/share/tomcat6/lib /usr/share/cloudstack-management/lib - invoke-rc.d tomcat6 stop || true - if [ ! -f "/etc/cloudstack/management/server.xml" ]; then - ln -s /etc/cloudstack/management/server-nonssl.xml /etc/cloudstack/management/server.xml - fi - fi - # Add jdbc MySQL driver settings to db.properties if not present grep -s -q "db.cloud.driver=jdbc:mysql" ${CONFDIR}/${DBPROPS} || sed -i -e "\$adb.cloud.driver=jdbc:mysql" ${CONFDIR}/${DBPROPS} grep -s -q "db.usage.driver=jdbc:mysql" ${CONFDIR}/${DBPROPS} || sed -i -e "\$adb.usage.driver=jdbc:mysql" ${CONFDIR}/${DBPROPS} diff --git a/debian/control b/debian/control index f402325..971b0a8 100644 --- a/debian/control +++ b/debian/control @@ -15,7 +15,7 @@ Description: A common package which contains files which are shared by several C Package: cloudstack-management Architecture: all -Depends: ${python:Depends}, openjdk-8-jre-headless | java8-runtime-headless | java8-runtime | openjdk-7-jre-headless, cloudstack-common (= ${source:Version}), tomcat6 | tomcat7, sudo, jsvc, python-mysql.connector, libmysql-java, augeas-tools, mysql-client, adduser, bzip2, ipmitool, lsb-release, init-system-helpers (>= 1.14~) +Depends: ${python:Depends}, openjdk-8-jre-headless | java8-runtime-headless | java8-runtime | openjdk-7-jre-headless, cloudstack-common (= ${source:Version}), sudo, jsvc, python-mysql.connector, libmysql-java, augeas-tools, mysql-client, adduser, bzip2, ipmitool, lsb-release, init-system-helpers (>= 1.14~) Conflicts: cloud-server, cloud-client, cloud-client-ui Description: CloudStack server library The CloudStack management server diff --git a/debian/rules b/debian/rules index 82a40239..6fc10ad 100755 --- a/debian/rules +++ b/debian/rules @@ -66,7 +66,6 @@ override_dh_auto_install: mkdir -p $(DESTDIR)/$(SYSCONFDIR)/security/limits.d/ mkdir -p $(DESTDIR)/$(SYSCONFDIR)/sudoers.d/ mkdir -p $(DESTDIR)/usr/share/$(PACKAGE)-management - mkdir -p $(DESTDIR)/usr/share/$(PACKAGE)-management/webapps/client mkdir $(DESTDIR)/usr/share/$(PACKAGE)-management/setup mkdir $(DESTDIR)/var/log/$(PACKAGE)/management mkdir $(DESTDIR)/var/cache/$(PACKAGE)/management @@ -76,21 +75,24 @@ override_dh_auto_install: mkdir $(DESTDIR)/var/lib/$(PACKAGE)/management mkdir $(DESTDIR)/var/lib/$(PACKAGE)/mnt cp -r client/target/utilities/scripts/db/* $(DESTDIR)/usr/share/$(PACKAGE)-management/setup/ - cp -r client/target/cloud-client-ui-$(VERSION)/* $(DESTDIR)/usr/share/$(PACKAGE)-management/webapps/client/ cp server/target/conf/* $(DESTDIR)/$(SYSCONFDIR)/$(PACKAGE)/server/ cp client/target/conf/* $(DESTDIR)/$(SYSCONFDIR)/$(PACKAGE)/management/ + cp client/target/cloud-client-ui-$(VERSION).jar $(DESTDIR)/usr/share/$(PACKAGE)-management/ + # To have a uniq name across versions for the startup script + ln -s cloud-client-ui-$(VERSION).jar $(DESTDIR)/usr/share/$(PACKAGE)-management/cloud-management-server.jar + cp client/target/bcprov-jdk15on-1.55.jar $(DESTDIR)/usr/share/$(PACKAGE)-management/ + # To make jetty happy from the 1st line of log + ln -s log4j-cloud.xml $(DESTDIR)/$(SYSCONFDIR)/$(PACKAGE)/management/log4j.xml # nast hack for a couple of configuration files mv $(DESTDIR)/$(SYSCONFDIR)/$(PACKAGE)/server/cloudstack-limits.conf $(DESTDIR)/$(SYSCONFDIR)/security/limits.d/ mv $(DESTDIR)/$(SYSCONFDIR)/$(PACKAGE)/server/cloudstack-sudoers $(DESTDIR)/$(SYSCONFDIR)/sudoers.d/$(PACKAGE) chmod 0440 $(DESTDIR)/$(SYSCONFDIR)/sudoers.d/$(PACKAGE) - ln -s tomcat6-nonssl.conf $(DESTDIR)/$(SYSCONFDIR)/$(PACKAGE)/management/tomcat6.conf install -D packaging/debian/init/cloud-management $(DESTDIR)/$(SYSCONFDIR)/init.d/$(PACKAGE)-management install -D client/target/utilities/bin/cloud-update-xenserver-licenses $(DESTDIR)/usr/bin/cloudstack-update-xenserver-licenses # Remove configuration in /ur/share/cloudstack-management/webapps/client/WEB-INF # This should all be in /etc/cloudstack/management - rm $(DESTDIR)/usr/share/$(PACKAGE)-management/webapps/client/WEB-INF/classes/*.* ln -s ../../..$(SYSCONFDIR)/$(PACKAGE)/management $(DESTDIR)/usr/share/$(PACKAGE)-management/conf ln -s ../../../var/log/$(PACKAGE)/management $(DESTDIR)/usr/share/$(PACKAGE)-management/logs ln -s ../../../var/cache/$(PACKAGE)/management/temp $(DESTDIR)/usr/share/$(PACKAGE)-management/temp diff --git a/packaging/debian/init/cloud-management b/packaging/debian/init/cloud-management index 05c38be..a1d64a8 100755 --- a/packaging/debian/init/cloud-management +++ b/packaging/debian/init/cloud-management @@ -34,9 +34,16 @@ PATH=/bin:/usr/bin:/sbin:/usr/sbin NAME=cloudstack-management DESC="CloudStack-specific Tomcat servlet engine" DAEMON=/usr/bin/jsvc -CATALINA_HOME=/usr/share/cloudstack-management -DEFAULT=/etc/cloudstack/management/tomcat6.conf +MANAGEMENT_HOME=/usr/share/$NAME +MANAGEMENT_CONFIG="/etc/cloudstack/management" JVM_TMP=/tmp/$NAME-temp +USER="cloud" +GROUP="cloud" +UBER_JAR="$MANAGEMENT_HOME/cloud-management-server.jar" +BOOTSTRAP_CLASS="org.apache.cloudstack.ServerDaemon" +MANAGEMENT_PID="/var/run/$NAME.pid" +JSVC_CLASSPATH="/usr/share/java/commons-daemon.jar:$MANAGEMENT_HOME/bcprov-jdk15on-1.55.jar:$MANAGEMENT_CONFIG:/usr/share/$NAME/setup:$MANAGEMENT_HOME:$UBER_JAR" + # We have to explicitly set the HOME variable to the homedir from the user "cloud" # This is because various scripts run by the management server read the HOME variable @@ -60,9 +67,6 @@ fi # The following variables can be overwritten in $DEFAULT -# Run Tomcat 6 as this user ID -TOMCAT6_USER=tomcat6 - # The first existing directory is used for JAVA_HOME (if JAVA_HOME is not # defined in $DEFAULT) JDK_DIRS="/usr/lib/jvm/java-8-openjdk-amd64 /usr/lib/jvm/java-8-openjdk-i386 /usr/lib/jvm/java-8-oracle /usr/lib/jvm/java-8-openjdk" @@ -70,7 +74,7 @@ JDK_DIRS="/usr/lib/jvm/java-8-openjdk-amd64 /usr/lib/jvm/java-8-openjdk-i386 /us # 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" + JAVA_HOME="$jdir" fi done export JAVA_HOME @@ -103,30 +107,17 @@ if [ ! -f "$CATALINA_HOME/bin/bootstrap.jar" ]; then fi [ -f "$DAEMON" ] || exit 0 +[ -r "$UBER_JAR" ] || exit 0 +[ -d "$MANAGEMENT_CONFIG" ] || exit 0 -POLICY_CACHE="$CATALINA_BASE/work/catalina.policy" - -JAVA_OPTS="$JAVA_OPTS -Djava.endorsed.dirs=$CATALINA_HOME/endorsed -Dcatalina.base=$CATALINA_BASE -Dcatalina.home=$CATALINA_HOME -Djava.io.tmpdir=$JVM_TMP" - -# Set the JSP compiler if set in the tomcat6.default file -if [ -n "$JSP_COMPILER" ]; then - JAVA_OPTS="$JAVA_OPTS -Dbuild.compiler=$JSP_COMPILER" -fi - -if [ "$TOMCAT6_SECURITY" = "yes" ]; then - JAVA_OPTS="$JAVA_OPTS -Djava.security.manager -Djava.security.policy=$POLICY_CACHE" -fi +JAVA_OPTS="$JAVA_OPTS -Djava.io.tmpdir=$JVM_TMP" -# Set juli LogManager if logging.properties is provided -if [ -r "$CATALINA_BASE"/conf/logging.properties ]; then - JAVA_OPTS="$JAVA_OPTS "-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" "-Djava.util.logging.config.file="$CATALINA_BASE/conf/logging.properties" +# Load extra arguments from java-opts.conf if any +if [ -r "$MANAGEMENT_CONFIG/java-opts.conf" ]; then + JAVA_EXTRA_OPTS=$(cat $MANAGEMENT_CONFIG/java-opts.conf) + JAVA_OPTS="$JAVA_OPTS $JAVA_EXTRA_OPTS" fi -# Define other required variables -CATALINA_PID="/var/run/$NAME.pid" -BOOTSTRAP_CLASS=org.apache.catalina.startup.Bootstrap -JSVC_CLASSPATH="/usr/share/java/commons-daemon.jar:$CATALINA_HOME/bin/bootstrap.jar:/etc/cloudstack/management:/usr/share/cloudstack-management/setup" - # 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/" @@ -140,25 +131,9 @@ case "$1" in exit 1 fi - if [ ! -d "$CATALINA_BASE/conf" ]; then - log_failure_msg "invalid CATALINA_BASE: $CATALINA_BASE" - exit 1 - fi - log_daemon_msg "Starting $DESC" "$NAME" - if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ - --user $TOMCAT6_USER --startas "$JAVA_HOME/bin/java" \ - >/dev/null; then - - # Regenerate POLICY_CACHE file - umask 022 - echo "// AUTO-GENERATED FILE from /etc/tomcat6/policy.d/" \ - > "$POLICY_CACHE" - echo "" >> "$POLICY_CACHE" - if ls $CATALINA_BASE/conf/policy.d/*.policy > /dev/null 2>&1 ; then - cat $CATALINA_BASE/conf/policy.d/*.policy \ - >> "$POLICY_CACHE" - fi + if start-stop-daemon --test --start --quiet --pidfile "$MANAGEMENT_PID" \ + --user $USER --startas "$JAVA_HOME/bin/java"; then # Remove / recreate JVM_TMP directory rm -rf "$JVM_TMP" @@ -166,48 +141,34 @@ case "$1" in log_failure_msg "could not create JVM temporary directory" exit 1 } - chown $TOMCAT6_USER "$JVM_TMP" - cd "$JVM_TMP" - # fix storage issues on nfs mounts umask 000 - $DAEMON -user "$TOMCAT6_USER" -cp "$JSVC_CLASSPATH" \ - -outfile SYSLOG -errfile SYSLOG \ - -pidfile "$CATALINA_PID" $JAVA_OPTS "$BOOTSTRAP_CLASS" - - sleep 5 - if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ - --user $TOMCAT6_USER --startas "$JAVA_HOME/bin/java" \ - >/dev/null; then - log_end_msg 1 - else - log_end_msg 0 - fi + start-stop-daemon --start --quiet --pidfile "$MANAGEMENT_PID" \ + --user $USER --group $GROUP --exec $DAEMON -- -user "$USER" -server \ + -home "$JAVA_HOME" -cp "$JSVC_CLASSPATH" \ + -outfile SYSLOG -errfile SYSLOG \ + -pidfile "$MANAGEMENT_PID" $JAVA_OPTS "$BOOTSTRAP_CLASS" + log_end_msg $? else - log_progress_msg "(already running)" + log_progress_msg "(already running)" log_end_msg 0 fi ;; stop) log_daemon_msg "Stopping $DESC" "$NAME" - if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ - --user "$TOMCAT6_USER" --startas "$JAVA_HOME/bin/java" \ - >/dev/null; then - log_progress_msg "(not running)" - else - $DAEMON -cp "$JSVC_CLASSPATH" -pidfile "$CATALINA_PID" \ - -stop "$BOOTSTRAP_CLASS" - fi - rm -rf "$JVM_TMP" + start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile "$MANAGEMENT_PID" + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + [ "$RETVAL" = 0 ] && rm -rf "$JVM_TMP" log_end_msg 0 ;; status) - if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ - --user $TOMCAT6_USER --startas "$JAVA_HOME/bin/java" \ + if start-stop-daemon --test --start --pidfile "$$MANAGEMENT_PID" \ + --user $USER --startas "$JAVA_HOME/bin/java" \ >/dev/null; then - if [ -f "$CATALINA_PID" ]; then + if [ -f "$$MANAGEMENT_PID" ]; then log_success_msg "$DESC is not running, but pid file exists." exit 1 else @@ -215,12 +176,12 @@ case "$1" in exit 3 fi else - log_success_msg "$DESC is running with pid `cat $CATALINA_PID`" + log_success_msg "$DESC is running with pid `cat $$MANAGEMENT_PID`" fi ;; restart|force-reload) - if start-stop-daemon --test --stop --pidfile "$CATALINA_PID" \ - --user $TOMCAT6_USER --startas "$JAVA_HOME/bin/java" \ + if start-stop-daemon --test --stop --pidfile "$$MANAGEMENT_PID" \ + --user $USER --startas "$JAVA_HOME/bin/java" \ >/dev/null; then $0 stop sleep 1 diff --git a/pom.xml b/pom.xml index 96fe925..938031c 100644 --- a/pom.xml +++ b/pom.xml @@ -125,6 +125,7 @@ <cs.groovy.version>2.4.7</cs.groovy.version> <cs.nitro.version>10.1</cs.nitro.version> <cs.wiremock.version>2.8.0</cs.wiremock.version> + <cs.jetty.version>9.2.22.v20170606</cs.jetty.version><!-- Java 7+ --> </properties> <distributionManagement> @@ -480,6 +481,41 @@ <artifactId>slf4j-log4j12</artifactId> <version>1.7.22</version> </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + <version>${cs.jetty.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-servlet</artifactId> + <version>${cs.jetty.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-servlets</artifactId> + <version>${cs.jetty.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-webapp</artifactId> + <version>${cs.jetty.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-jmx</artifactId> + <version>${cs.jetty.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-util</artifactId> + <version>${cs.jetty.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-annotations</artifactId> + <version>${cs.jetty.version}</version> + </dependency> </dependencies> </dependencyManagement> -- To stop receiving notification emails like this one, please contact "commits@cloudstack.apache.org" <commits@cloudstack.apache.org>.