commit fbf022988b8f28b759b93136b4807a22e32ee9ad
Author: Michael Simacek <msimacek(a)redhat.com>
Date: Tue Apr 1 19:29:55 2014 +0200
Simplify jetty startup script and use systemd features
djetty.script | 30 -------------
jetty.service | 7 ++-
jetty.sh | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
jetty.spec | 25 +++++++----
4 files changed, 156 insertions(+), 42 deletions(-)
---
diff --git a/jetty.service b/jetty.service
index 97652c1..ae69ebf 100644
--- a/jetty.service
+++ b/jetty.service
@@ -9,9 +9,10 @@ Description=Jetty Web Application Server
After=syslog.target network.target
[Service]
-Type=forking
-ExecStart=/usr/bin/jetty start
-ExecStop=/usr/bin/jetty stop
+Type=simple
+ExecStart=/usr/share/jetty/bin/jetty.sh
+User=jetty
+Group=jetty
[Install]
WantedBy=multi-user.target
diff --git a/jetty.sh b/jetty.sh
new file mode 100644
index 0000000..5f44bbb
--- /dev/null
+++ b/jetty.sh
@@ -0,0 +1,136 @@
+#!/usr/bin/env bash
+# Configuration files
+#
+# /etc/default/jetty
+# If it exists, this is read at the start of script. It may perform any
+# sequence of shell commands, like setting relevant environment variables.
+#
+# /etc/jetty.conf
+# If found, and no configurations were given on the command line,
+# the file will be used as this script's configuration.
+# Each line in the file may contain:
+# - A comment denoted by the pound (#) sign as first non-blank character.
+# - The path to a regular file, which will be passed to jetty as a
+# config.xml file.
+# - The path to a directory. Each *.xml file in the directory will be
+# passed to jetty as a config.xml file.
+# - All other lines will be passed, as-is to the start.jar
+#
+# The files will be checked for existence before being passed to jetty.
+#
+# Configuration variables
+#
+# JAVA
+# Command to invoke Java. If not set, java (from the PATH) will be used.
+#
+# JAVA_OPTIONS
+# Extra options to pass to the JVM
+#
+# JETTY_HOME
+# Where Jetty is installed. If not set, the script will try go
+# guess it by first looking at the invocation path for the script,
+# and then by looking in standard locations as $HOME/opt/jetty
+# and /opt/jetty. The java system property "jetty.home" will be
+# set to this value for use by configure.xml files, f.e.:
+#
+# <Arg><Property name="jetty.home"
default="."/>/webapps/jetty.war</Arg>
+#
+# JETTY_BASE
+# Where your Jetty base directory is. If not set, the value from
+# $JETTY_HOME will be used.
+#
+# JETTY_ARGS
+# The default arguments to pass to jetty.
+# For example
+# JETTY_ARGS=jetty.port=8080 jetty.spdy.port=8443 jetty.secure.port=443
+#
+
+set -e -C
+trap "exit 0" 15
+
+readConfig()
+{
+ echo "Reading $1.."
+ source "$1"
+}
+
+CONFIGS=()
+
+if [ -f /etc/default/jetty ]; then
+ readConfig /etc/default/jetty
+fi
+
+if [ -z "$JETTY_HOME" ]; then
+ JETTY_HOME=/usr/share/jetty
+fi
+
+if [ -z "$JETTY_BASE" ]; then
+ JETTY_BASE="$JETTY_HOME"
+fi
+
+cd "$JETTY_BASE"
+JETTY_BASE="$PWD"
+
+if [ -z "$JETTY_CONF" ]
+then
+ JETTY_CONF=/etc/jetty.conf
+fi
+
+if [ -f "$JETTY_CONF" ] && [ -r "$JETTY_CONF" ]
+then
+ while read -r CONF
+ do
+ if expr "$CONF" : '#' >/dev/null ; then
+ continue
+ fi
+
+ if [ -d "$CONF" ]
+ then
+ # assume it's a directory with configure.xml files
+ # for example: /etc/jetty.d/
+ # sort the files before adding them to the list of JETTY_ARGS
+ for XMLFILE in "$CONF/"*.xml
+ do
+ if [ -r "$XMLFILE" ] && [ -f "$XMLFILE" ]
+ then
+ JETTY_ARGS+=("$XMLFILE")
+ else
+ echo "** WARNING: Cannot read '$XMLFILE' specified in
'$JETTY_CONF'"
+ fi
+ done
+ else
+ # assume it's a command line parameter (let start.jar deal with its validity)
+ JETTY_ARGS+=("$CONF")
+ fi
+ done < "$JETTY_CONF"
+fi
+
+if [ -z "$JAVA" ]
+then
+ . /usr/share/java-utils/java-functions
+ set_jvm
+ set_javacmd
+ JAVA="$JAVACMD"
+fi
+
+if [ -z "$JETTY_LOGS" ] && [ -d $JETTY_BASE/logs ]
+then
+ JETTY_LOGS=/var/log/jetty/logs
+fi
+JAVA_OPTIONS+=("-Djetty.logs=$JETTY_LOGS")
+
+JAVA_OPTIONS+=("-Djetty.home=$JETTY_HOME"
"-Djetty.base=$JETTY_BASE")
+
+JETTY_START="$JETTY_HOME/start.jar"
+START_INI="$JETTY_BASE/start.ini"
+if [ ! -f "$START_INI" ]
+then
+ echo "Cannot find a start.ini in your JETTY_BASE directory: $JETTY_BASE"
2>&2
+ exit 1
+fi
+
+RUN_ARGS=(${JAVA_OPTIONS[@]} -jar "$JETTY_START" ${JETTY_ARGS[*]})
+RUN_CMD=("$JAVA" ${RUN_ARGS[@]})
+
+echo -n "Starting Jetty: "
+${RUN_CMD[*]}
diff --git a/jetty.spec b/jetty.spec
index dbde52b..70c5602 100644
--- a/jetty.spec
+++ b/jetty.spec
@@ -55,14 +55,14 @@
Name: jetty
Version: 9.1.3
-Release: 3%{?dist}
+Release: 4%{?dist}
Summary: Java Webserver and Servlet Container
# Jetty is dual licensed under both ASL 2.0 and EPL 1.0, see NOTICE.txt
License: ASL 2.0 or EPL
URL:
http://www.eclipse.org/jetty/
Source0:
http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/snapshot/jet...
-Source1: djetty.script
+Source1: jetty.sh
Source3: jetty.logrotate
Source5: %{name}.service
# MIT license text taken from Utf8Appendable.java
@@ -598,16 +598,18 @@ find . -name "*.class" -exec rm {} \;
%pom_remove_dep :org.eclipse.jdt.core jetty-jsp
-cp %{SOURCE1} djetty
cp %{SOURCE6} .
+# the default location is not allowed by SELinux
+sed -i '/<SystemProperty name="jetty.state"/d' \
+ jetty-distribution/src/main/resources/etc/jetty-started.xml
+
+
# Looks like all CDDL licensed content in tarball has been replaced,
# we don't need to install this license
rm LICENSE-CONTRIBUTOR/CDDLv1.0.txt
%build
-sed -i -e "s|/usr/share|%{_datadir}|g" djetty
-
%mvn_package :jetty-distribution __noinstall
# Separate package for main POM file
%mvn_package :jetty-project project
@@ -642,6 +644,9 @@ install -dm 755 %{buildroot}%{_unitdir}
# systemd unit file
cp %{SOURCE5} %{buildroot}%{_unitdir}/
+# replace the startup script with ours
+cp -p %{SOURCE1} %{buildroot}%{homedir}/
+
# main pkg
tar xvf jetty-distribution/target/%{name}-distribution-%{version}.%{addver}.tar.gz -C
%{buildroot}%{homedir}
mv %{buildroot}%{homedir}/%{name}-distribution-%{version}.%{addver}/*
%{buildroot}%{homedir}/
@@ -652,9 +657,6 @@ rm -f %{buildroot}%{homedir}/bin/*cygwin*
cp jetty-distribution/target/distribution/etc/* %{buildroot}%{homedir}/etc/
cp jetty-distribution/target/distribution/modules/* %{buildroot}%{homedir}/modules/
-chmod +x djetty
-mv djetty %{buildroot}%{_bindir}/djetty
-ln -s %{homedir}/bin/jetty.sh %{buildroot}%{_bindir}/%{name}
install -pm 644 %{SOURCE3} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
echo '# Placeholder configuration file. No default is provided.' > \
%{buildroot}%{confdir}/jetty.conf
@@ -749,6 +751,7 @@ fi
exit 0
%post
+setsebool -P httpd_execmem 1
%systemd_post jetty.service
%preun
@@ -756,6 +759,7 @@ exit 0
%postun
%systemd_postun_with_restart jetty.service
+setsebool -P httpd_execmem 0
%triggerun -- jetty < 8.1.0-3
@@ -774,7 +778,6 @@ exit 0
%if %{with service}
%config(noreplace) %{_sysconfdir}/tmpfiles.d/%{name}.conf
%config(noreplace) %attr(644, root, root) %{_sysconfdir}/logrotate.d/%{name}
-%{_bindir}/*
%config(noreplace) %{confdir}
%dir %{jettylibdir}
%dir %{jettycachedir}
@@ -851,6 +854,10 @@ exit 0
%doc NOTICE.txt LICENSE*
%changelog
+* Tue Apr 01 2014 Michael Simacek <msimacek(a)redhat.com> - 9.1.3-4
+- Simplify (and fix) jetty startup script and use systemd features
+- Allow execmem access for jetty
+
* Thu Mar 06 2014 Erinn Looney-Triggs <erinn.looneytriggs(a)gmail.com> - 9.1.3-3
- Adjust useradd to be more flexible as shown here:
https://fedoraproject.org/wiki/Packaging:UsersAndGroups