#!/bin/bash BRMSGW_BASE=${POLICY_HOME}/servers/brmsgw/ COMPONENT=brmsgw brmsgw_RUNNING="pgrep -f "${BRMSGW_BASE}"" RETVAL=0 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() { pid=$(pgrep -f "${BRMSGW_BASE}" 2> /dev/null) kill -9 "${pid}" RETVAL=$? } function stop() { um_stop if [[ ${RETVAL} != 0 ]]; then update_monitor ${COMPONENT} on else update_monitor ${COMPONENT} off fi } # unmonitored start, does not change monitor status (immutable) function um_start() { unset JMX_JAVA_OPTS JVM_SECURITY JMX_JAVA_OPTS+=("-Dcom.sun.management.jmxremote") JMX_JAVA_OPTS+=("-Dcom.sun.management.jmxremote.port=$BRMSGW_JMX_PORT") JMX_JAVA_OPTS+=("-Dcom.sun.management.jmxremote.ssl=false") JMX_JAVA_OPTS+=("-Dcom.sun.management.jmxremote.authenticate=false") JVM_JAVA_OPTS=("-Xms${COMPONENT_X_MS_MB}M" "-Xmx${COMPONENT_X_MX_MB}M") JVM_SECURITY+=("-Djavax.net.ssl.keyStore=${POLICY_HOME}/etc/ssl/policy-keystore") JVM_SECURITY+=("-Djavax.net.ssl.keyStorePassword=${KEYSTORE_PASSWD}") JVM_SECURITY+=("-Djavax.net.ssl.trustStore=${POLICY_HOME}/etc/ssl/policy-keystore") JVM_SECURITY+=("-Djavax.net.ssl.trustStorePassword=${KEYSTORE_PASSWD}") JAVA_OPTS=("${JVM_JAVA_OPTS[@]}" "${JMX_JAVA_OPTS[@]}" "${JVM_SECURITY[@]}") cd $POLICY_HOME/servers/brmsgw mkdir -p $POLICY_LOGS/policy/brmsgw 2>/dev/null nohup $JAVA_HOME/bin/java -jar "${JAVA_OPTS[@]}" $POLICY_HOME/servers/brmsgw/BRMSGateway.jar>> $POLICY_LOGS/policy/brmsgw/brmsgw.log 2>&1 & RETVAL=$? } function start() { um_start if [[ ${RETVAL} != 0 ]]; then update_monitor ${COMPONENT} off else update_monitor ${COMPONENT} on fi } function status() { # check status pid=$(pgrep -f "${BRMSGW_BASE}" 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 COMPONENT=$(basename $0) CONF_FILE="${POLICY_HOME}/servers/${COMPONENT}/config.properties" # 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 "error: invalid option $@" RETVAL=1 ;; esac exit ${RETVAL}