* merge the jsvc into tomcat-sysd code, the -jsvc-sysd is a symlink

* properly use jsvc with pid file to start and stop

OBS-URL: https://build.opensuse.org/package/show/Java:packages/tomcat?expand=0&rev=6
This commit is contained in:
Michal Vyskocil 2012-07-19 08:58:29 +00:00 committed by Git OBS Bridge
parent a1a7392be9
commit 3b8b9e494f
8 changed files with 98 additions and 262 deletions

View File

@ -1,17 +1,18 @@
# Systemd unit file for tomcat
#
# To create clones of this service:
# 1) By default SERVICE_NAME=tomcat. When cloned, the value must be defined
# before tomcat-sysd is called.
# 2) Create /etc/sysconfig/${SERVICE_NAME} from /etc/sysconfig/tomcat
# to override tomcat defaults
# You can clone this service by:
# 1.) Add a new EnvironmentFile declaring the new values for CATALINA_BASE
# and others
# 2.) Define new Environment=JSVC_PIDFILE=/var/run/tomcat-foo.pid if you want
# to run more than one service
[Unit]
Description=Apache Tomcat Web Application Container JSVC wrapper
After=syslog.target network.target
After=network.target
[Service]
Type=forking
Type=simple
EnvironmentFile=/etc/tomcat/tomcat.conf
ExecStart=/usr/sbin/tomcat-jsvc-sysd start
ExecStop=/usr/sbin/tomcat-jsvc-sysd stop

View File

@ -1,83 +0,0 @@
#!/bin/bash
if [ -r /usr/share/java-utils/java-functions ]; then
. /usr/share/java-utils/java-functions
else
echo "Can't read Java functions library, aborting"
exit 1
fi
# Get the tomcat config (use this for environment specific settings)
#if [ -z "${TOMCAT_CFG}" ]; then
# TOMCAT_CFG="/etc/tomcat/tomcat.conf"
#fi
#if [ -r "$TOMCAT_CFG" ]; then
# . $TOMCAT_CFG
#fi
set_javacmd
# CLASSPATH munging
if [ -n "$JSSE_HOME" ]; then
CLASSPATH="${CLASSPATH}:$(build-classpath jcert jnet jsse 2>/dev/null)"
fi
CLASSPATH="${CLASSPATH}:${CATALINA_HOME}/bin/bootstrap.jar"
CLASSPATH="${CLASSPATH}:${CATALINA_HOME}/bin/tomcat-juli.jar"
CLASSPATH="${CLASSPATH}:$(build-classpath commons-daemon 2>/dev/null)"
# if jsvc installed and USE_JSVC=true
# then use jsvc instead of calling java directly
if [ -x /usr/bin/jsvc ]; then
JAVACMD="/usr/bin/jsvc -nodetach -user ${TOMCAT_USER} -outfile ${CATALINA_BASE}/logs/catalina.out -errfile ${CATALINA_BASE}/logs/catalina.out"
if [ "$1" = "stop" ]; then
JAVACMD="${JAVACMD} -stop"
fi
fi
if [ "$1" = "start" ]; then
${JAVACMD} $JAVA_OPTS $CATALINA_OPTS \
-classpath "$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
-Djava.util.logging.config.file="${CATALINA_BASE}/conf/logging.properties" \
-Djava.util.logging.manager="org.apache.juli.ClassLoaderLogManager" \
org.apache.catalina.startup.Bootstrap start \
>> ${CATALINA_BASE}/logs/catalina.out 2>&1 &
if [ ! -z "$CATALINA_PID" ]; then
echo $! > $CATALINA_PID
fi
elif [ "$1" = "start-security" ]; then
${JAVACMD} $JAVA_OPTS $CATALINA_OPTS \
-classpath "$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
-Djava.security.manager \
-Djava.security.policy=="${CATALINA_BASE}/conf/catalina.policy" \
-Djava.util.logging.config.file="${CATALINA_BASE}/conf/logging.properties" \
-Djava.util.logging.manager="org.apache.juli.ClassLoaderLogManager" \
org.apache.catalina.startup.Bootstrap start \
>> ${CATALINA_BASE}/logs/catalina.out 2>&1 &
if [ ! -z "$CATALINA_PID" ]; then
echo $! > $CATALINA_PID
fi
elif [ "$1" = "stop" ]; then
${JAVACMD} $JAVA_OPTS \
-classpath "$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
org.apache.catalina.startup.Bootstrap stop \
>> ${CATALINA_BASE}/logs/catalina.out 2>&1
elif [ "$1" = "version" ]; then
${JAVACMD} -classpath ${CATALINA_HOME}/lib/catalina.jar \
org.apache.catalina.util.ServerInfo
else
echo "Usage: $0 {start|start-security|stop|version}"
exit 1
fi

View File

@ -1,113 +0,0 @@
#!/bin/bash
#
# This script provides systemd activation of the tomcat service
# To create clones of this service:
# 1) SERVICE_NAME must be defined before calling this script
# 2) Create /etc/sysconfig/${SERVICE_NAME} from /etc/sysconfig/tomcat
# to override tomcat defaults
# SERVICE_NAME is a required value only if the service name is
# different from 'tomcat'
#
NAME="${SERVICE_NAME:-tomcat}"
#I'll bet this isn't required.
# unset ISBOOT
# For SELinux we need to use 'runuser' not 'su'
if [ -x "/sbin/runuser" ]; then
SU="/sbin/runuser -s /bin/sh"
else
SU="/bin/su -s /bin/sh"
fi
# Path to the tomcat launch script
TOMCAT_SCRIPT="/usr/sbin/tomcat-jsvc"
# Define the tomcat username
TOMCAT_USER="${TOMCAT_USER:-tomcat}"
# TOMCAT_LOG should be different from catalina.out.
# Usually the below config is all that is necessary
TOMCAT_LOG=/var/log/${NAME}/${SERVICE_NAME}-jsvc-sysd.log
# Get the tomcat config (use this for environment specific settings)
TOMCAT_CFG="/etc/tomcat/tomcat.conf"
if [ -r "$TOMCAT_CFG" ]; then
. $TOMCAT_CFG
fi
# Get instance specific config file
if [ -r "/etc/sysconfig/${NAME}" ]; then
. /etc/sysconfig/${NAME}
fi
function parseOptions() {
options=""
options="$options $(
awk '!/^#/ && !/^$/ { ORS=" "; print "export ", $0, ";" }' \
$TOMCAT_CFG
)"
if [ -r "/etc/sysconfig/${NAME}" ]; then
options="$options $(
awk '!/^#/ && !/^$/ { ORS=" ";
print "export ", $0, ";" }' \
/etc/sysconfig/${NAME}
)"
fi
TOMCAT_SCRIPT="$options ${TOMCAT_SCRIPT}"
}
# See how we were called.
function start() {
# fix permissions on the log and pid files
export CATALINA_PID="/var/run/${NAME}.pid"
touch $CATALINA_PID 2>&1
if [ "$?" -eq "0" ]; then
chown ${TOMCAT_USER}:${TOMCAT_USER} $CATALINA_PID
fi
touch $TOMCAT_LOG 2>&1
if [ "$?" -eq "0" ]; then
chown ${TOMCAT_USER}:${TOMCAT_USER} $TOMCAT_LOG
fi
# if jsvc installed and USE_JSVC=true
# then start as root and use jsvc to drop privileges
if [ -x /usr/bin/jsvc ]; then
TOMCAT_USER="root"
fi
parseOptions
if [ "$SECURITY_MANAGER" = "true" ]; then
$SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start-security" >> $TOMCAT_LOG 2>&1
else
$SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start" >> $TOMCAT_LOG 2>&1
fi
}
function stop() {
# if jsvc installed and USE_JSVC=true
# then start as root and use jsvc to drop privileges
if [ -x /usr/bin/jsvc ]; then
TOMCAT_USER="root"
fi
parseOptions
$SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} stop" >> $TOMCAT_LOG 2>&1
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
esac

View File

@ -1,24 +1,43 @@
#!/bin/bash
#
# This script provides systemd activation of the tomcat service
# To create clones of this service:
# 1) Create /etc/tomcat/${SERVICE_NAME}.conf from /etc/tomcat/tomcat.conf
# to override tomcat defaults and add the EnvironmentFile=
# 2) Change the location of PIDFile=
# This script provides systemd activation of the tomcat service and tomcat
# throught jsvc wrapper
# check the basic environment variables
if [[ -z "${CATALINA_BASE}" || \
-z "${CATALINA_HOME}" || \
-z "${CATALINA_TMPDIR}" ]]; then
echo "ERROR: one of CATALINA_BASE, CATALINA_HOME or CATALINA_TMPDIR is not defined" >&2
echo " use proper EnvironmentFile= in your .service file" >&2
exit 1
fi
if [[ "${0}" =~ tomcat-jsvc ]]; then
if [[ ! -x /usr/bin/jsvc ]]; then
echo "ERROR: cannot use ${0}, /usr/bin/jsvc does not exists" >&2
exit 1
fi
USE_JSVC=true
JSVC_PIDFILE=${JSVC_PIDFILE:-/var/run/${0##*/}}
else
USE_JSVC=false
fi
#### from /usr/sbin/dtomcat
if [[ -r /usr/share/java-utils/java-functions ]]; then
. /usr/share/java-utils/java-functions
. /usr/share/java-utils/java-functions
else
echo "Can't read Java functions library, aborting" >&2
exit 1
echo "ERROR: Can't read Java functions library, aborting" >&2
exit 1
fi
set_javacmd
# CLASSPATH munging
if [[ -n "$JSSE_HOME" ]]; then
CLASSPATH="${CLASSPATH}:$(build-classpath jcert jnet jsse 2>/dev/null)"
CLASSPATH="${CLASSPATH}:$(build-classpath jcert jnet jsse 2>/dev/null)"
fi
CLASSPATH="${CLASSPATH}:${CATALINA_HOME}/bin/bootstrap.jar"
CLASSPATH="${CLASSPATH}:${CATALINA_HOME}/bin/tomcat-juli.jar"
@ -29,8 +48,8 @@ function start() {
local ret
# running as root is not recommended in any case!
if [[ $(id -u) == 0 ]]; then
# running as root is not allowed if not running with jsvc
if ! ${USE_JSVC} && [[ $(id -u) == 0 ]]; then
echo "ERROR: starting tomcat under uid 0 is not supported" >&2
echo " use appropriate User/Group settings in service file" >&2
echo " see man systemd.exec for details" >&2
@ -38,21 +57,24 @@ function start() {
fi
if [[ "$SECURITY_MANAGER" = "true" ]]; then
DSECURITY_MANAGER="-Djava.security.manager"
DSECURITY_MANAGER="-Djava.security.manager"
else
unset DSECURITY_MANAGER
unset DSECURITY_MANAGER
fi
if ${USE_JSVC}; then
JAVACMD="/usr/bin/jsvc -pidfile ${JSVC_PIDFILE} -nodetach -user ${TOMCAT_USER:-tomcat}"
fi
${JAVACMD} $JAVA_OPTS $CATALINA_OPTS \
-classpath "$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" ${DSECURITY_MANAGER} \
-Djava.util.logging.config.file="${CATALINA_BASE}/conf/logging.properties" \
-Djava.util.logging.manager="org.apache.juli.ClassLoaderLogManager" \
org.apache.catalina.startup.Bootstrap start
-classpath "$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" ${DSECURITY_MANAGER} \
-Djava.util.logging.config.file="${CATALINA_BASE}/conf/logging.properties" \
-Djava.util.logging.manager="org.apache.juli.ClassLoaderLogManager" \
org.apache.catalina.startup.Bootstrap start
ret=${?}
return $ret
@ -62,17 +84,29 @@ function stop() {
local ret
${JAVACMD} $JAVA_OPTS \
-classpath "$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
org.apache.catalina.startup.Bootstrap stop
ret=${?}
if ${USE_JSVC}; then
#XXX: foo is needed because of funny jsvc parser needs a class name
/usr/bin/jsvc -stop -pidfile ${JSVC_PIDFILE} foo
ret=${?}
if [[ ret == 143 ]]; then
ret=0
if [[ $ret == 0 ]]; then
rm -f ${JSVC_PIDFILE}
fi
else
${JAVACMD} $JAVA_OPTS \
-classpath "$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
org.apache.catalina.startup.Bootstrap stop
ret=${?}
# workaround the 143 code emmited by jvm in case of sigterm
# using ExecStart=- will ignore all other failures as well
if [[ ret == 143 ]]; then
ret=0
fi
fi
return $ret
@ -80,8 +114,8 @@ function stop() {
function version() {
exec ${JAVACMD} -classpath ${CATALINA_HOME}/lib/catalina.jar \
org.apache.catalina.util.ServerInfo
exec ${JAVACMD} -classpath ${CATALINA_HOME}/lib/catalina.jar \
org.apache.catalina.util.ServerInfo
}
@ -99,9 +133,9 @@ case "$1" in
;;
version)
version
;;
;;
*)
echo "Usage: $0 {start|stop|restart|version}" >&2
exit 1
echo "Usage: $0 {start|stop|restart|version}" >&2
exit 1
esac

View File

@ -7,7 +7,6 @@ JAVA_HOME="@@@JAVAHOME@@@"
# Where your tomcat installation lives
CATALINA_BASE="@@@TCHOME@@@"
CATALINA_HOME="@@@TCHOME@@@"
JASPER_HOME="@@@TCHOME@@@"
CATALINA_TMPDIR="@@@TCTEMP@@@"
# You can pass some parameters to java here if you wish to
@ -17,7 +16,10 @@ CATALINA_TMPDIR="@@@TCTEMP@@@"
#JAVA_OPTS="-Djava.library.path=@@@LIBDIR@@@"
# What user should run tomcat
# WARNING: systemd will use values in tomcat.service!
# This value is interpreted differently
# 1.) for systemd units derived from tomcat.service, the User/Group settings is used
# 2.) for systemd units derived from tomcat-jsvc.service this value is respected (with tomcat as a default)
# 3.) for sysv init script, this value is respected (with tomcat as a default)
#TOMCAT_USER="tomcat"
# You can change your tomcat locale here

View File

@ -1,11 +1,12 @@
# Systemd unit file for tomcat
#
# You can clone this service by adding a new EnvironmentFile declaring the new
# values for CATALINA_BASE et all
# You can clone this service by:
# 1.) Add a new EnvironmentFile declaring the new values for CATALINA_BASE
# and others
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
After=network.target
[Service]
Type=simple
@ -13,8 +14,7 @@ EnvironmentFile=/etc/tomcat/tomcat.conf
User=tomcat
Group=tomcat
ExecStart=/usr/sbin/tomcat-sysd start
ExecStop=-/usr/sbin/tomcat-sysd stop
ExecStop=/usr/sbin/tomcat-sysd stop
[Install]
WantedBy=multi-user.target

View File

@ -1,5 +1,5 @@
-------------------------------------------------------------------
Tue Jul 17 14:16:37 UTC 2012 - mvyskocil@suse.cz
Thu Jul 19 08:48:31 UTC 2012 - mvyskocil@suse.cz
- fix bnc#771802 - systemd support is broken
* change type froking to simple as it does not make a sense run java in a
@ -7,6 +7,8 @@ Tue Jul 17 14:16:37 UTC 2012 - mvyskocil@suse.cz
* remove the need of nested wrappers, so /usr/sbin/tomcat-sysd now relies on
systemd features like User/EnvironmentFile
* workaround the 143 exit code in Stop phase - return 0 in this case
* merge the jsvc into tomcat-sysd code, the -jsvc-sysd is a symlink
* properly use jsvc with pid file to start and stop
-------------------------------------------------------------------
Wed Jun 13 12:37:49 UTC 2012 - mvyskocil@suse.cz

View File

@ -61,16 +61,14 @@ Source7: %{name}-%{major_version}.%{minor_version}-tool-wrapper.script
Source8: servlet-api-OSGi-MANIFEST.MF
Source9: jsp-api-OSGi-MANIFEST.MF
Source10: %{name}-%{major_version}.%{minor_version}-log4j.properties
Source11: %{name}-%{major_version}.%{minor_version}.service
Source11: tomcat-7.0.service
Source12: el-api-OSGi-MANIFEST.MF
Source13: jasper-el-OSGi-MANIFEST.MF
Source14: jasper-OSGi-MANIFEST.MF
Source15: tomcat-api-OSGi-MANIFEST.MF
Source16: tomcat-juli-OSGi-MANIFEST.MF
Source17: tomcat-7.0-tomcat-sysd
Source18: %{name}-%{major_version}.%{minor_version}-tomcat-jsvc-sysd
Source19: %{name}-%{major_version}.%{minor_version}-jsvc.wrapper
Source20: %{name}-%{major_version}.%{minor_version}-jsvc.service
Source20: tomcat-7.0-jsvc.service
Source1000: tomcat-rpmlintrc
#PATCH-FIX-UPSTREAM: from jpackage.org package
@ -189,6 +187,7 @@ Requires(postun): %{_sbindir}/update-alternatives
%description jsp-2_2-api
Apache Tomcat JSP API implementation classes
%if 0%{?suse_version} > 1140
%package jsvc
Summary: Apache jsvc wrapper for Apache Tomcat as separate service
Group: Productivity/Networking/Web/Servers
@ -199,7 +198,7 @@ Requires: apache-commons-daemon-jsvc
Systemd service and wrapper scripts to start tomcat with jsvc,
which allows tomcat to perform some privileged operations
(e.g. bind to a port < 1024) and then switch identity to a non-privileged user.
%endif
%package lib
Summary: Libraries needed to run the Tomcat Web container
@ -385,14 +384,9 @@ popd
${RPM_BUILD_ROOT}%{_unitdir}/%{name}.service
%{__install} -m 0644 %{SOURCE17} \
${RPM_BUILD_ROOT}%{_sbindir}/%{name}-sysd
%endif
%{__install} -m 0644 %{SOURCE19} \
${RPM_BUILD_ROOT}%{_sbindir}/%{name}-jsvc
%if 0%{?suse_version} > 1140
%{__install} -m 0644 %{SOURCE20} \
${RPM_BUILD_ROOT}%{_unitdir}/%{name}-jsvc.service
%{__install} -m 0644 %{SOURCE18} \
${RPM_BUILD_ROOT}%{_sbindir}/%{name}-jsvc-sysd
(cd ${RPM_BUILD_ROOT}%{_sbindir}; ln -s %{name}-sysd %{name}-jsvc-sysd)
%endif
%{__sed} -e "s|\@\@\@TCLOG\@\@\@|%{logdir}|g" %{SOURCE5} \
> ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d/%{name}
@ -708,10 +702,9 @@ fi
%{appdir}/examples
%{appdir}/sample
%if 0%{?suse_version} > 1140
%files jsvc
%defattr(755,root,root,0755)
%{_sbindir}/%{name}-jsvc
%if 0%{?suse_version} > 1140
%{_sbindir}/%{name}-jsvc-sysd
%attr(0644,root,root) %{_unitdir}/%{name}-jsvc.service
%endif