[jetty/f20] Simplify jetty startup script and use systemd features

Michael Šimáček msimacek at fedoraproject.org
Fri Apr 11 08:59:12 UTC 2014


commit c20d8f23d8a85a2039a86d6d6256aa9b03947750
Author: Michael Simacek <msimacek at 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      |  150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 jetty.spec    |   31 ++++++++----
 4 files changed, 174 insertions(+), 44 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..0feddde
--- /dev/null
+++ b/jetty.sh
@@ -0,0 +1,150 @@
+#!/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: "
+set +e
+${RUN_CMD[*]}
+
+RET="$?"
+if [ "$RET" -ne 0 ]; then
+cat << EOF
+If jvm exited with Out of Memory Error it is quite likely that your SELinux
+policy doesn't allow execmem access for the JVM. To solve this problem, use:
+setsebool -P httpd_execmem 1
+to allow execmem acces for processes in the httpd domain. Please bear in mind
+that this might affect other processess. For more information see
+httpd_selinux(8).
+EOF
+exit "$RET"
+fi
diff --git a/jetty.spec b/jetty.spec
index dd44003..35947ef 100644
--- a/jetty.spec
+++ b/jetty.spec
@@ -55,14 +55,14 @@
 
 Name:           jetty
 Version:        9.0.5
-Release:        1%{?dist}
+Release:        2%{?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/jetty-%{version}.%{addver}.tar.gz
-Source1:        djetty.script
+Source1:        jetty.sh
 Source3:        jetty.logrotate
 Source5:        %{name}.service
 # MIT license text taken from Utf8Appendable.java
@@ -523,6 +523,9 @@ find . -name "*.class" -exec rm {} \;
 # ReportDocumentRender". Investigate proper fix some other time?
 %pom_remove_plugin :maven-pmd-plugin
 
+# not needed
+%pom_remove_plugin ":maven-eclipse-plugin" jetty-osgi
+
 # License plugin may be useful for upstream, but it has no use in
 # Fedora.
 %pom_remove_plugin :maven-license-plugin
@@ -562,16 +565,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
@@ -615,10 +620,6 @@ rm -f %{buildroot}%{homedir}/bin/*cygwin*
 # copy previously extracted configuration
 cp jetty-distribution/target/distribution/etc/* %{buildroot}%{homedir}/etc/
 
-chmod +x %{buildroot}%{homedir}/bin/jetty-xinetd.sh
-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
@@ -670,7 +671,6 @@ JETTY_HOME=%{homedir}
 JETTY_CONSOLE=%{logdir}/jetty-console.log
 JETTY_PORT=8080
 JETTY_RUN=%{_localstatedir}/run/%{name}
-JETTY_PID=\$JETTY_RUN/jetty.pid
 EO_RC
 ) > %{buildroot}%{homedir}/.jettyrc
 
@@ -704,6 +704,11 @@ for cdir in contexts contexts-available resources;do
     ln -sf %{homedir}/$cdir %{buildroot}/%{confdir}/$cdir
 done
 
+# remove demo configuration (rhbz#1083088)
+rm %{buildroot}%{homedir}/start.d/900-demo.ini
+
+# replace the startup script with ours
+cp -p %{SOURCE1} %{buildroot}%{homedir}/bin/jetty.sh
 
 %pre
 # Add the "jetty" user and group
@@ -737,11 +742,11 @@ getent passwd %username &>/dev/null || useradd  -r -u %jtuid -g %username \
 %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}
 %{homedir}
+%attr(744, jetty, jetty) %{homedir}/bin/jetty.sh
 %attr(755, jetty, jetty) %{logdir}
 %attr(755, jetty, jetty) %{tempdir}
 %ghost %dir %attr(755, jetty, jetty) %{rundir}
@@ -814,6 +819,10 @@ getent passwd %username &>/dev/null || useradd  -r -u %jtuid -g %username \
 %doc NOTICE.txt LICENSE*
 
 %changelog
+* Thu Apr 10 2014 Michael Simacek <msimacek at redhat.com> - 9.0.5-2
+- Simplify jetty startup script and use systemd features
+- Remove demo configuration (rhbz#1083088)
+
 * Thu Aug 22 2013 Michal Srb <msrb at redhat.com> - 9.0.5-1
 - Update to upstream version 9.0.5
 


More information about the scm-commits mailing list