| #!/bin/bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| NAME="${SERVICE_NAME:-tomcat}" |
| |
| |
| |
| |
| |
| if [ -x "/sbin/runuser" ]; then |
| SU="/sbin/runuser -s /bin/sh" |
| else |
| SU="/bin/su -s /bin/sh" |
| fi |
| |
| |
| TOMCAT_SCRIPT="/usr/sbin/tomcat-jsvc" |
| |
| |
| TOMCAT_USER="${TOMCAT_USER:-tomcat}" |
| |
| |
| |
| TOMCAT_LOG=/var/log/${NAME}/${NAME}-sysd.log |
| |
| |
| TOMCAT_CFG="/etc/tomcat/tomcat.conf" |
| if [ -r "$TOMCAT_CFG" ]; then |
| . $TOMCAT_CFG |
| fi |
| |
| |
| 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}" |
| } |
| |
| |
| function start() { |
| |
| export CATALINA_PID="/var/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 |
| |
| |
| |
| if [ -x /usr/bin/jsvc ]; then |
| TOMCAT_USER="root" |
| 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() { |
| |
| |
| if [ -x /usr/bin/jsvc ]; then |
| TOMCAT_USER="root" |
| fi |
| |
| parseOptions |
| $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} stop" >> $TOMCAT_LOG 2>&1 |
| } |
| |
| |
| case "$1" in |
| start) |
| start |
| ;; |
| stop) |
| stop |
| ;; |
| restart) |
| stop |
| start |
| ;; |
| esac |
| |