- fix bnc#771802 - systemd support is broken

* change type froking to simple as it does not make a sense run java in a
    background to emulate that
  * 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

OBS-URL: https://build.opensuse.org/package/show/Java:packages/tomcat?expand=0&rev=5
This commit is contained in:
Michal Vyskocil 2012-07-17 14:23:06 +00:00 committed by Git OBS Bridge
parent 683475e52e
commit a1a7392be9
5 changed files with 96 additions and 77 deletions

View File

@ -2,87 +2,87 @@
#
# 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
# 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=
# 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"
#### from /usr/sbin/dtomcat
if [[ -r /usr/share/java-utils/java-functions ]]; then
. /usr/share/java-utils/java-functions
else
SU="/bin/su -s /bin/sh"
echo "Can't read Java functions library, aborting" >&2
exit 1
fi
# Path to the tomcat launch script
TOMCAT_SCRIPT="/usr/sbin/tomcat"
# 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}/${NAME}-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
set_javacmd
# CLASSPATH munging
if [[ -n "$JSSE_HOME" ]]; then
CLASSPATH="${CLASSPATH}:$(build-classpath jcert jnet jsse 2>/dev/null)"
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}"
}
CLASSPATH="${CLASSPATH}:${CATALINA_HOME}/bin/bootstrap.jar"
CLASSPATH="${CLASSPATH}:${CATALINA_HOME}/bin/tomcat-juli.jar"
CLASSPATH="${CLASSPATH}:$(build-classpath commons-daemon 2>/dev/null)"
# 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
local ret
# running as root is not recommended in any case!
if [[ $(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
exit 2
fi
touch $TOMCAT_LOG 2>&1
if [ "$?" -eq "0" ]; then
chown ${TOMCAT_USER}:${TOMCAT_USER} $TOMCAT_LOG
fi
parseOptions
if [ "$SECURITY_MANAGER" = "true" ]; then
$SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start-security" >> $TOMCAT_LOG 2>&1
if [[ "$SECURITY_MANAGER" = "true" ]]; then
DSECURITY_MANAGER="-Djava.security.manager"
else
$SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start" >> $TOMCAT_LOG 2>&1
unset DSECURITY_MANAGER
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
ret=${?}
return $ret
}
function stop() {
parseOptions
$SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} stop" >> $TOMCAT_LOG 2>&1
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 [[ ret == 143 ]]; then
ret=0
fi
return $ret
}
function version() {
exec ${JAVACMD} -classpath ${CATALINA_HOME}/lib/catalina.jar \
org.apache.catalina.util.ServerInfo
}
# See how we were called.
@ -97,5 +97,11 @@ case "$1" in
stop
start
;;
version)
version
;;
*)
echo "Usage: $0 {start|stop|restart|version}" >&2
exit 1
esac

View File

@ -17,7 +17,8 @@ CATALINA_TMPDIR="@@@TCTEMP@@@"
#JAVA_OPTS="-Djava.library.path=@@@LIBDIR@@@"
# What user should run tomcat
TOMCAT_USER="tomcat"
# WARNING: systemd will use values in tomcat.service!
#TOMCAT_USER="tomcat"
# You can change your tomcat locale here
#LANG="en_US"
@ -32,7 +33,8 @@ SHUTDOWN_WAIT="30"
SHUTDOWN_VERBOSE="false"
# Set the TOMCAT_PID location
CATALINA_PID="/var/run/tomcat.pid"
# WARNING: does not make any sense for systemd users
#CATALINA_PID="/var/run/tomcat.pid"
# Connector port is 8080 for this tomcat instance
#CONNECTOR_PORT="8080"

View File

@ -1,19 +1,20 @@
# 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 adding a new EnvironmentFile declaring the new
# values for CATALINA_BASE et all
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
Type=simple
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,3 +1,13 @@
-------------------------------------------------------------------
Tue Jul 17 14:16:37 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
background to emulate that
* 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
-------------------------------------------------------------------
Wed Jun 13 12:37:49 UTC 2012 - mvyskocil@suse.cz

View File

@ -67,7 +67,7 @@ Source13: jasper-el-OSGi-MANIFEST.MF
Source14: jasper-OSGi-MANIFEST.MF
Source15: tomcat-api-OSGi-MANIFEST.MF
Source16: tomcat-juli-OSGi-MANIFEST.MF
Source17: %{name}-%{major_version}.%{minor_version}-tomcat-sysd
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