From 186acca061cd9d6c390704cc7b26a6a75eed9e90 Mon Sep 17 00:00:00 2001 From: Dave Knox Date: Thu, 1 Jul 2010 20:55:12 +0000 Subject: [PATCH] corrections for LSB compliance --- tomcat6-6.0.init | 91 +++++++++++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 32 deletions(-) diff --git a/tomcat6-6.0.init b/tomcat6-6.0.init index 930c0fc..e4e9517 100644 --- a/tomcat6-6.0.init +++ b/tomcat6-6.0.init @@ -141,8 +141,13 @@ function parseOptions() { # See how we were called. function start() { - echo -n "Starting ${TOMCAT_PROG}: " - if [ -f "/var/lock/subsys/${NAME}" ] ; then + + echo -n "Starting ${TOMCAT_PROG}: " + if [ "$RETVAL" != "0" ]; then + log_failure_msg + return + fi + if [ -f "/var/lock/subsys/${NAME}" ]; then if [ -f "/var/run/${NAME}.pid" ]; then read kpid < /var/run/${NAME}.pid # if checkpid $kpid 2>&1; then @@ -157,11 +162,15 @@ function start() { fi # fix permissions on the log and pid files export CATALINA_PID="/var/run/${NAME}.pid" - touch $CATALINA_PID - chown ${TOMCAT_USER}:${TOMCAT_USER} $CATALINA_PID - touch $TOMCAT_LOG - chown ${TOMCAT_USER}:${TOMCAT_USER} $TOMCAT_LOG - if [ "$CATALINA_HOME" != "/usr/share/tomcat6" ]; then + touch $CATALINA_PID 2>&1 || RETVAL="4" + if [ "$RETVAL" -eq "0" -a "$?" -eq "0" ]; then + chown ${TOMCAT_USER}:${TOMCAT_USER} $CATALINA_PID + fi + [ "$RETVAL" -eq "0" ] && touch $TOMCAT_LOG 2>&1 || RETVAL="4" + if [ "$RETVAL" -eq "0" -a "$?" -eq "0" ]; then + chown ${TOMCAT_USER}:${TOMCAT_USER} $TOMCAT_LOG + fi + if [ "$CATALINA_HOME" != "/usr/share/tomcat6" -a "$RETVAL" -eq "0" ]; then # Create a tomcat directory if it doesn't exist makeHomeDir # If CATALINA_HOME doesn't exist modify port number so that @@ -172,37 +181,37 @@ function start() { ${CATALINA_HOME}/conf/server.xml fi parseOptions - if [ "$SECURITY_MANAGER" = "true" ]; then + if [ "$RETVAL" -eq "0" -a "$SECURITY_MANAGER" = "true" ]; then $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start-security" \ - >> $TOMCAT_LOG 2>&1 + >> $TOMCAT_LOG 2>&1 || RETVAL="4" else - $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start" >> $TOMCAT_LOG 2>&1 + + [ "$RETVAL" -eq "0" ] && $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start" >> $TOMCAT_LOG 2>&1 || RETVAL="4" fi - RETVAL="$?" - if [ "$RETVAL" -eq 0 ]; then + if [ "$RETVAL" -eq "0" ]; then log_success_msg touch /var/lock/subsys/${NAME} else - log_failure_msg + log_failure_msg "Error code ${RETVAL}" fi if [ "$DISTRIB_ID" = "MandrivaLinux" ]; then echo fi - return $RETVAL } function stop() { - RETVAL="0" echo -n "Stopping ${TOMCAT_PROG}: " if [ -f "/var/lock/subsys/${NAME}" ]; then - parseOptions - $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} stop" >> $TOMCAT_LOG 2>&1 - RETVAL="$?" - if [ "$RETVAL" -eq "0" ]; then - count="0" - if [ -f "/var/run/${NAME}.pid" ]; then - read kpid < /var/run/${NAME}.pid - until [ "$(ps --pid $kpid | grep -c $kpid)" -eq "0" ] || \ + parseOptions + if [ "$RETVAL" -eq "0" ]; then + touch /var/lock/subsys/${NAME} 2>&1 || RETVAL="4" + [ "$RETVAL" -eq "0" ] && $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} stop" >> $TOMCAT_LOG 2>&1 || RETVAL="4" + fi + if [ "$RETVAL" -eq "0" ]; then + 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" @@ -212,7 +221,7 @@ function stop() { done if [ "$count" -gt "$SHUTDOWN_WAIT" ]; then if [ "$SHUTDOWN_VERBOSE" = "true" ]; then - echo "killing processes which didn't stop after $SHUTDOWN_WAIT seconds" + log_warning_msg "killing processes which did not stop after ${SHUTDOWN_WAIT} seconds" fi kill -9 $kpid fi @@ -221,17 +230,25 @@ function stop() { rm -f /var/lock/subsys/${NAME} /var/run/${NAME}.pid else log_failure_msg + RETVAL="4" fi else log_success_msg + RETVAL="0" fi if [ "$DISTRIB_ID" = "MandrivaLinux" ]; then echo fi - return $RETVAL +} + +function usage() +{ + echo "Usage: $0 {start|stop|restart|condrestart|try-restart|reload|force-reload|status|version}" + RETVAL="2" } # See how we were called. +RETVAL="0" case "$1" in start) start @@ -260,32 +277,42 @@ case "$1" in ;; status) if [ -f "/var/run/${NAME}.pid" ]; then -# status ${NAME} -# RETVAL="$?" read kpid < /var/run/${NAME}.pid if [ -d "/proc/${kpid}" ]; then - echo "${NAME} (pid ${kpid}) is running..." + log_success_msg "${NAME} (pid ${kpid}) is running..." RETVAL="0" + else +# The pid file exists but the process is not running + log_warning_msg "PID file exists, but process is not running" + RETVAL="1" fi else pid="$(/usr/bin/pgrep -d , -u ${TOMCAT_USER} -G ${TOMCAT_USER} java)" if [ -z "$pid" ]; then # status ${NAME} # RETVAL="$?" - echo "${NAME} is stopped" + log_success_msg "${NAME} is stopped" RETVAL="3" else - echo "${NAME} (pid $pid) is running..." + log_success_msg "${NAME} (pid $pid) is running..." RETVAL="0" fi fi + if [ -f /var/lock/subsys/${NAME} ]; then + pid="$(/usr/bin/pgrep -d , -u ${TOMCAT_USER} -G ${TOMCAT_USER} java)" +# The lockfile exists but the process is not running + if [ -z "$pid" ]; then + log_failure_msg "${NAME} lockfile exists but process is not running" + RETVAL="2" + fi + fi ;; version) ${TOMCAT_SCRIPT} version ;; *) - echo "Usage: $0 {start|stop|restart|condrestart|try-restart|reload|force-reload|status|version}" - RETVAL="2" + usage + ;; esac exit $RETVAL