From 91d04c64771832a0b8815ffbe1f0f9920320d94d Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Tue, 14 Feb 2017 19:41:00 -0500 Subject: Initial OpenECOMP policy/engine commit Change-Id: I7dbff37733b661643dd4d1caefa3d7dccc361b6e Signed-off-by: Pamela Dragosh --- .../servers/common/logparser/init.d/logparserd | 131 ++++++++++++++++ .../install/servers/common/tomcat/bin/setenv.sh | 31 ++++ .../install/servers/common/tomcat/conf/server.xml | 167 +++++++++++++++++++++ .../install/servers/common/tomcat/init.d/tomcatd | 91 +++++++++++ 4 files changed, 420 insertions(+) create mode 100755 packages/base/src/files/install/servers/common/logparser/init.d/logparserd create mode 100644 packages/base/src/files/install/servers/common/tomcat/bin/setenv.sh create mode 100644 packages/base/src/files/install/servers/common/tomcat/conf/server.xml create mode 100644 packages/base/src/files/install/servers/common/tomcat/init.d/tomcatd (limited to 'packages/base/src/files/install/servers/common') diff --git a/packages/base/src/files/install/servers/common/logparser/init.d/logparserd b/packages/base/src/files/install/servers/common/logparser/init.d/logparserd new file mode 100755 index 000000000..37221b9c3 --- /dev/null +++ b/packages/base/src/files/install/servers/common/logparser/init.d/logparserd @@ -0,0 +1,131 @@ +#!/bin/bash +# +# init script for a Java application +# + +function update_monitor() { + COMPONENT=$1 + STATUS=$2 + if [[ -f ${POLICY_HOME}/etc/monitor/monitor.cfg ]]; then + /bin/sed -i.bak \ + -e "s/^${COMPONENT}=.*/${COMPONENT}=${STATUS}/g" \ + ${POLICY_HOME}/etc/monitor/monitor.cfg + fi +} + +# unmonitored start, does not change monitor status (immutable) +function um_start() { + JMX_JAVA_OPTS="-Dcom.sun.management.jmxremote" + JMX_JAVA_OPTS="${JMX_JAVA_OPTS} -Dcom.sun.management.jmxremote.port=${LOGPARSER_JMX_PORT}" + JMX_JAVA_OPTS="${JMX_JAVA_OPTS} -Dcom.sun.management.jmxremote.ssl=false" + JMX_JAVA_OPTS="${JMX_JAVA_OPTS} -Dcom.sun.management.jmxremote.authenticate=false" + JVM_JAVA_OPTS="-Xms${LOGPARSER_X_MS_MB}M -Xmx${LOGPARSER_X_MX_MB}M" + + JAVA_OPTS="${JAVA_OPTS} ${JMX_JAVA_OPTS} ${JVM_JAVA_OPTS}" + + # Redirects default and error output to a log file + cd ${POLICY_HOME}/servers/${COMPONENT}/bin + nohup $JAVA_HOME/bin/java -jar ${JAVA_OPTS} ${SERVICE} ${SERVER} ${LOGTYPE} >> ${POLICY_HOME}/servers/${COMPONENT}/logs/stdout 2>&1 & +RETVAL=$? + RETVAL=$? +} + +# Starts the application +function start() { + um_start + if [[ ${RETVAL} != 0 ]]; then + update_monitor ${COMPONENT} off + else + update_monitor ${COMPONENT} on + fi +} + +# unmonitored stop, does not change monitor status (immutable) +function um_stop() { + # Kills the application process + pkill -u ${POLICY_USER} -f "${SERVICE} ${SERVER} ${LOGTYPE}" -TERM + RETVAL=$? + if [[ ${RETVAL} != 0 ]]; then + sleep 2 + pkill -u ${POLICY_USER} -f "${SERVICE} ${SERVER} ${LOGTYPE}" -KILL + RETVAL=$? + fi +} + +# Stops the application +function stop() { + um_stop + update_monitor ${COMPONENT} off +} + +# Show the application status +function status() { + # check status + pid=$(pgrep -f -u ${POLICY_USER} "${SERVICE} ${SERVER} ${LOGTYPE}" 2> /dev/null) + RETVAL=$? + + # If the PID was returned means the application is running + if [ ${RETVAL} -eq 0 ] ; then + echo "running with pid ${pid}" + else + echo "stopped" + fi +} + +# Main logic, a simple case to call functions + +# determine if this is a paplp or pdplp component +COMPONENT=$(basename $0) + +CONF_FILE="${POLICY_HOME}/servers/${COMPONENT}/bin/parserlog.properties" +SERVICE="${POLICY_HOME}/servers/${COMPONENT}/bin/logparser.jar" + +# read properties +shopt -s extglob +configfile="dos_or_unix" # set the actual path name of your (DOS or Unix) config file +while IFS='= ' read lhs rhs +do + if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then + rhs="${rhs%%\#*}" # Del in line right comments + rhs="${rhs%%*( )}" # Del trailing spaces + rhs="${rhs%\"*}" # Del opening string quotes + rhs="${rhs#\"*}" # Del closing string quotes + if [[ $lhs != *"."* ]]; then + declare $lhs="$rhs" + fi + fi +done < "${CONF_FILE}" +if [ $? -ne 0 ]; then + echo "error: cannot source configuration ${CONF_FILE}" + exit 1 +fi + +case "$1" in + status) + status + ;; + restart) + stop + sleep 2 + start + ;; + start) + start + ;; + umstart) + um_start + ;; + stop) + stop + ;; + umstop) + um_stop + ;; + *) + echo "Usage: $0 {start|stop|umstart|umstop|restart|status}" + RETVAL=1 + ;; +esac + +exit ${RETVAL} + diff --git a/packages/base/src/files/install/servers/common/tomcat/bin/setenv.sh b/packages/base/src/files/install/servers/common/tomcat/bin/setenv.sh new file mode 100644 index 000000000..154b2a544 --- /dev/null +++ b/packages/base/src/files/install/servers/common/tomcat/bin/setenv.sh @@ -0,0 +1,31 @@ +### +# ============LICENSE_START======================================================= +# ECOMP Policy Engine +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed 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. +# ============LICENSE_END========================================================= +### + +CATALINA_OPTS="${CATALINA_OPTS} -Dcom.sun.management.jmxremote" +CATALINA_OPTS="${CATALINA_OPTS} -Dcom.sun.management.jmxremote.port=${{TOMCAT_JMX_PORT}}" +CATALINA_OPTS="${CATALINA_OPTS} -Dcom.sun.management.jmxremote.ssl=false" +CATALINA_OPTS="${CATALINA_OPTS} -Dcom.sun.management.jmxremote.authenticate=false" +CATALINA_OPTS="${CATALINA_OPTS} -Djavax.net.ssl.keyStore=${POLICY_HOME}/etc/ssl/policy-keystore" +CATALINA_OPTS="${CATALINA_OPTS} -Djavax.net.ssl.keyStorePassword=${KEYSTORE_PASSWD}" +CATALINA_OPTS="${CATALINA_OPTS} -Djavax.net.ssl.trustStore=${POLICY_HOME}/etc/ssl/policy-keystore" +CATALINA_OPTS="${CATALINA_OPTS} -Djavax.net.ssl.trustStorePassword=${KEYSTORE_PASSWD}" +CATALINA_OPTS="${CATALINA_OPTS} -Xms${{TOMCAT_X_MS_MB}}M" +CATALINA_OPTS="${CATALINA_OPTS} -Xmx${{TOMCAT_X_MX_MB}}M" +export CATALINA_OPTS diff --git a/packages/base/src/files/install/servers/common/tomcat/conf/server.xml b/packages/base/src/files/install/servers/common/tomcat/conf/server.xml new file mode 100644 index 000000000..e45450024 --- /dev/null +++ b/packages/base/src/files/install/servers/common/tomcat/conf/server.xml @@ -0,0 +1,167 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/base/src/files/install/servers/common/tomcat/init.d/tomcatd b/packages/base/src/files/install/servers/common/tomcat/init.d/tomcatd new file mode 100644 index 000000000..114f8a77e --- /dev/null +++ b/packages/base/src/files/install/servers/common/tomcat/init.d/tomcatd @@ -0,0 +1,91 @@ +#!/bin/bash + +function update_monitor() { + COMPONENT=$1 + STATUS=$2 + if [[ -f ${POLICY_HOME}/etc/monitor/monitor.cfg ]]; then + /bin/sed -i.bak \ + -e "s/^${COMPONENT}=.*/${COMPONENT}=${STATUS}/g" \ + ${POLICY_HOME}/etc/monitor/monitor.cfg + fi +} + +# unmonitored stop, does not change monitor status (immutable) +function um_stop() { + cd ${TOMCAT_BASE}/bin/ + ${TOMCAT_BASE}/bin/catalina.sh stop -force + + # make sure .. + pid=$(pgrep -f -u ${POLICY_USER} "${TOMCAT_RUNNING}" 2> /dev/null) + RETVAL=$? + if [[ ${RETVAL} == 0 ]]; then + pkill -u ${POLICY_USER} -f "${TOMCAT_RUNNING}" -KILL + RETVAL=$? + fi +} + +function stop() { + um_stop + update_monitor ${{COMPONENT_TYPE}} off +} + +# unmonitored start, does not change monitor status (immutable) +function um_start() { + cd ${TOMCAT_BASE}/bin/ + ${TOMCAT_BASE}/bin/catalina.sh start + RETVAL=$? +} + +function start() { + um_start + if [[ ${RETVAL} != 0 ]]; then + update_monitor ${{COMPONENT_TYPE}} off + else + update_monitor ${{COMPONENT_TYPE}} on + fi +} + +TOMCAT_BASE=${POLICY_HOME}/servers/${{COMPONENT_TYPE}} +TOMCAT_RUNNING="^$JAVA_HOME/bin/java .* -Dcatalina.base=${TOMCAT_BASE} .* start$" + +PWD_ENTER=${PWD} +RETVAL=0 + +. ${POLICY_HOME}/etc/profile.d/env.sh + +case "$1" in + status) + pid=$(pgrep -f -u ${POLICY_USER} "${TOMCAT_RUNNING}" 2> /dev/null) + RETVAL=$? + if [ $RETVAL -eq 0 ]; then + echo "running with pid ${pid}" + else + echo "stopped" + fi + ;; + restart) + stop + sleep 2 + start + ;; + start) + start + ;; + umstart) + um_start + ;; + stop) + stop + ;; + umstop) + um_stop + ;; + *) + cd ${TOMCAT_BASE}/bin/ + ${TOMCAT_BASE}/bin/catalina.sh "$@" + RETVAL=$? + ;; +esac + +cd ${PWD_ENTER} +exit ${RETVAL} -- cgit 1.2.3-korg