From e838a75f8462fb0bfc8233feaf14f8117c3569dd Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 19 Oct 2024 13:16:07 +0300 Subject: [PATCH 01/15] openfire.postinst and postrm: replace doc with a link --- build/debian/openfire.postinst | 18 +----------------- build/debian/openfire.postrm | 13 +------------ 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/build/debian/openfire.postinst b/build/debian/openfire.postinst index d54e3f710c..b97add29e7 100644 --- a/build/debian/openfire.postinst +++ b/build/debian/openfire.postinst @@ -1,23 +1,7 @@ #! /bin/sh set -e -# summary of how this script can be called: -# * `configure' -# * `abort-upgrade' -# * `abort-remove' `in-favour' -# -# * `abort-deconfigure' `in-favour' -# `removing' -# -# for details, see http://www.debian.org/doc/debian-policy/ or -# the debian-policy package -# -# quoting from the policy: -# Any necessary prompting should almost always be confined to the -# post-installation script, and should be protected with a conditional -# so that unnecessary prompting doesn't happen if a package's -# installation fails and the `postinst' is called with `abort-upgrade', -# `abort-remove' or `abort-deconfigure'. +# See https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html case "$1" in configure) diff --git a/build/debian/openfire.postrm b/build/debian/openfire.postrm index 8a2d21ec67..20966ea786 100644 --- a/build/debian/openfire.postrm +++ b/build/debian/openfire.postrm @@ -5,18 +5,7 @@ set -e -# summary of how this script can be called: -# * `remove' -# * `purge' -# * `upgrade' -# * `failed-upgrade' -# * `abort-install' -# * `abort-install' -# * `abort-upgrade' -# * `disappear' overwrit>r> -# for details, see http://www.debian.org/doc/debian-policy/ or -# the debian-policy package - +# See https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html case "$1" in purge) From e68f3a7d876536639f0daf922c241f7ccca5610d Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 19 Oct 2024 13:32:49 +0300 Subject: [PATCH 02/15] openfire.default: remove useless comment --- build/debian/openfire.default | 8 -------- 1 file changed, 8 deletions(-) diff --git a/build/debian/openfire.default b/build/debian/openfire.default index 378d14d212..6dc6485795 100644 --- a/build/debian/openfire.default +++ b/build/debian/openfire.default @@ -1,11 +1,3 @@ -# Defaults for openfire initscript -# sourced by /etc/init.d/openfire -# installed at /etc/default/openfire by the maintainer scripts - -# -# This is a POSIX shell fragment -# - # If you wish to override the auto-detected JAVA_HOME variable, uncomment # and change the following line. #JAVA_HOME=/usr/java/default From ebe7cbd62bca3d9f63c54cae1f65d6937fc04365 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 19 Oct 2024 14:03:37 +0300 Subject: [PATCH 03/15] openfire.sh: reformat tabs to two spaces --- distribution/src/bin/openfire.sh | 221 +++++++++++++++---------------- 1 file changed, 109 insertions(+), 112 deletions(-) diff --git a/distribution/src/bin/openfire.sh b/distribution/src/bin/openfire.sh index 4d365b5a3d..a57766e338 100644 --- a/distribution/src/bin/openfire.sh +++ b/distribution/src/bin/openfire.sh @@ -1,82 +1,79 @@ #!/bin/sh - -# -# - # tries to determine arguments to launch openfire -# OS specific support. $var _must_ be set to either true or false. +# OS specific support cygwin=false; darwin=false; linux=false; case "`uname`" in - CYGWIN*) cygwin=true ;; - Darwin*) darwin=true - if [ -z "$JAVA_HOME" ] ; then - JAVA_HOME=/usr/libexec/java_home - fi - ;; - Linux*) linux=true - if [ -z "$JAVA_HOME" ]; then - shopt -s nullglob - jdks=`ls -r1d /usr/java/j* /usr/lib/jvm/* 2>/dev/null` - for jdk in $jdks; do - if [ -f "$jdk/bin/java" ]; then - JAVA_HOME="$jdk" - break - fi - done - fi - ;; + CYGWIN*) + cygwin=true + ;; + Darwin*) + darwin=true + if [ -z "$JAVA_HOME" ] ; then + JAVA_HOME=/usr/libexec/java_home + fi + ;; + Linux*) + linux=true + if [ -z "$JAVA_HOME" ]; then + shopt -s nullglob + jdks=`ls -r1d /usr/java/j* /usr/lib/jvm/* 2>/dev/null` + for jdk in $jdks; do + if [ -f "$jdk/bin/java" ]; then + JAVA_HOME="$jdk" + break + fi + done + fi + ;; esac #if openfire home is not set or is not a directory if [ -z "$OPENFIRE_HOME" -o ! -d "$OPENFIRE_HOME" ]; then - - if [ -d /opt/openfire ] ; then - OPENFIRE_HOME="/opt/openfire" - fi - - if [ -d /usr/local/openfire ] ; then - OPENFIRE_HOME="/usr/local/openfire" - fi - - if [ -d ${HOME}/opt/openfire ] ; then - OPENFIRE_HOME="${HOME}/opt/openfire" - fi - - #resolve links - $0 may be a link in openfire's home - PRG="$0" - progname=`basename "$0$"` - - # need this for relative symlinks - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi - done - - #assumes we are in the bin directory - OPENFIRE_HOME=`dirname "$PRG"`/.. - - #make it fully qualified - OPENFIRE_HOME=`cd "$OPENFIRE_HOME" && pwd` + if [ -d /opt/openfire ] ; then + OPENFIRE_HOME="/opt/openfire" + fi + + if [ -d /usr/local/openfire ] ; then + OPENFIRE_HOME="/usr/local/openfire" + fi + + if [ -d ${HOME}/opt/openfire ] ; then + OPENFIRE_HOME="${HOME}/opt/openfire" + fi + + #resolve links - $0 may be a link in openfire's home + PRG="$0" + progname=`basename "$0$"` + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi + done + + #assumes we are in the bin directory + OPENFIRE_HOME=`dirname "$PRG"`/.. + + #make it fully qualified + OPENFIRE_HOME=`cd "$OPENFIRE_HOME" && pwd` fi OPENFIRE_OPTS="${OPENFIRE_OPTS} -DopenfireHome=\"${OPENFIRE_HOME}\"" # For Cygwin, ensure paths are in UNIX format before anything is touched if $cygwin ; then - [ -n "$OPENFIRE_HOME" ] && - OPENFIRE_HOME=`cygpath --unix "$OPENFIRE_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$OPENFIRE_HOME" ] && + OPENFIRE_HOME=`cygpath --unix "$OPENFIRE_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` fi #set the OPENFIRE_LIB location @@ -85,83 +82,83 @@ OPENFIRE_OPTS="${OPENFIRE_OPTS} -Dopenfire.lib.dir=\"${OPENFIRE_LIB}\"" # Override with bundled jre if it exists. if [ -f "$OPENFIRE_HOME/jre/bin/java" ]; then - JAVA_HOME="$OPENFIRE_HOME/jre" - JAVACMD="$OPENFIRE_HOME/jre/bin/java" + JAVA_HOME="$OPENFIRE_HOME/jre" + JAVACMD="$OPENFIRE_HOME/jre/bin/java" fi if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD=`which java 2> /dev/null ` - if [ -z "$JAVACMD" ] ; then - JAVACMD=java - fi - fi + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD=`which java 2> /dev/null ` + if [ -z "$JAVACMD" ] ; then + JAVACMD=java + fi + fi fi if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." - echo " We cannot execute $JAVACMD" - exit 1 + echo "Error: JAVA_HOME is not defined correctly." + echo " We cannot execute $JAVACMD" + exit 1 fi # Note: you can combine options, eg: -devboot -debug for arguments in "$@" do -case $arguments in + case $arguments in -debug) - echo "Starting debug mode" - JAVACMD="$JAVACMD -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005" - ;; + echo "Starting debug mode" + JAVACMD="$JAVACMD -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005" + ;; -remotedebug) - echo "Starting remote debug mode" - JAVACMD="$JAVACMD -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=\*:5005" - ;; + echo "Starting remote debug mode" + JAVACMD="$JAVACMD -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=\*:5005" + ;; -demoboot) - echo "Starting demoboot" - cp $OPENFIRE_HOME/conf/openfire-demoboot.xml $OPENFIRE_HOME/conf/openfire.xml - ;; + echo "Starting demoboot" + cp $OPENFIRE_HOME/conf/openfire-demoboot.xml $OPENFIRE_HOME/conf/openfire.xml + ;; -devboot) - HOSTNAME=$(hostname) - sed "s/example.org/$HOSTNAME/g" $OPENFIRE_HOME/conf/openfire-demoboot.xml > $OPENFIRE_HOME/conf/openfire.xml - ;; + HOSTNAME=$(hostname) + sed "s/example.org/$HOSTNAME/g" $OPENFIRE_HOME/conf/openfire-demoboot.xml > $OPENFIRE_HOME/conf/openfire.xml + ;; *) - # unknown option, pass through the Java command - JAVACMD="$JAVACMD $arguments" - ;; -esac + # unknown option, pass through the Java command + JAVACMD="$JAVACMD $arguments" + ;; + esac done JAVACMD="${JAVACMD} -Dlog4j.configurationFile=${OPENFIRE_LIB}/log4j2.xml -Dlog4j2.formatMsgNoLookups=true -Djdk.tls.ephemeralDHKeySize=matched -Djsse.SSLEngine.acceptLargeFragments=true -Djava.net.preferIPv6Addresses=system" if [ -z "$LOCALCLASSPATH" ] ; then - LOCALCLASSPATH=$OPENFIRE_LIB/startup.jar + LOCALCLASSPATH=$OPENFIRE_LIB/startup.jar else - LOCALCLASSPATH=$OPENFIRE_LIB/startup.jar:$LOCALCLASSPATH + LOCALCLASSPATH=$OPENFIRE_LIB/startup.jar:$LOCALCLASSPATH fi # For Cygwin, switch paths to appropriate format before running java if $cygwin; then - if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then - format=mixed - else - format=windows - fi - OPENFIRE_HOME=`cygpath --$format "$OPENFIRE_HOME"` - OPENFIRE_LIB=`cygpath --$format "$OPENFIRE_LIB"` - JAVA_HOME=`cygpath --$format "$JAVA_HOME"` - LOCALCLASSPATH=`cygpath --path --$format "$LOCALCLASSPATH"` - if [ -n "$CLASSPATH" ] ; then - CLASSPATH=`cygpath --path --$format "$CLASSPATH"` - fi - CYGHOME=`cygpath --$format "$HOME"` + if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then + format=mixed + else + format=windows + fi + OPENFIRE_HOME=`cygpath --$format "$OPENFIRE_HOME"` + OPENFIRE_LIB=`cygpath --$format "$OPENFIRE_LIB"` + JAVA_HOME=`cygpath --$format "$JAVA_HOME"` + LOCALCLASSPATH=`cygpath --path --$format "$LOCALCLASSPATH"` + if [ -n "$CLASSPATH" ] ; then + CLASSPATH=`cygpath --path --$format "$CLASSPATH"` + fi + CYGHOME=`cygpath --$format "$HOME"` fi # add a second backslash to variables terminated by a backslash under cygwin From 272a8c6906613db0a6b19b9d65b39110e127edc2 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 19 Oct 2024 14:18:07 +0300 Subject: [PATCH 04/15] openfire.sh: split OS detection and $JAVA_HOME detection --- distribution/src/bin/openfire.sh | 36 ++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/distribution/src/bin/openfire.sh b/distribution/src/bin/openfire.sh index a57766e338..848f031ae5 100644 --- a/distribution/src/bin/openfire.sh +++ b/distribution/src/bin/openfire.sh @@ -2,34 +2,38 @@ # tries to determine arguments to launch openfire # OS specific support -cygwin=false; -darwin=false; -linux=false; +cygwin=false +darwin=false +linux=false case "`uname`" in CYGWIN*) cygwin=true ;; Darwin*) darwin=true - if [ -z "$JAVA_HOME" ] ; then - JAVA_HOME=/usr/libexec/java_home - fi ;; Linux*) linux=true - if [ -z "$JAVA_HOME" ]; then - shopt -s nullglob - jdks=`ls -r1d /usr/java/j* /usr/lib/jvm/* 2>/dev/null` - for jdk in $jdks; do - if [ -f "$jdk/bin/java" ]; then - JAVA_HOME="$jdk" - break - fi - done - fi ;; esac +if [ -z "$JAVA_HOME" ] ; then + if $darwin ; then + JAVA_HOME=/usr/libexec/java_home + fi + if $linux; then + # shellcheck disable=SC2039 + shopt -s nullglob + jdks=$(ls -r1d /usr/java/j* /usr/lib/jvm/* 2>/dev/null) + for jdk in $jdks; do + if [ -f "$jdk/bin/java" ]; then + JAVA_HOME="$jdk" + break + fi + done + fi +fi + #if openfire home is not set or is not a directory if [ -z "$OPENFIRE_HOME" -o ! -d "$OPENFIRE_HOME" ]; then if [ -d /opt/openfire ] ; then From eed2580962138ad7a244e5f7959edd91a6cbbb5b Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 19 Oct 2024 14:21:08 +0300 Subject: [PATCH 05/15] openfire.sh: fix SC2006: Use $(...) notation instead of legacy backticked Remove unused progname --- distribution/src/bin/openfire.sh | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/distribution/src/bin/openfire.sh b/distribution/src/bin/openfire.sh index 848f031ae5..b465d7df5a 100644 --- a/distribution/src/bin/openfire.sh +++ b/distribution/src/bin/openfire.sh @@ -5,7 +5,7 @@ cygwin=false darwin=false linux=false -case "`uname`" in +case "$(uname)" in CYGWIN*) cygwin=true ;; @@ -50,24 +50,23 @@ if [ -z "$OPENFIRE_HOME" -o ! -d "$OPENFIRE_HOME" ]; then #resolve links - $0 may be a link in openfire's home PRG="$0" - progname=`basename "$0$"` # need this for relative symlinks while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` + ls=$(ls -ld "$PRG") + link=$(expr "$ls" : '.*-> \(.*\)$') if expr "$link" : '/.*' > /dev/null; then PRG="$link" else - PRG=`dirname "$PRG"`"/$link" + PRG=$(dirname "$PRG")"/$link" fi done #assumes we are in the bin directory - OPENFIRE_HOME=`dirname "$PRG"`/.. + OPENFIRE_HOME=$(dirname "$PRG")/.. #make it fully qualified - OPENFIRE_HOME=`cd "$OPENFIRE_HOME" && pwd` + OPENFIRE_HOME=$(cd "$OPENFIRE_HOME" && pwd) fi OPENFIRE_OPTS="${OPENFIRE_OPTS} -DopenfireHome=\"${OPENFIRE_HOME}\"" @@ -75,9 +74,9 @@ OPENFIRE_OPTS="${OPENFIRE_OPTS} -DopenfireHome=\"${OPENFIRE_HOME}\"" # For Cygwin, ensure paths are in UNIX format before anything is touched if $cygwin ; then [ -n "$OPENFIRE_HOME" ] && - OPENFIRE_HOME=`cygpath --unix "$OPENFIRE_HOME"` + OPENFIRE_HOME=$(cygpath --unix "$OPENFIRE_HOME") [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + JAVA_HOME=$(cygpath --unix "$JAVA_HOME") fi #set the OPENFIRE_LIB location @@ -99,7 +98,7 @@ if [ -z "$JAVACMD" ] ; then JAVACMD="$JAVA_HOME/bin/java" fi else - JAVACMD=`which java 2> /dev/null ` + JAVACMD=$(which java 2> /dev/null ) if [ -z "$JAVACMD" ] ; then JAVACMD=java fi @@ -155,14 +154,14 @@ if $cygwin; then else format=windows fi - OPENFIRE_HOME=`cygpath --$format "$OPENFIRE_HOME"` - OPENFIRE_LIB=`cygpath --$format "$OPENFIRE_LIB"` - JAVA_HOME=`cygpath --$format "$JAVA_HOME"` - LOCALCLASSPATH=`cygpath --path --$format "$LOCALCLASSPATH"` + OPENFIRE_HOME=$(cygpath --$format "$OPENFIRE_HOME") + OPENFIRE_LIB=$(cygpath --$format "$OPENFIRE_LIB") + JAVA_HOME=$(cygpath --$format "$JAVA_HOME") + LOCALCLASSPATH=$(cygpath --path --$format "$LOCALCLASSPATH") if [ -n "$CLASSPATH" ] ; then - CLASSPATH=`cygpath --path --$format "$CLASSPATH"` + CLASSPATH=$(cygpath --path --$format "$CLASSPATH") fi - CYGHOME=`cygpath --$format "$HOME"` + CYGHOME=$(cygpath --$format "$HOME") fi # add a second backslash to variables terminated by a backslash under cygwin From 6852da230c8837fc28a04e8a40f7f93949afd5b8 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 19 Oct 2024 14:27:39 +0300 Subject: [PATCH 06/15] openfire.sh: merge two $cygwin ifs --- distribution/src/bin/openfire.sh | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/distribution/src/bin/openfire.sh b/distribution/src/bin/openfire.sh index b465d7df5a..55d3596593 100644 --- a/distribution/src/bin/openfire.sh +++ b/distribution/src/bin/openfire.sh @@ -149,23 +149,21 @@ fi # For Cygwin, switch paths to appropriate format before running java if $cygwin; then - if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then - format=mixed - else - format=windows - fi - OPENFIRE_HOME=$(cygpath --$format "$OPENFIRE_HOME") - OPENFIRE_LIB=$(cygpath --$format "$OPENFIRE_LIB") - JAVA_HOME=$(cygpath --$format "$JAVA_HOME") - LOCALCLASSPATH=$(cygpath --path --$format "$LOCALCLASSPATH") - if [ -n "$CLASSPATH" ] ; then - CLASSPATH=$(cygpath --path --$format "$CLASSPATH") - fi - CYGHOME=$(cygpath --$format "$HOME") -fi + if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then + format=mixed + else + format=windows + fi + OPENFIRE_HOME=$(cygpath --$format "$OPENFIRE_HOME") + OPENFIRE_LIB=$(cygpath --$format "$OPENFIRE_LIB") + JAVA_HOME=$(cygpath --$format "$JAVA_HOME") + LOCALCLASSPATH=$(cygpath --path --$format "$LOCALCLASSPATH") + if [ -n "$CLASSPATH" ] ; then + CLASSPATH=$(cygpath --path --$format "$CLASSPATH") + fi + CYGHOME=$(cygpath --$format "$HOME") -# add a second backslash to variables terminated by a backslash under cygwin -if $cygwin; then + # add a second backslash to variables terminated by a backslash under cygwin case "$OPENFIRE_HOME" in *\\ ) OPENFIRE_HOME="$OPENFIRE_HOME\\" From 8b8d53bd04c00eb39f6b9980a750fee50afba2c6 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 19 Oct 2024 14:29:36 +0300 Subject: [PATCH 07/15] openfire.sh: fix shellcheck warnings --- distribution/src/bin/openfire.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/distribution/src/bin/openfire.sh b/distribution/src/bin/openfire.sh index 55d3596593..7f73e7c28f 100644 --- a/distribution/src/bin/openfire.sh +++ b/distribution/src/bin/openfire.sh @@ -1,6 +1,8 @@ #!/bin/sh # tries to determine arguments to launch openfire +# shellcheck disable=SC2166 + # OS specific support cygwin=false darwin=false @@ -44,7 +46,7 @@ if [ -z "$OPENFIRE_HOME" -o ! -d "$OPENFIRE_HOME" ]; then OPENFIRE_HOME="/usr/local/openfire" fi - if [ -d ${HOME}/opt/openfire ] ; then + if [ -d "${HOME}/opt/openfire" ] ; then OPENFIRE_HOME="${HOME}/opt/openfire" fi @@ -125,11 +127,11 @@ do ;; -demoboot) echo "Starting demoboot" - cp $OPENFIRE_HOME/conf/openfire-demoboot.xml $OPENFIRE_HOME/conf/openfire.xml + cp "$OPENFIRE_HOME/conf/openfire-demoboot.xml" "$OPENFIRE_HOME/conf/openfire.xml" ;; -devboot) HOSTNAME=$(hostname) - sed "s/example.org/$HOSTNAME/g" $OPENFIRE_HOME/conf/openfire-demoboot.xml > $OPENFIRE_HOME/conf/openfire.xml + sed "s/example.org/$HOSTNAME/g" "$OPENFIRE_HOME/conf/openfire-demoboot.xml" > "$OPENFIRE_HOME/conf/openfire.xml" ;; *) # unknown option, pass through the Java command @@ -187,4 +189,5 @@ if $cygwin; then fi openfire_exec_command="exec $JAVACMD -server $OPENFIRE_OPTS -classpath \"$LOCALCLASSPATH\" -jar \"$OPENFIRE_LIB/startup.jar\"" +# shellcheck disable=SC2086 eval $openfire_exec_command From 14e83a1abaa9cb76246002c16d35f3139e2fda97 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 19 Oct 2024 19:38:57 +0300 Subject: [PATCH 08/15] openfire.sh: use same JAVA_HOME search by alternatives as the init.d uses --- distribution/src/bin/openfire.sh | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/distribution/src/bin/openfire.sh b/distribution/src/bin/openfire.sh index 7f73e7c28f..1b1b8ac1ee 100644 --- a/distribution/src/bin/openfire.sh +++ b/distribution/src/bin/openfire.sh @@ -20,24 +20,34 @@ case "$(uname)" in esac if [ -z "$JAVA_HOME" ] ; then + echo "JAVA_HOME is empty, trying to find it" if $darwin ; then JAVA_HOME=/usr/libexec/java_home fi if $linux; then - # shellcheck disable=SC2039 - shopt -s nullglob - jdks=$(ls -r1d /usr/java/j* /usr/lib/jvm/* 2>/dev/null) - for jdk in $jdks; do - if [ -f "$jdk/bin/java" ]; then - JAVA_HOME="$jdk" - break - fi - done + JAVA_HOME=$(LC_ALL=C update-alternatives --display java \ + | grep best \ + | grep -oe "\/.*\/bin\/java" \ + | sed 's/\/bin\/java//g') + if [ -z "$JAVA_HOME" ] ; then + echo "Unable to get preferred JAVA_HOME from java alternative" + # shellcheck disable=SC2039 + shopt -s nullglob + jdks=$(ls -r1d /usr/java/j* /usr/lib/jvm/* 2>/dev/null) + for jdk in $jdks; do + if [ -f "$jdk/bin/java" ]; then + JAVA_HOME="$jdk" + break + fi + done + fi fi + echo "JAVA_HOME is set to $JAVA_HOME" fi #if openfire home is not set or is not a directory if [ -z "$OPENFIRE_HOME" -o ! -d "$OPENFIRE_HOME" ]; then + echo "OPENFIRE_HOME is empty, trying to find it" if [ -d /opt/openfire ] ; then OPENFIRE_HOME="/opt/openfire" fi @@ -69,6 +79,7 @@ if [ -z "$OPENFIRE_HOME" -o ! -d "$OPENFIRE_HOME" ]; then #make it fully qualified OPENFIRE_HOME=$(cd "$OPENFIRE_HOME" && pwd) + echo "OPENFIRE_HOME is set to $OPENFIRE_HOME" fi OPENFIRE_OPTS="${OPENFIRE_OPTS} -DopenfireHome=\"${OPENFIRE_HOME}\"" From e4d35913f878615607b2c89c860388d3ce01f18d Mon Sep 17 00:00:00 2001 From: Guus der Kinderen Date: Sat, 19 Oct 2024 18:52:28 +0300 Subject: [PATCH 09/15] OF-2786: Openfire to use system-defined preferences for IPv6 over IPv4 When establishing an outbound connection, Openfire now prefers the IP family as defined by the order in which the operating system returns addresses. This change is the openfire.init.d is same as was made in 30b4a176 for openfire.sh --- build/debian/openfire.init.d | 1 + 1 file changed, 1 insertion(+) diff --git a/build/debian/openfire.init.d b/build/debian/openfire.init.d index 3fafa06165..97cf0a2cca 100644 --- a/build/debian/openfire.init.d +++ b/build/debian/openfire.init.d @@ -47,6 +47,7 @@ test -x $JAVA || exit 1 DAEMON_OPTS="$DAEMON_OPTS -server -DopenfireHome=${DAEMON_DIR} \ -Dlog4j.configurationFile=${DAEMON_LIB}/log4j2.xml \ -Dlog4j2.formatMsgNoLookups=true \ + -Djdk.tls.ephemeralDHKeySize=matched -Djsse.SSLEngine.acceptLargeFragments=true -Djava.net.preferIPv6Addresses=system \ -Dopenfire.lib.dir=${DAEMON_LIB} -classpath ${DAEMON_LIB}/startup.jar\ -jar ${DAEMON_LIB}/startup.jar" From 791802178e0f71016aad99ab36f38307a47b4ca8 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 19 Oct 2024 21:19:20 +0300 Subject: [PATCH 10/15] openfire.sh: print options --- distribution/src/bin/openfire.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/distribution/src/bin/openfire.sh b/distribution/src/bin/openfire.sh index 1b1b8ac1ee..659624f9dd 100644 --- a/distribution/src/bin/openfire.sh +++ b/distribution/src/bin/openfire.sh @@ -127,6 +127,7 @@ fi # Note: you can combine options, eg: -devboot -debug for arguments in "$@" do + echo "Option: $arguments" case $arguments in -debug) echo "Starting debug mode" From 6127a33e7357931b980d71a593a332ce7ae302ef Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 19 Oct 2024 21:20:12 +0300 Subject: [PATCH 11/15] debian package: Install /usr/share/openfire/bin/openfire.sh --- build/debian/openfire.dirs | 1 + build/debian/openfire.install | 1 + 2 files changed, 2 insertions(+) diff --git a/build/debian/openfire.dirs b/build/debian/openfire.dirs index 41058b4a04..cbfc0b3f31 100644 --- a/build/debian/openfire.dirs +++ b/build/debian/openfire.dirs @@ -1,4 +1,5 @@ /etc/openfire +/usr/share/openfire/bin /usr/share/openfire/lib /usr/share/openfire/resources /var/log/openfire diff --git a/build/debian/openfire.install b/build/debian/openfire.install index 03648eb6cc..a73246d1c7 100644 --- a/build/debian/openfire.install +++ b/build/debian/openfire.install @@ -1,3 +1,4 @@ +bin/openfire.sh /usr/share/openfire/bin lib/*.jar usr/share/openfire/lib lib/log4j2.xml etc/openfire resources/database usr/share/openfire/resources From c1144d3adbde02738833fdd436e27390299485a0 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 19 Oct 2024 21:21:05 +0300 Subject: [PATCH 12/15] debian package: Install UFW rules --- build/debian/openfire.install | 1 + .../src/assembly/basic-distribution.xml | 5 +++ .../src/dist/etc/ufw/applications.d/openfire | 39 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 distribution/src/dist/etc/ufw/applications.d/openfire diff --git a/build/debian/openfire.install b/build/debian/openfire.install index a73246d1c7..18d9faa7c0 100644 --- a/build/debian/openfire.install +++ b/build/debian/openfire.install @@ -6,3 +6,4 @@ conf/openfire.xml etc/openfire conf/security.xml etc/openfire resources/security etc/openfire plugins var/lib/openfire +dist/* / diff --git a/distribution/src/assembly/basic-distribution.xml b/distribution/src/assembly/basic-distribution.xml index 7f1e1cfdd1..f36c43d451 100644 --- a/distribution/src/assembly/basic-distribution.xml +++ b/distribution/src/assembly/basic-distribution.xml @@ -119,6 +119,11 @@ true + + + ${project.basedir}/src/dist + dist + diff --git a/distribution/src/dist/etc/ufw/applications.d/openfire b/distribution/src/dist/etc/ufw/applications.d/openfire new file mode 100644 index 0000000000..0617f5c65f --- /dev/null +++ b/distribution/src/dist/etc/ufw/applications.d/openfire @@ -0,0 +1,39 @@ +[Openfire C2S] +title=Openfire XMPP Server - Client to Server (C2S) connections +description=Allow for XMPP clients to connect to the server and also use File Transfers +ports=5222|5223|8010|7777 + +[Openfire Web] +title=Openfire XMPP Server - Web Binding for WebSocket and BOSH +description=Allow for XMPP web clients to connect to the server +ports=7070|7443 + +[Openfire S2S] +title=Openfire XMPP Server - Server to Server (S2S) connections +description=This allows users from your server to talk with users from other servers in internet (federation). If your server used for internal company communication you should disable this. +ports=5269|5270 + +[Openfire External Components] +title=Openfire XMPP Server - External Components +description=This allows to connect for XEP-0114 Jabber Component Protocol +ports=5275|5276 + +[Openfire Proxy] +title=Openfire XMPP Server - TURN Proxy and STUN server +description=This allows users to use calls and file transfer between each others when they are behind NAT. +ports=3478|5349 + +[Openfire Connection Manager] +title=Openfire XMPP Server - Connection Manager +description=Openfire Connection Manager improves the scalability of server by handling a portion of the client connections +ports=5262|5263 + +[Openfire Admin Console] +title=Openfire XMPP Server - Admin Console +description=You can manage the XMPP server from a web admin console +ports=9090|9091 + +[Openfire Full] +title=Openfire XMPP Server - All components (C2S + S2S + External Components + Proxy + Connection Manager + Admin Console) +description=Open all ports that are exposed by the Openfire +ports=5222|5223|8010|7777|7070|7443|5269|5270|5275|5276|3478|5349|5262|5263|9090|9091 From c5593016b0b90dfa1aa79e9d2529f16db04a93fc Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 19 Oct 2024 21:22:15 +0300 Subject: [PATCH 13/15] admin console setup page: check JRE version with Runtime.Version --- xmppserver/src/main/webapp/setup/index.jsp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/xmppserver/src/main/webapp/setup/index.jsp b/xmppserver/src/main/webapp/setup/index.jsp index 95a084dfb7..bfb92006dc 100644 --- a/xmppserver/src/main/webapp/setup/index.jsp +++ b/xmppserver/src/main/webapp/setup/index.jsp @@ -43,12 +43,9 @@ boolean openfireHomeExists = false; Path openfireHome = null; - // Check for JRE 1.8 - try { - String version = System.getProperty("java.version"); - jreVersionCompatible = Integer.parseInt(version.split("\\.")[0]) >= 11; - } - catch (Throwable t) {} + // Check for min JRE requirement + Runtime.Version MIN_JAVA_VERSION = Runtime.Version.parse("11"); + jreVersionCompatible = MIN_JAVA_VERSION.compareTo(Runtime.version()) <= 0; // Check for Servlet 2.3: try { Class c = ClassUtils.forName("javax.servlet.http.HttpSession"); From 7d97327a43fd8ae8b4d909183e73b6cefbfeec61 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 19 Oct 2024 21:30:14 +0300 Subject: [PATCH 14/15] OF-2526: Support SystemD in Debian package --- .../usr/lib/systemd/system/openfire.service | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 distribution/src/dist/usr/lib/systemd/system/openfire.service diff --git a/distribution/src/dist/usr/lib/systemd/system/openfire.service b/distribution/src/dist/usr/lib/systemd/system/openfire.service new file mode 100644 index 0000000000..88b2596030 --- /dev/null +++ b/distribution/src/dist/usr/lib/systemd/system/openfire.service @@ -0,0 +1,17 @@ +[Unit] +Description=Openfire XMPP Server +After=network.target + +[Service] +User=openfire +Group=openfire +EnvironmentFile=-/etc/default/openfire +Type=simple +WorkingDirectory=/usr/share/openfire/ +ExecStart=/bin/bash -c '/usr/share/openfire/bin/openfire.sh ${DAEMON_OPTS}' +Restart=on-failure +RuntimeDirectory=openfire + +[Install] +WantedBy=multi-user.target +Alias=xmpp.service From 12422c427a54c2fa1f41dba3f707dc4ca8441236 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 19 Oct 2024 22:46:39 +0300 Subject: [PATCH 15/15] OF-2526: SystemD: limit resources and add openfire.slice --- .../src/dist/usr/lib/systemd/system/openfire.service | 9 +++++++++ .../src/dist/usr/lib/systemd/system/openfire.slice | 5 +++++ 2 files changed, 14 insertions(+) create mode 100644 distribution/src/dist/usr/lib/systemd/system/openfire.slice diff --git a/distribution/src/dist/usr/lib/systemd/system/openfire.service b/distribution/src/dist/usr/lib/systemd/system/openfire.service index 88b2596030..8a7fb98be5 100644 --- a/distribution/src/dist/usr/lib/systemd/system/openfire.service +++ b/distribution/src/dist/usr/lib/systemd/system/openfire.service @@ -12,6 +12,15 @@ ExecStart=/bin/bash -c '/usr/share/openfire/bin/openfire.sh ${DAEMON_OPTS}' Restart=on-failure RuntimeDirectory=openfire +# Specify resource limits in the slice +Slice=openfire.slice +# We expect a lot of connections from many clients so increase limit of file descriptiors +LimitNOFILE=50000 +# The Openfire is less important for CPU than system vital services +Nice=5 +# If not enough RAM then kill the Openfire first to preserve system vital services +OOMScoreAdjust=-100 + [Install] WantedBy=multi-user.target Alias=xmpp.service diff --git a/distribution/src/dist/usr/lib/systemd/system/openfire.slice b/distribution/src/dist/usr/lib/systemd/system/openfire.slice new file mode 100644 index 0000000000..eef22a5749 --- /dev/null +++ b/distribution/src/dist/usr/lib/systemd/system/openfire.slice @@ -0,0 +1,5 @@ +[Slice] +#MemoryAccounting=yes +#MemoryMax=95% +#CPUQuota=95% +#CPUAccounting=yes