[tomcat6] resolves rhbz 719283 - systemv unit file. Incorrect group permissions on basedir
Dave Knox
dknox at fedoraproject.org
Thu Sep 22 00:09:17 UTC 2011
commit eb8f22f607d50693db1b7e9e344bbe966aa2f765
Author: David Knox <dknox at dknox-laptop.(none)>
Date: Wed Sep 21 18:09:28 2011 -0600
resolves rhbz 719283 - systemv unit file. Incorrect group permissions on basedir
tomcat6-6.0-tomcat6-sysd | 101 +++++++++++++++++++++++++++++++++++++++++++
tomcat6-6.0-tomcat6.service | 19 ++++++++
tomcat6-6.0.init | 8 ++--
tomcat6.spec | 62 +++++++++++++++++++++++---
4 files changed, 179 insertions(+), 11 deletions(-)
---
diff --git a/tomcat6-6.0-tomcat6-sysd b/tomcat6-6.0-tomcat6-sysd
new file mode 100644
index 0000000..30185d6
--- /dev/null
+++ b/tomcat6-6.0-tomcat6-sysd
@@ -0,0 +1,101 @@
+#!/bin/bash
+#
+# This script provides systemd activation of the tomcat6 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/tomcat6
+# to override tomcat6 defaults
+
+# SERVICE_NAME is a required value only if the service name is
+# different from 'tomcat6'
+#
+NAME="${SERVICE_NAME:-tomcat6}"
+
+#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/tomcat6"
+
+# 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/tomcat6/tomcat6.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
+
+ 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() {
+ 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
+
diff --git a/tomcat6-6.0-tomcat6.service b/tomcat6-6.0-tomcat6.service
new file mode 100644
index 0000000..2fc0739
--- /dev/null
+++ b/tomcat6-6.0-tomcat6.service
@@ -0,0 +1,19 @@
+# Systemd unit file for tomcat6
+#
+# To create clones of this service:
+# 1) By default SERVICE_NAME=tomcat6. When cloned, the value must be defined
+# before tomcat6-sysd is called.
+# 2) Create /etc/sysconfig/${SERVICE_NAME} from /etc/sysconfig/tomcat6
+# to override tomcat6 defaults
+
+[Unit]
+Description=Apache Tomcat6 Web Application Container
+After=syslog.target network.target
+
+[Service]
+Type=forking
+ExecStart=/usr/sbin/tomcat6-sysd start
+ExecStop=/usr/sbin/tomcat6-sysd stop
+
+[Install]
+WantedBy=multi-user.target
diff --git a/tomcat6-6.0.init b/tomcat6-6.0.init
index ad81343..4fa698d 100644
--- a/tomcat6-6.0.init
+++ b/tomcat6-6.0.init
@@ -67,7 +67,7 @@ TOMCAT_PROG="${NAME}"
TOMCAT_USER="${TOMCAT_USER:-tomcat}"
# Define the tomcat log file
-TOMCAT_LOG="${TOMCAT_LOG:-/var/log/tomcat6/catalina.out}"
+TOMCAT_LOG="${TOMCAT_LOG:-${CATALINA_HOME}/logs/${NAME}-initd.log}"
RETVAL="0"
@@ -184,10 +184,10 @@ function start() {
parseOptions
if [ "$RETVAL" -eq "0" -a "$SECURITY_MANAGER" = "true" ]; then
$SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start-security" \
- >> /var/log/${NAME}/initd.log 2>&1 || RETVAL="4"
+ >> ${TOMCAT_LOG} 2>&1 || RETVAL="4"
else
- [ "$RETVAL" -eq "0" ] && $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start" >> /var/log/${NAME}/initd.log 2>&1 || RETVAL="4"
+ [ "$RETVAL" -eq "0" ] && $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start" >> /var/log/${NAME}/${TOMCAT_LOG} 2>&1 || RETVAL="4"
fi
if [ "$RETVAL" -eq "0" ]; then
log_success_msg
@@ -206,7 +206,7 @@ function stop() {
parseOptions
if [ "$RETVAL" -eq "0" ]; then
touch /var/lock/subsys/${NAME} 2>&1 || RETVAL="4"
- [ "$RETVAL" -eq "0" ] && $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} stop" >> /var/log/${NAME}/initd.log 2>&1 || RETVAL="4"
+ [ "$RETVAL" -eq "0" ] && $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} stop" >> ${TOMCAT_LOG} 2>&1 || RETVAL="4"
fi
if [ "$RETVAL" -eq "0" ]; then
count="0"
diff --git a/tomcat6.spec b/tomcat6.spec
index 17efc52..a6cf5b0 100644
--- a/tomcat6.spec
+++ b/tomcat6.spec
@@ -70,6 +70,9 @@ 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}-tomcat6.service
+Source12: %{name}-%{major_version}.%{minor_version}-tomcat6-sysd
+
Patch0: %{name}-%{major_version}.%{minor_version}-bootstrap-MANIFEST.MF.patch
Patch1: %{name}-%{major_version}.%{minor_version}-tomcat-users-webapp.patch
# In 6.0.32 source
@@ -93,12 +96,13 @@ BuildRequires: java-devel
BuildRequires: jpackage-utils >= 0:1.7.0
BuildRequires: junit
BuildRequires: log4j
+BuildRequires: systemd-units
Requires: jakarta-commons-daemon
Requires: jakarta-commons-logging
Requires: jakarta-commons-collections
Requires: jakarta-commons-dbcp
Requires: jakarta-commons-pool
-Requires: java
+Requires: java
Requires: procps
Requires: %{name}-lib = %{epoch}:%{version}-%{release}
Requires(pre): shadow-utils
@@ -107,6 +111,9 @@ Requires(post): chkconfig
Requires(preun): chkconfig
Requires(post): redhat-lsb
Requires(preun): redhat-lsb
+Requires(post): systemd-units
+Requires(preun): systemd-units
+Requires(postun): systemd-units
# added after log4j sub-package was removed
Provides: %{name}-log4j = %{epoch}:%{version}-%{release}
@@ -144,6 +151,15 @@ Summary: Javadoc generated documentation for Apache Tomcat
%description javadoc
Javadoc generated documentation for Apache Tomcat.
+%package systemv
+Group: System Environment/Applications
+Summary: Systemv scripts for Apache Tomcat
+Requires: %{name} = %{epoch}:%{version}-%{release}
+
+%description systemv
+SystemV scripts to start and stop tomcat6 service
+
+
%package jsp-%{jspspec}-api
Group: Internet/WWW/Dynamic Content
Summary: Apache Tomcat JSP API implementation classes
@@ -281,6 +297,7 @@ zip -u output/build/lib/jsp-api.jar META-INF/MANIFEST.MF
%{__install} -d -m 0775 ${RPM_BUILD_ROOT}%{homedir}
%{__install} -d -m 0775 ${RPM_BUILD_ROOT}%{tempdir}
%{__install} -d -m 0775 ${RPM_BUILD_ROOT}%{workdir}
+%{__install} -d -m 0755 ${RPM_BUILD_ROOT}%{_unitdir}
# move things into place
# First copy supporting libs to tomcat lib
@@ -317,6 +334,8 @@ popd
-e "s|\@\@\@TCTEMP\@\@\@|%{tempdir}|g" \
-e "s|\@\@\@LIBDIR\@\@\@|%{_libdir}|g" %{SOURCE7} \
> ${RPM_BUILD_ROOT}%{_bindir}/%{name}-tool-wrapper
+%{__install} -m 755 %{SOURCE11} ${RPM_BUILD_ROOT}%{_unitdir}/%{name}.service
+%{__install} -m 755 %{SOURCE12} ${RPM_BUILD_ROOT}%{_sbindir}/%{name}-sysd
# create jsp and servlet API symlinks
pushd ${RPM_BUILD_ROOT}%{_javadir}
%{__mv} %{name}/jsp-api.jar %{name}-jsp-%{jspspec}-api.jar
@@ -424,6 +443,10 @@ done
%post
# install but don't activate
/sbin/chkconfig --add %{name}
+if [ $1 -eq 1 ]; then
+ #initial installation
+ /bin/systemctl daemon-reload >/dev/null 2>&1 || :
+fi
%post jsp-%{jspspec}-api
%{_sbindir}/update-alternatives --install %{_javadir}/jsp.jar jsp \
@@ -465,11 +488,19 @@ if [ "$1" -eq "0" ]; then
fi
%preun
-# don't remove under any condition
-#%{__rm} -rf %{workdir} %{tempdir}
if [ "$1" = "0" ]; then
- %{_initrddir}/%{name} stop >/dev/null 2>&1
+ %{_initrddir}/%{name} stop > /dev/null 2>&1
/sbin/chkconfig --del %{name}
+ # package removal, not upgrade
+ /bin/systemctl --no-reload disable tomcat6.service > /dev/null 2>&1 || :
+ /bin/systemctl stop tomcat6.service > /dev/null 2>&1 || :
+fi
+
+%postun
+/bin/systemctl daemon-reload > /dev/null 2>&1 || :
+if [ $1 -ge 1 ]; then
+ #package upgrade, not uninstall
+ /bin/systemctl try-restart tomcat6.service > /dev/null 2>&1 || :
fi
@@ -491,17 +522,24 @@ if [ "$1" = "0" ]; then
%{_javadir}/%{name}-el-%{elspec}-api.jar
fi
+%triggerun -- tomcat6 < 0:6.0.32-15
+/usr/bin/systemd-sysv-convert -- save tomcat6 > /dev/null 2>&1 || :
+# Run these becasue the SysV package being removed won't do them
+/sbin/chkconfig --del tomcat6 > /dev/null 2>&1 || :
+/bin/systemctl try-restart tomcat6.service > /dev/null 2>&1 || :
+
%files
%defattr(0664,root,tomcat,0775)
%doc {LICENSE,NOTICE,RELEASE*}
%attr(0755,root,root) %{_bindir}/%{name}-digest
%attr(0755,root,root) %{_bindir}/%{name}-tool-wrapper
-%attr(0755,root,root) %{_sbindir}/d%{name}
+%attr(0755,root,root) %{_unitdir}/%{name}.service
+%attr(0755,root,root) %{_sbindir}/%{name}-sysd
%attr(0755,root,root) %{_sbindir}/%{name}
-%attr(0755,root,root) %{_initrddir}/%{name}
+# %attr(0755,root,root) %{_initrddir}/%{name}
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%config(noreplace) %{_sysconfdir}/sysconfig/%{name}
-%attr(0765,root,tomcat) %dir %{basedir}
+%attr(0775,root,tomcat) %dir %{basedir}
%attr(0775,root,tomcat) %dir %{appdir}
%attr(0775,root,tomcat) %dir %{confdir}
%attr(0775,root,tomcat) %dir %{confdir}/Catalina
@@ -577,7 +615,17 @@ fi
%{appdir}/examples
%{appdir}/sample
+%files systemv
+%defattr(755,root,root,0755)
+%{_sbindir}/%{name}
+%{_sbindir}/d%{name}
+%{_initrddir}/%{name}
+
%changelog
+* Thu Sep 9 2011 David Knox <dknox at redhat.com> 0:6.0.32-15
+- Resolves: rhbz 719283 - provide native systemd unit file
+- Resolves: incorrect permissions on basedir
+
* Wed Aug 31 2011 David Knox <dknox at redhat.com> 0:6.0.32-14
- Resolves: rhbz 734886 - additionally created instances regression
More information about the scm-commits
mailing list