Bug 31447 - Contribution: system daemon script for GNU/Linux
Summary: Contribution: system daemon script for GNU/Linux
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Catalina (show other bugs)
Version: Unknown
Hardware: All Linux
: P3 enhancement (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-28 08:56 UTC by Pander
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pander 2004-09-28 08:56:05 UTC
Here is a contribution of a system daemon script for GNU/Linux to mangege 
starting and stopping of Tomcat. It has been developed and tested on RedHat 
Enterprise Server 3 but had been made with other distributions in mind. RedHat 
(and probably also for Mandrake) specfied code (/etc/rc.d/init.d/functions) is 
only activated when available.

It would be very nice to ship Tomcat with a out of the box worknig system 
deamon script for Linux.

#!/bin/bash
#
# Startup script for the Tomcat Servlet Container
#
# chkconfig: - 86 14
# description: Tomcat is the servlet container that is used in the official \
#              Reference Implementation for the Java Servlet and JavaServer \
#              Pages technologies
 
# Source function library.
if [ -x /etc/rc.d/init.d/functions ]; then
	. /etc/rc.d/init.d/functions
else
	echo_success() {
		echo -n "[  OK  ]"
		echo -ne "\r"
		return 0
	}
	echo_failure() {
		echo -n "[FAILED]"
		echo -ne "\r"
		return 1
	}
fi
prog=tomcat
TOMCAT_HOME=/opt/tomcat

start() {
	echo -n $"Starting $prog: "
	su - root -c $TOMCAT_HOME/bin/startup.sh > /dev/null
	RETVAL=$?
	if [ $RETVAL -eq 0 ]; then
		echo_success
	else
		echo_failure
	fi
	echo
	[ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
	return $RETVAL
}
stop() {
	echo -n $"Stopping $prog: "
	su - root -c $TOMCAT_HOME/bin/shutdown.sh > /dev/null
	RETVAL=$?
	if [ $RETVAL -eq 0 ]; then
		echo_success
	else
		echo_failure
	fi
	echo
	[ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog
	return $RETVAL
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  status)
	INSTANCES=`ps --columns 512 -aef|grep java|grep tomcat|grep 
org.apache.catalina.startup.Bootstrap|wc -l`
	if [ $INSTANCES -eq 0 ]; then	
		echo $prog is stopped
		REVAL=3
	else
		if [ $INSTANCES -eq 1 ]; then	
			echo $prog is running 1 instance...
		else
			echo $prog is running $INSTANCES instances...
		fi
		REVAL=0
	fi
	;;
  *)
	echo $"Usage: $prog {start|stop|restart|status|help}"
	exit 1
esac

exit $RETVAL
Comment 1 Yoav Shapira 2004-09-30 15:10:31 UTC
I wonder what the proper CVS location for this is.  jakarta-tomcat-
catalina/catalina/src/bin might be the place, but I'm thinking we might need a 
new contrib directory for some other OS-specific scripts we're getting via the 
mailing list.
Comment 2 Yoav Shapira 2004-10-28 20:02:17 UTC
OK, added for Tomcat 5.0.30.  See bin/contrib directory.  Thanks for submitting 
this.