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 f7cc6300b8add1227f1dea76e07d19337c66fa31
Author: Marc-Aurèle Brothier <m...@brothier.org>
AuthorDate: Mon Jul 31 08:11:37 2017 +0200

    Modify cloudtack-amanement init with uber jar startup
---
 packaging/debian/init/cloud-management | 111 +++++++++++----------------------
 1 file changed, 36 insertions(+), 75 deletions(-)

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

-- 
To stop receiving notification emails like this one, please contact
"commits@cloudstack.apache.org" <commits@cloudstack.apache.org>.

Reply via email to