RFC: New port for using Tomcat with jakarta-commons-daemon (jscv)
Martin Jakob
mj-mailinglist at gmx.de
Sun Jun 19 12:45:27 GMT 2005
Hi,
I hope this is the correct list to post this message, because it has tomcat
as
its main topic, but well, its also about creating/improving a port, so...
Since i had to start tomcat with different jdks and/or startup-parameters,
i sat down and tried to use the jscv from
http://jakarta.apache.org/commons/daemon/jsvc.html
I found the port from Herve Quiroz, extended it a bit and added a rcNG
tomcat.sh controll-script.
The port works quite well on my test system, so maybe its usefull for other
people as well. I tested it with jdk1.4.2, jdk1.5.0, jakarta-tomcat-5.0 and
the new jakarta-tomcat-5.5.9 port. Just changing the variables in rc.conf
and
restart the daemon switches the used jdk (and other parameters).
I am sure there are more glitches in the port, but here are some points
where i need input and ideas from other people:
- the name
"jakarta-tomcat-daemon" is not an official name, i used it for the tests.
Any better ideas?
- the patch "patch-jsvc-unix.c"
its more or less a hack to show the complete path of the process in ps. I
added
this, so that i could use the builtin rcNG functions for
stop/restart/status.
Maybe someone with better knowledge of C can comment on this hack?
- dependencies
at the moment there are no tomcat dependencies regarded in the Makefile.
- shutdown time
it really takes some time after /usr/local/etc/rc.d/tomcat.sh (stop|restart)
is
executed to stop/restart the process. Again, any ideas what could cause
this?
Credits:
Based on the ports/scripts from Herve Quiroz and clement (apache2)
So, now have fun with this port :)
--Martin
--- BEGIN SHAR FILE
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# .
# ./files
# ./files/patch-configure
# ./files/tomcat.sh
# ./files/patch-jsvc-unix.c
# ./Makefile
# ./distinfo
# ./pkg-descr
# ./pkg-message
#
echo c - .
mkdir -p . > /dev/null 2>&1
echo c - ./files
mkdir -p ./files > /dev/null 2>&1
echo x - ./files/patch-configure
sed 's/^X//' >./files/patch-configure << 'END-of-./files/patch-configure'
X$FreeBSD$
X
XPatch to have configure script recognize FreeBSD 5.x and 6.x
X
X--- src/native/unix/configure.orig Wed Dec 22 18:53:10 2004
X+++ src/native/unix/configure Wed Dec 22 18:53:30 2004
X@@ -2583,7 +2583,7 @@
X CFLAGS="$CFLAGS -DOS_SYSV -DDSO_DLFCN -Kthread"
X LDFLAGS="-Kthread $LDFLAGS -ldl"
X ;;
X- freebsd4.?)
X+ freebsd[456].?)
X CFLAGS="$CFLAGS -DOS_FREEBSD -DDSO_DLFCN -D_THREAD_SAFE -pthread"
X LDFLAGS="-pthread $LDFLAGS"
X supported_os="freebsd"
END-of-./files/patch-configure
echo x - ./files/tomcat.sh
sed 's/^X//' >./files/tomcat.sh << 'END-of-./files/tomcat.sh'
X#!/bin/sh
X#
X# $FreeBSD$
X#
X
X# PROVIDE: tomcat
X# REQUIRE: NETWORKING SERVERS
X# BEFORE: DAEMON
X# KEYWORD: shutdown
X
X#
X# Add the following lines to /etc/rc.conf to enable tomcat:
X# tomcat_enable (bool): Set to "NO" by default.
X# Set it to "YES" to enable tomcat
X### Optional
X# tomcat_tcuser (str): User to run tomcat as, Default to
"www"
X# the used jsvc program has its own
method
X# to change the user, so use the
variable name
X# "tcuser" instead of the rcNG-"user"
variable
X# tomcat_javahome (str): Set to "/usr/local/jdk1.4.2" by
default.
X# tomcat_jvmtype (str): What JavaVM Type to use, server or
client
X# Default to "server"
X# tomcat_catalinahome (string): Home directory of the Tomcat
installation
X# defaults to
"/usr/local/jakarta-tomcat5.0"
X#
X# tomcat_catalinaopts (str): Setting system properties
X# eg. "-Djava.awt.headless=true" etc.
X#
X# tomcat_javaopts (str): Setting non-standard options
regarding
X# the JVM.
X# eg. "-Xms128m -Xmx128m", "-Xdebug"
etc.
X#
X
X. /etc/rc.subr
X
Xname="tomcat"
Xrcvar=`set_rcvar`
X
Xtomcat_tcpidfile="/var/run/tomcat.pid"
X
X[ -z "$tomcat_enable" ] && tomcat_enable="NO"
X[ -z "$tomcat_tcuser" ] && tomcat_tcuser="www"
X[ -z "$tomcat_javahome" ] && tomcat_javahome="/usr/local/jdk1.4.2"
X[ -z "$tomcat_jvmtype" ] && tomcat_jvmtype="server"
X[ -z "$tomcat_catalinahome" ] &&
tomcat_catalinahome="/usr/local/jakarta-tomcat5.0"
X
Xload_rc_config $name
X
X# export these explizit
Xexport
LD_LIBRARY_PATH="$tomcat_javahome/jre/lib/i386/$tomcat_jvmtype:$tomcat_javahome/jre/lib/i386"
X
Xcommand="/usr/local/sbin/tomcat"
Xarguments="-jvm $tomcat_jvmtype \
X -errfile /dev/null \
X -outfile $tomcat_catalinahome/logs/catalina.out \
X -pidfile $tomcat_tcpidfile \
X -user $tomcat_tcuser \
X -home $tomcat_javahome \
X -Dcatalina.home=$tomcat_catalinahome \
X -Djava.io.tmpdir=$tomcat_catalinahome/temp \
X -cp
$tomcat_javahome/lib/tools.jar:$tomcat_catalinahome/bin/commons-daemon.jar:$tomcat_catalinahome/bin/bootstrap.jar"
X
Xbootclassfile="org.apache.catalina.startup.Bootstrap"
X
Xif [ -n "$tomcat_catalinaopts" ]; then
X arguments="$arguments $tomcat_catalinaopts"
Xfi
X
Xif [ -n "$tomcat_javaopts" ]; then
X arguments="$arguments $tomcat_javaopts"
Xfi
X
Xcommand_args="$arguments $bootclassfile"
X
Xrun_rc_command "$1"
END-of-./files/tomcat.sh
echo x - ./files/patch-jsvc-unix.c
sed 's/^X//' >./files/patch-jsvc-unix.c <<
'END-of-./files/patch-jsvc-unix.c'
X--- src/native/unix/native/jsvc-unix.c.orig Sat Jun 18 15:27:16 2005
X+++ src/native/unix/native/jsvc-unix.c Sat Jun 18 15:27:55 2005
X@@ -601,6 +601,13 @@
X uid_t uid=0;
X gid_t gid=0;
X
X+#ifdef OS_FREEBSD
X+ /* to use the rcNG infrastructure properly (stopping the process),
X+ it is necessary, to get atleast the processname/path
X+ via the ps command. So set this via setproctitle() */
X+ setproctitle("%s", argv[0]);
X+#endif /* ifdef OS_FREEBSD */
X+
X /* Parse command line arguments */
X args=arguments(argc,argv);
X if (args==NULL) return(1);
END-of-./files/patch-jsvc-unix.c
echo x - ./Makefile
sed 's/^X//' >./Makefile << 'END-of-./Makefile'
X# New ports collection makefile for: Jakarta Tomcat Daemon
X# Date created: May 18, 2005
X# Whom: mj at freebsd.local
X#
X# $FreeBSD$
X#
X
XPORTNAME= tomcat-daemon
XPORTVERSION= 1.0.1
XCATEGORIES= sysutils java
XMASTER_SITES= ${MASTER_SITE_APACHE_JAKARTA}
XMASTER_SITE_SUBDIR= commons/daemon/source
XPKGNAMEPREFIX= jakarta-
XDISTNAME= daemon-${PORTVERSION}
X
XMAINTAINER= ports at FreeBSD.org
XCOMMENT= Start Jakarta Tomcat as a Unix Daemon
X
XGNU_CONFIGURE= yes
XUSE_GMAKE= yes
XNATIVE_WRKSRC= ${WRKSRC}/src/native/unix
XCONFIGURE_WRKSRC= ${NATIVE_WRKSRC}
X
XUSE_JAVA= yes
XJAVA_VERSION= 1.3+
X
XCONTROL_PROGRAM=jsvc
XTOMCAT_SERVICE=tomcat
X
XPLIST_FILES= sbin/${TOMCAT_SERVICE} \
X etc/rc.d/"${TOMCAT_SERVICE}.sh"
X
X.include <bsd.port.pre.mk>
X
XCONFIGURE_ARGS+= --with-java="${JAVA_HOME}"
X
Xdo-build:
X cd ${NATIVE_WRKSRC}/native; ${SETENV} ${MAKE_ENV} ${GMAKE}
X
Xdo-install:
X @${ECHO_CMD} "=> Installing ${TOMCAT_SERVICE} in ${PREFIX}/sbin/"
X @${INSTALL_PROGRAM} ${NATIVE_WRKSRC}/${CONTROL_PROGRAM}
${PREFIX}/sbin/${TOMCAT_SERVICE}
X @${ECHO_CMD} "=> Installing ${PREFIX}/etc/rc.d/${TOMCAT_SERVICE}.sh
startup script."
X @${INSTALL_SCRIPT} -m 555 ${FILESDIR}/"${TOMCAT_SERVICE}.sh"
${PREFIX}/etc/rc.d/"${TOMCAT_SERVICE}.sh"
X
Xpost-install:
X @${ECHO_CMD} ""
X @${CAT} ${PKGMESSAGE}
X
X.include <bsd.port.post.mk>
END-of-./Makefile
echo x - ./distinfo
sed 's/^X//' >./distinfo << 'END-of-./distinfo'
XMD5 (daemon-1.0.1.tar.gz) = df3eb5aafa53ca530843a09d40b8a1c0
XSIZE (daemon-1.0.1.tar.gz) = 301023
END-of-./distinfo
echo x - ./pkg-descr
sed 's/^X//' >./pkg-descr << 'END-of-./pkg-descr'
XRun Tomcat as Unix daemon.
X
XWWW: http://jakarta.apache.org/commons/daemon/
END-of-./pkg-descr
echo x - ./pkg-message
sed 's/^X//' >./pkg-message << 'END-of-./pkg-message'
XTo run tomcat server from startup, add tomcat_enable="YES"
Xin your /etc/rc.conf or /etc/rc.conf.local
XExtra options can be found in startup script.
END-of-./pkg-message
exit
More information about the freebsd-java
mailing list