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