Blame SOURCES/tomcat-7.0-tomcat-jsvc-sysd

262920
#!/bin/bash
262920
#
262920
# This script provides systemd activation of the tomcat service
262920
# To create clones of this service:
262920
# 1) SERVICE_NAME must be defined before calling this script
262920
# 2) Create /etc/sysconfig/${SERVICE_NAME} from /etc/sysconfig/tomcat
262920
# to override tomcat defaults
262920
262920
# SERVICE_NAME is a required value only if the service name is 
262920
# different from 'tomcat'
262920
#
262920
NAME="${SERVICE_NAME:-tomcat}"
262920
262920
#I'll bet this isn't required. 
262920
# unset ISBOOT
262920
262920
# For SELinux we need to use 'runuser' not 'su'
262920
if [ -x "/sbin/runuser" ]; then
262920
    SU="/sbin/runuser -s /bin/sh"
262920
else
262920
    SU="/bin/su -s /bin/sh"
262920
fi
262920
262920
# Path to the tomcat launch script
262920
TOMCAT_SCRIPT="/usr/sbin/tomcat-jsvc"
262920
        
262920
# Define the tomcat username
262920
TOMCAT_USER="${TOMCAT_USER:-tomcat}"
262920
262920
# TOMCAT_LOG should be different from catalina.out.
262920
# Usually the below config is all that is necessary
262920
TOMCAT_LOG=/var/log/${NAME}/${NAME}-sysd.log
262920
262920
# Get the tomcat config (use this for environment specific settings)
262920
TOMCAT_CFG="/etc/tomcat/tomcat.conf"
262920
if [ -r "$TOMCAT_CFG" ]; then
262920
    . $TOMCAT_CFG
262920
fi
262920
262920
# Get instance specific config file
262920
if [ -r "/etc/sysconfig/${NAME}" ]; then
262920
    . /etc/sysconfig/${NAME}
262920
fi
262920
262920
function parseOptions() {
262920
    options=""
262920
    options="$options $(
262920
                 awk '!/^#/ && !/^$/ { ORS=" "; print "export ", $0, ";" }' \
262920
                 $TOMCAT_CFG
262920
             )"
262920
    if [ -r "/etc/sysconfig/${NAME}" ]; then
262920
        options="$options $(
262920
                     awk '!/^#/ && !/^$/ { ORS=" ";
262920
                                           print "export ", $0, ";" }' \
262920
                     /etc/sysconfig/${NAME}
262920
                 )"
262920
    fi
262920
    TOMCAT_SCRIPT="$options ${TOMCAT_SCRIPT}"
262920
}
262920
262920
# See how we were called.
262920
function start() {
262920
    # fix permissions on the log and pid files
262920
    export CATALINA_PID="/var/run/${NAME}.pid"
262920
    touch $CATALINA_PID 2>&1 
262920
    if [ "$?" -eq "0" ]; then
262920
      chown ${TOMCAT_USER}:${TOMCAT_USER} $CATALINA_PID
262920
    fi
262920
262920
    touch $TOMCAT_LOG 2>&1 
262920
    if [ "$?" -eq "0" ]; then
262920
      chown ${TOMCAT_USER}:${TOMCAT_USER} $TOMCAT_LOG
262920
    fi
262920
262920
    # if jsvc installed and USE_JSVC=true
262920
    # then start as root and use jsvc to drop privileges
262920
    if [ -x /usr/bin/jsvc ]; then
262920
      TOMCAT_USER="root"
262920
    fi
262920
262920
    parseOptions  
262920
    if [ "$SECURITY_MANAGER" = "true" ]; then
262920
       $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start-security" >> $TOMCAT_LOG 2>&1 
262920
    else
262920
       $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start" >> $TOMCAT_LOG 2>&1
262920
    fi
262920
}
262920
262920
function stop() {
262920
    # if jsvc installed and USE_JSVC=true
262920
    # then start as root and use jsvc to drop privileges
262920
    if [ -x /usr/bin/jsvc ]; then
262920
      TOMCAT_USER="root"
262920
    fi
262920
262920
    parseOptions  
262920
    $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} stop" >> $TOMCAT_LOG 2>&1
262920
}
262920
262920
# See how we were called.
262920
case "$1" in
262920
    start)
262920
        start
262920
        ;;
262920
    stop)
262920
        stop
262920
        ;;
262920
    restart)
262920
        stop
262920
        start
262920
        ;;
262920
esac
262920