From owner-freebsd-java@FreeBSD.ORG Wed Aug 10 17:11:04 2005 Return-Path: X-Original-To: freebsd-java@FreeBSD.ORG Delivered-To: freebsd-java@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1307016A41F for ; Wed, 10 Aug 2005 17:11:04 +0000 (GMT) (envelope-from herve.quiroz@esil.univ-mrs.fr) Received: from arabica.esil.univ-mrs.fr (arabica.esil.univ-mrs.fr [139.124.41.108]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8060743D46 for ; Wed, 10 Aug 2005 17:11:02 +0000 (GMT) (envelope-from herve.quiroz@esil.univ-mrs.fr) Received: from arabica.esil.univ-mrs.fr (localhost [127.0.0.1]) by arabica.esil.univ-mrs.fr (8.13.3/8.13.3) with ESMTP id j7AHAker078350; Wed, 10 Aug 2005 19:10:46 +0200 (CEST) (envelope-from herve.quiroz@esil.univ-mrs.fr) Received: (from rv@localhost) by arabica.esil.univ-mrs.fr (8.13.3/8.13.3/Submit) id j7AHAcvN078349; Wed, 10 Aug 2005 19:10:38 +0200 (CEST) (envelope-from herve.quiroz@esil.univ-mrs.fr) X-Authentication-Warning: arabica.esil.univ-mrs.fr: rv set sender to herve.quiroz@esil.univ-mrs.fr using -f Date: Wed, 10 Aug 2005 19:10:38 +0200 From: Herve Quiroz To: freebsd-java@FreeBSD.ORG Message-ID: <20050810171038.GA78209@arabica.esil.univ-mrs.fr> Mail-Followup-To: freebsd-java@FreeBSD.ORG, liukang@bjut.edu.cn, jan grant , SimpleRezo Team , Anton Yudin Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.1i Cc: SimpleRezo Team , jan grant , liukang@bjut.edu.cn, Anton Yudin Subject: [PATCH] New rcNG Tomcat startup script X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Aug 2005 17:11:04 -0000 Hi all, I have been working on the Tomcat ports lately and I have come up with the attached patch. It is based on a prior work from Ari Suutari [1] and I think it implements all the requested features. Just install the port and have a look at the header in ${PREFIX}/etc/rc.d/jakarta-tomcat55.sh. This solution is quite flexible as it uses javavmwrapper and allows to set various requirements on the JVM in rc.conf. It handles the same settings that those that were used with the prior rc script and tomcatctl program (e.g. STDOUT_LOG) as well as the ones in the original catalina.sh (e.g. CATALINA_HOME, CATALINA_BASE, CATALINA_TMPDIR). It starts fine and shutdowns fine as well, with no latency, and will run as the user of your choice (will use ${USER} from the port by default, which means 'www'). Last but not least, it supports additional JVM settings (e.g. to increase max heap as there seem to be quite a demand on this one). I also fixed some permissions issue with STDOUT_LOG and STDERR_LOG (they were both 755 when they should have been 664). Now there are lots of permission issues to fix, mostly regarding to Jan Grant's PR [2]. This will be taken care of in the next step. For now I would like volunteers to test and review the patch. I would also be glad if the submitters of the many Tomcat-related PRs and the maintainer itself could give some comments as well. Herve [1] http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/38018 [2] http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/83434 Index: Makefile =================================================================== RCS file: /home/ncvs/ports/www/jakarta-tomcat55/Makefile,v retrieving revision 1.26 diff -u -r1.26 Makefile --- Makefile 25 Jul 2005 16:10:34 -0000 1.26 +++ Makefile 10 Aug 2005 16:32:27 -0000 @@ -19,6 +19,8 @@ JAVA_VERSION= 1.4+ NO_BUILD= YES +USE_RC_SUBR= yes + .if !defined(NOPORTDOCS) MAN1= ${CONTROL_SCRIPT_NAME}.1 .endif @@ -49,7 +51,6 @@ PID_FILE= /var/run/${APP_SHORTNAME}.pid REPLACE_FILES= ${PORTSDIR}/www/jakarta-tomcat4/files/daemonctl.c \ ${PORTSDIR}/www/jakarta-tomcat4/files/daemonctl.1 \ - ${PORTSDIR}/www/jakarta-tomcat4/files/startup.sh \ ${WRKSRC}/conf/server.xml JAR_FILE= bin/bootstrap.jar WRKDIR?= ${WRKDIRPREFIX}${.CURDIR}/work @@ -58,6 +59,13 @@ CONF_EXT= sample PLIST_SUB+= CONF_EXT=${CONF_EXT} +SUB_FILES= tomcat.sh +SUB_LIST= TOMCAT_VERSION=${MAJOR_VER:S/.//} \ + TOMCAT_HOME=${APP_HOME} \ + USER=${USER} \ + STDOUT_LOG=${STDOUT_LOG} \ + STDERR_LOG=${STDERR_LOG} + .include .if ${JAVA_PORT_VERSION:C/^([0-9])\.([0-9])(.*)$/\1.\2/} == "1.4" @@ -149,14 +157,10 @@ -e "/%%JAR_ARGS%%/s//\"start\",/g" \ ${WRKDIR}/daemonctl.c > ${WRKDIR}/daemonctl_.c @cd ${WRKDIR} && ${CC} -ansi -o ${CONTROL_SCRIPT_NAME} daemonctl_.c - @${CP} ${WRKDIR}/${CONTROL_SCRIPT_NAME} ${CONTROL_SCRIPT} - @${CHOWN} ${USER}:${GROUP} ${CONTROL_SCRIPT} - @${CHMOD} 6754 ${CONTROL_SCRIPT} @${ECHO_MSG} " [ DONE ]" @${ECHO_MSG} -n ">> Installing startup script..." - @${CP} ${WRKDIR}/startup.sh ${STARTUP_SCRIPT} - @${CHMOD} 0544 ${STARTUP_SCRIPT} + @${INSTALL_SCRIPT} ${WRKDIR}/tomcat.sh ${PREFIX}/etc/rc.d/jakarta-tomcat${MAJOR_VER:S/.//}.sh @${ECHO_MSG} " [ DONE ]" .if !defined(NOPORTDOCS) @@ -166,8 +170,8 @@ .endif @${ECHO_MSG} -n ">> Creating log files..." - @${INSTALL} /dev/null ${STDOUT_LOG} - @${INSTALL} /dev/null ${STDERR_LOG} + @${INSTALL} -m 664 -o ${USER} -g ${GROUP} /dev/null ${STDOUT_LOG} + @${INSTALL} -m 664 -o ${USER} -g ${GROUP} /dev/null ${STDERR_LOG} @${ECHO_MSG} " [ DONE ]" @${ECHO_MSG} -n ">> Creating symlink to tools.jar..." Index: pkg-plist =================================================================== RCS file: /home/ncvs/ports/www/jakarta-tomcat55/pkg-plist,v retrieving revision 1.16 diff -u -r1.16 pkg-plist --- pkg-plist 25 Jul 2005 16:10:34 -0000 1.16 +++ pkg-plist 10 Aug 2005 16:32:28 -0000 @@ -20,7 +20,7 @@ @unexec if cmp -s %D/%%T%%/conf/workers2.properties %D/%%T%%/conf/workers2.properties.%%CONF_EXT%%; then rm -f %D/%%T%%/conf/workers2.properties; else echo If permanently deleting this package, %D/%%T%%/conf/workers2.properties must be removed manually; fi @unexec if cmp -s %D/%%T%%/conf/workers2.properties.minimal %D/%%T%%/conf/workers2.properties.minimal.%%CONF_EXT%%; then rm -f %D/%%T%%/conf/workers2.properties.minimal; else echo If permanently deleting this package, %D/%%T%%/conf/workers2.properties.minimal must be removed manually; fi bin/tomcat55ctl -etc/rc.d/020.jakarta-tomcat55.sh +etc/rc.d/jakarta-tomcat55.sh %%T%%/LICENSE %%T%%/NOTICE %%T%%/RELEASE-NOTES Index: files/tomcat.sh.in =================================================================== RCS file: files/tomcat.sh.in diff -N files/tomcat.sh.in --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ files/tomcat.sh.in 10 Aug 2005 16:32:28 -0000 @@ -0,0 +1,114 @@ +#!/bin/sh +# +# $FreeBSD$ +# + +# PROVIDE: jakarta-tomcat%%TOMCAT_VERSION%% +# REQUIRE: NETWORKING SERVERS +# BEFORE: DAEMON +# KEYWORD: FreeBSD shutdown + +# +# Configuration settings for jakarta-tomcat%%TOMCAT_VERSION%% in /etc/rc.conf: +# +# jakarta_tomcat%%TOMCAT_VERSION%%_enable (bool): +# Set to "NO" by default. +# Set it to "YES" to enable jakarta-tomcat%%TOMCAT_VERSION%% +# +# jakarta_tomcat%%TOMCAT_VERSION%%_flags (str): +# Set to "" by default. +# Extra flags passed to start command +# +# jakarta_tomcat%%TOMCAT_VERSION%%_catalina_home (str) +# Set to "%%TOMCAT_HOME%%" by default. +# Set the CATALINA_HOME variable for the Tomcat process +# +# jakarta_tomcat%%TOMCAT_VERSION%%_catalina_base (str) +# Set to "%%TOMCAT_HOME%%" by default. +# Set the CATALINA_BASE variable for the Tomcat process +# +# jakarta_tomcat%%TOMCAT_VERSION%%_catalina_tmpdir (str) +# Set to "%%TOMCAT_HOME%%/temp" by default. +# Set the CATALINA_TMPDIR variable for the Tomcat process +# +# jakarta_tomcat%%TOMCAT_VERSION%%_stdout_log (str) +# Set to "%%STDOUT_LOG%%" by default. +# Set the location for the Tomcat process log (standard output) +# +# jakarta_tomcat%%TOMCAT_VERSION%%_stderr_log (str) +# Set to "%%STDERR_LOG%%" by default. +# Set the location for the Tomcat process log (error output) +# +# jakarta_tomcat%%TOMCAT_VERSION%%_java_home (str): +# jakarta_tomcat%%TOMCAT_VERSION%%_java_vendor (str): +# jakarta_tomcat%%TOMCAT_VERSION%%_java_version (str): +# jakarta_tomcat%%TOMCAT_VERSION%%_java_os (str): +# Specify the requirements of the Java VM to use. See javavm(1). +# +# jakarta_tomcat%%TOMCAT_VERSION%%_classpath (str): +# Set to "" by default. +# Addtional classes to add to the CLASSPATH +# +# jakarta_tomcat%%TOMCAT_VERSION%%_java_opts (str): +# Set to "" by default. +# Java VM args to use. +# + +jakarta_tomcat%%TOMCAT_VERSION%%_enable="${jakarta_tomcat%%TOMCAT_VERSION%%_enable:-"NO"}" +jakarta_tomcat%%TOMCAT_VERSION%%_java_version="${jakarta_tomcat%%TOMCAT_VERSION%%_java_version:-"%%JAVA_VERSION%%"}" +jakarta_tomcat%%TOMCAT_VERSION%%_user="${jakarta_tomcat%%TOMCAT_VERSION%%_user:-"%%USER%%"}" +jakarta_tomcat%%TOMCAT_VERSION%%_catalina_home="${jakarta_tomcat%%TOMCAT_VERSION%%_catalina_home:-"%%TOMCAT_HOME%%"}" +jakarta_tomcat%%TOMCAT_VERSION%%_catalina_base="${jakarta_tomcat%%TOMCAT_VERSION%%_catalina_base:-"%%TOMCAT_HOME%%"}" +jakarta_tomcat%%TOMCAT_VERSION%%_catalina_tmpdir="${jakarta_tomcat%%TOMCAT_VERSION%%_catalina_tmpdir:-"%%TOMCAT_HOME%%/temp"}" +jakarta_tomcat%%TOMCAT_VERSION%%_stdout_log="${jakarta_tomcat%%TOMCAT_VERSION%%_stdout_log:-"%%STDOUT_LOG%%"}" +jakarta_tomcat%%TOMCAT_VERSION%%_stderr_log="${jakarta_tomcat%%TOMCAT_VERSION%%_stderr_log:-"%%STDERR_LOG%%"}" + +. %%RC_SUBR%% + +name="jakarta_tomcat%%TOMCAT_VERSION%%" +rcvar=`set_rcvar` + +if [ -n "${jakarta_tomcat%%TOMCAT_VERSION%%_java_home}" ] ; then + export JAVA_HOME="${jakarta_tomcat%%TOMCAT_VERSION%%_java_home}" +fi + +if [ -n "${jakarta_tomcat%%TOMCAT_VERSION%%_java_version}" ] ; then + export JAVA_VERSION="${jakarta_tomcat%%TOMCAT_VERSION%%_java_version}" +fi + +if [ -n "${jakarta_tomcat%%TOMCAT_VERSION%%_java_vendor}" ] ; then + export JAVA_VENDOR="${jakarta_tomcat%%TOMCAT_VERSION%%_java_vendor}" +fi + +if [ -n "${jakarta_tomcat%%TOMCAT_VERSION%%_java_os}" ] ; then + export JAVA_OS="${jakarta_tomcat%%TOMCAT_VERSION%%_java_os}" +fi + +java_command="%%LOCALBASE%%/bin/java \ + ${jakarta_tomcat%%TOMCAT_VERSION%%_java_opts} \ + -Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS \ + -classpath %%TOMCAT_HOME%%/bin/bootstrap.jar:%%TOMCAT_HOME%%/bin/commons-logging-api.jar:${jakarta_tomcat%%TOMCAT_VERSION%%_classpath} \ + -Dcatalina.base=${jakarta_tomcat%%TOMCAT_VERSION%%_catalina_base} \ + -Dcatalina.home=${jakarta_tomcat%%TOMCAT_VERSION%%_catalina_home} \ + -Djava.io.tmpdir=${jakarta_tomcat%%TOMCAT_VERSION%%_catalina_tmpdir} \ + org.apache.catalina.startup.Bootstrap" + +log_args=">> ${jakarta_tomcat%%TOMCAT_VERSION%%_stdout_log} \ + 2>> ${jakarta_tomcat%%TOMCAT_VERSION%%_stderr_log} " + +procname="java" +required_files="${jakarta_tomcat%%TOMCAT_VERSION%%_catalina_home}/conf/server.xml" + +command="/usr/sbin/daemon" +flags="${command} ${java_command} start ${jakarta_tomcat%%TOMCAT_VERSION%%_flags} ${log_args}" + +stop_cmd="jakarta_tomcat%%TOMCAT_VERSION%%_stop" + +jakarta_tomcat%%TOMCAT_VERSION%%_stop() { + echo "Stopping ${name}." + ${java_command} stop + wait_for_pids +} + +load_rc_config "${name}" +run_rc_command "$1"