#!/bin/sh # # $FreeBSD$ # # PROVIDE: tomcat%%TOMCAT_VERSION%% # REQUIRE: NETWORKING SERVERS # BEFORE: DAEMON # KEYWORD: shutdown # # Configuration settings for tomcat%%TOMCAT_VERSION%% in /etc/rc.conf: # # tomcat%%TOMCAT_VERSION%%_enable (bool): # Set to "NO" by default. # Set it to "YES" to enable tomcat%%TOMCAT_VERSION%% # # tomcat%%TOMCAT_VERSION%%_flags (str): # Set to "" by default. # Extra flags passed to start command # # tomcat%%TOMCAT_VERSION%%_catalina_home (str) # Set to "%%TOMCAT_HOME%%" by default. # Set the CATALINA_HOME variable for the Tomcat process # # tomcat%%TOMCAT_VERSION%%_catalina_base (str) # Set to "%%TOMCAT_HOME%%" by default. # Set the CATALINA_BASE variable for the Tomcat process # # tomcat%%TOMCAT_VERSION%%_catalina_tmpdir (str) # Set to "%%TOMCAT_HOME%%/temp" by default. # Set the CATALINA_TMPDIR variable for the Tomcat process # # tomcat%%TOMCAT_VERSION%%_stdout_log (str) # Set to "%%STDOUT_LOG%%" by default. # Set the location for the Tomcat process log (standard output) # # tomcat%%TOMCAT_VERSION%%_stderr_log (str) # Set to "%%STDERR_LOG%%" by default. # Set the location for the Tomcat process log (error output) # # tomcat%%TOMCAT_VERSION%%_stop_timeout (num) # Set to "10" by default. # Sets the timeout in seconds to allow tomcat to shutdown. # After the timeout has elapsed, tomcat will be killed. # # tomcat%%TOMCAT_VERSION%%_java_home (str): # tomcat%%TOMCAT_VERSION%%_java_vendor (str): # tomcat%%TOMCAT_VERSION%%_java_version (str): # tomcat%%TOMCAT_VERSION%%_java_os (str): # Specify the requirements of the Java VM to use. See javavm(1). # # tomcat%%TOMCAT_VERSION%%_classpath (str): # Set to "" by default. # Addtional classes to add to the CLASSPATH # # tomcat%%TOMCAT_VERSION%%_java_opts (str): # Set to "" by default. # Java VM args to use. # # tomcat%%TOMCAT_VERSION%%_java_start_opts (str): # Set to "" by default. # Additional Java VM args to use when starting tomcat. # tomcat%%TOMCAT_VERSION%%_enable="${tomcat%%TOMCAT_VERSION%%_enable:-"NO"}" tomcat%%TOMCAT_VERSION%%_java_version="${tomcat%%TOMCAT_VERSION%%_java_version:-"%%JAVA_VERSION%%"}" tomcat%%TOMCAT_VERSION%%_user="${tomcat%%TOMCAT_VERSION%%_user:-"%%USER%%"}" tomcat%%TOMCAT_VERSION%%_catalina_home="${tomcat%%TOMCAT_VERSION%%_catalina_home:-"%%TOMCAT_HOME%%"}" tomcat%%TOMCAT_VERSION%%_catalina_base="${tomcat%%TOMCAT_VERSION%%_catalina_base:-"%%TOMCAT_HOME%%"}" tomcat%%TOMCAT_VERSION%%_catalina_tmpdir="${tomcat%%TOMCAT_VERSION%%_catalina_tmpdir:-"%%TOMCAT_HOME%%/temp"}" tomcat%%TOMCAT_VERSION%%_stdout_log="${tomcat%%TOMCAT_VERSION%%_stdout_log:-"%%STDOUT_LOG%%"}" tomcat%%TOMCAT_VERSION%%_stderr_log="${tomcat%%TOMCAT_VERSION%%_stderr_log:-"%%STDERR_LOG%%"}" tomcat%%TOMCAT_VERSION%%_stop_timeout="${tomcat%%TOMCAT_VERSION%%_stop_timeout:-"10"}" . /etc/rc.subr name="tomcat%%TOMCAT_VERSION%%" rcvar=tomcat%%TOMCAT_VERSION%%_enable pidfile="%%PID_FILE%%" load_rc_config "${name}" if [ -n "${tomcat%%TOMCAT_VERSION%%_java_home}" ] ; then export JAVA_HOME="${tomcat%%TOMCAT_VERSION%%_java_home}" fi if [ -n "${tomcat%%TOMCAT_VERSION%%_java_version}" ] ; then export JAVA_VERSION="${tomcat%%TOMCAT_VERSION%%_java_version}" fi if [ -n "${tomcat%%TOMCAT_VERSION%%_java_vendor}" ] ; then export JAVA_VENDOR="${tomcat%%TOMCAT_VERSION%%_java_vendor}" fi if [ -n "${tomcat%%TOMCAT_VERSION%%_java_os}" ] ; then export JAVA_OS="${tomcat%%TOMCAT_VERSION%%_java_os}" fi java_args="-Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS \ -classpath %%TOMCAT_HOME%%/%%JAR_FILE%%:%%TOMCAT_HOME%%/bin/commons-logging-api.jar:${tomcat%%TOMCAT_VERSION%%_classpath} \ -Dcatalina.base=${tomcat%%TOMCAT_VERSION%%_catalina_base} \ -Dcatalina.home=${tomcat%%TOMCAT_VERSION%%_catalina_home} \ -Djava.io.tmpdir=${tomcat%%TOMCAT_VERSION%%_catalina_tmpdir} \ org.apache.catalina.startup.Bootstrap" java_start_command="%%LOCALBASE%%/bin/java \ ${tomcat%%TOMCAT_VERSION%%_java_opts} \ ${tomcat%%TOMCAT_VERSION%%_java_start_opts} \ ${java_args}" java_stop_command="%%LOCALBASE%%/bin/java \ ${tomcat%%TOMCAT_VERSION%%_java_opts} \ ${java_args}" log_args="%%LOG_ARGS%%" # Subvert the check_pid_file procname check. if [ -f $pidfile ]; then read rc_pid junk < $pidfile if [ ! -z "$rc_pid" ]; then procname=`ps -o command= -p $rc_pid | cut -f 1 -d ' '` fi fi if [ -z "$procname" ]; then procname=nonexistent fi required_files="${tomcat%%TOMCAT_VERSION%%_catalina_home}/conf/server.xml" command="/usr/sbin/daemon" flags="-p ${pidfile} ${java_start_command} start ${tomcat%%TOMCAT_VERSION%%_flags} ${log_args}" start_precmd=pid_touch stop_cmd="tomcat%%TOMCAT_VERSION%%_stop" status_cmd="tomcat%%TOMCAT_VERSION%%_status" pid_touch () { touch $pidfile chown $tomcat%%TOMCAT_VERSION%%_user $pidfile } tomcat%%TOMCAT_VERSION%%_stop() { if [ ! -s "$pidfile" ]; then echo "${name} not running? (check $pidfile)." return 1 fi echo "Stopping ${name}." ${java_stop_command} stop tomcat_wait_max_for_pid ${tomcat%%TOMCAT_VERSION%%_stop_timeout} `cat $pidfile` kill -KILL `cat $pidfile` 2> /dev/null && echo "Killed." rm -f ${pidfile} } tomcat%%TOMCAT_VERSION%%_status() { if [ ! -s "$pidfile" ]; then echo "${name} is not running." return 1 else echo "${name} is running as pid `cat $pidfile`." fi } tomcat_wait_max_for_pid() { _timeout=$1 shift _pid=$1 _prefix= while [ $_timeout -gt 0 ] ; do echo -n ${_prefix:-"Waiting (max $_timeout secs) for PIDS: "}$_pid _prefix=", " sleep 2 kill -0 $_pid 2> /dev/null || break _timeout=$(($_timeout-2)) done if [ -n "$_prefix" ]; then echo "." fi } cd ${tomcat%%TOMCAT_VERSION%%_catalina_base} run_rc_command "$1"