From 5627a97bca4e536938e71d63fc14ffeed39492b8 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Wed, 3 Apr 2019 17:13:39 +0200 Subject: [PATCH] dataminer, dataminer-multiple-instances: fixes to support tomcat 8. --- tomcat-multiple-instances/tasks/main.yml | 5 ++ .../templates/tomcat-instance.init.j2 | 50 ++++++++++++------- .../templates/tomcat-server.xml.j2 | 2 + tomcat/tasks/main.yml | 4 +- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/tomcat-multiple-instances/tasks/main.yml b/tomcat-multiple-instances/tasks/main.yml index ff9d0d8f..87bfea02 100644 --- a/tomcat-multiple-instances/tasks/main.yml +++ b/tomcat-multiple-instances/tasks/main.yml @@ -148,6 +148,7 @@ - name: Install the instances startup scripts template: src=tomcat-instance.init.j2 dest=/etc/init.d/tomcat-instance-{{ item.http_port }} mode=0755 owner=root group=root with_items: '{{ tomcat_m_instances }}' + register: reload_systemd tags: [ 'tomcat', 'tomcat_instances', 'tomcat_init' ] - name: Install the tomcat instances default file @@ -156,6 +157,10 @@ notify: tomcat instances restart tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_default', 'jdk' ] +- name: Reload the systemd daemon if we are running on a systemd-backed server + command: systemctl daemon-reload + when: ansible_service_mgr == 'systemd' + - name: Install a custom context.xml file template: src=tomcat-context.xml.j2 dest={{ item.instance_path }}/conf/context.xml owner={{ item.user }} group={{ item.user }} mode=0640 with_items: '{{ tomcat_m_instances }}' diff --git a/tomcat-multiple-instances/templates/tomcat-instance.init.j2 b/tomcat-multiple-instances/templates/tomcat-instance.init.j2 index 99f26c53..d13361c5 100755 --- a/tomcat-multiple-instances/templates/tomcat-instance.init.j2 +++ b/tomcat-multiple-instances/templates/tomcat-instance.init.j2 @@ -1,6 +1,6 @@ #!/bin/sh # -# /etc/init.d/tomcat-instance-{{ item.http_port }} -- startup script for the Tomcat 7 {{ item.user }} servlet engine on port {{ item.http_port }} +# /etc/init.d/tomcat-instance-{{ item.http_port }} -- startup script for the Tomcat {{ tomcat_version }} {{ item.user }} servlet engine on port {{ item.http_port }} # # Written by Miquel van Smoorenburg . # Modified for Debian GNU/Linux by Ian Murdock . @@ -10,7 +10,7 @@ # Additional improvements by Jason Brittain . # ### BEGIN INIT INFO -# Provides: tomcat-instance-8280 +# Provides: tomcat-instance-{{ item.http_port }} # Required-Start: $local_fs $remote_fs $network # Required-Stop: $local_fs $remote_fs $network # Should-Start: $named @@ -49,15 +49,29 @@ fi # The following variables can be overwritten in $DEFAULT -# Run Tomcat 7 as this user ID and group ID -TOMCAT7_USER={{ item.user }} -TOMCAT7_GROUP={{ item.user }} +# Run Tomcat {{ tomcat_version }} as this user ID and group ID +TOMCAT{{ tomcat_version }}_USER={{ item.user }} +TOMCAT{{ tomcat_version }}_GROUP={{ item.user }} # this is a work-around until there is a suitable runtime replacement # for dpkg-architecture for arch:all packages # this function sets the variable OPENJDKS find_openjdks() { + for jvmdir in /usr/lib/jvm/java-11-openjdk-* + do + if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-11-openjdk-common" ] + then + OPENJDKS=$jvmdir + fi + done + for jvmdir in /usr/lib/jvm/java-8-openjdk-* + do + if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-8-openjdk-common" ] + then + OPENJDKS=$jvmdir + fi + done for jvmdir in /usr/lib/jvm/java-7-openjdk-* do if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-7-openjdk-common" ] @@ -89,13 +103,13 @@ done export JAVA_HOME # Directory where the Tomcat binary distribution resides -CATALINA_HOME=/usr/share/tomcat7 +CATALINA_HOME=/usr/share/tomcat{{ tomcat_version }} # Directory for per-instance configuration files and webapps CATALINA_BASE={{ item.instance_path }} # Use the Java security manager? (yes/no) -TOMCAT7_SECURITY=no +TOMCAT{{ tomcat_version }}_SECURITY=no # Default Java options # Set java.awt.headless=true if JAVA_OPTS is not set so the @@ -124,13 +138,13 @@ if [ -z "$CATALINA_TMPDIR" ]; then CATALINA_TMPDIR="$JVM_TMP" fi -# Set the JSP compiler if set in the tomcat7.default file +# Set the JSP compiler if set in the ${ NAME }.default file if [ -n "$JSP_COMPILER" ]; then JAVA_OPTS="$JAVA_OPTS -Dbuild.compiler=\"$JSP_COMPILER\"" fi SECURITY="" -if [ "$TOMCAT7_SECURITY" = "yes" ]; then +if [ "$TOMCAT{{ tomcat_version }}_SECURITY" = "yes" ]; then SECURITY="-security" fi @@ -172,9 +186,9 @@ catalina_sh() { # Run the catalina.sh script as a daemon set +e touch "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out - chown $TOMCAT7_USER "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out - start-stop-daemon --start -b -u "$TOMCAT7_USER" -g "$TOMCAT7_GROUP" \ - -c "$TOMCAT7_USER" -d "$CATALINA_TMPDIR" -p "$CATALINA_PID" \ + chown $TOMCAT{{ tomcat_version }}_USER "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out + start-stop-daemon --start -b -u "$TOMCAT{{ tomcat_version }}_USER" -g "$TOMCAT{{ tomcat_version }}_GROUP" \ + -c "$TOMCAT{{ tomcat_version }}_USER" -d "$CATALINA_TMPDIR" -p "$CATALINA_PID" \ -x /bin/bash -- -c "$AUTHBIND_COMMAND $TOMCAT_SH" status="$?" set +a -e @@ -195,7 +209,7 @@ case "$1" in log_daemon_msg "Starting $DESC" "$NAME" if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ - --user $TOMCAT7_USER --exec "$JAVA_HOME/bin/java" \ + --user $TOMCAT{{ tomcat_version }}_USER --exec "$JAVA_HOME/bin/java" \ >/dev/null; then # Regenerate POLICY_CACHE file @@ -212,12 +226,12 @@ case "$1" in log_failure_msg "could not create JVM temporary directory" exit 1 } - chown $TOMCAT7_USER "$JVM_TMP" + chown $TOMCAT{{ tomcat_version }}_USER "$JVM_TMP" catalina_sh start $SECURITY sleep 5 if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ - --user $TOMCAT7_USER --exec "$JAVA_HOME/bin/java" \ + --user $TOMCAT{{ tomcat_version }}_USER --exec "$JAVA_HOME/bin/java" \ >/dev/null; then if [ -f "$CATALINA_PID" ]; then rm -f "$CATALINA_PID" @@ -237,7 +251,7 @@ case "$1" in set +e if [ -f "$CATALINA_PID" ]; then start-stop-daemon --stop --pidfile "$CATALINA_PID" \ - --user "$TOMCAT7_USER" \ + --user "$TOMCAT{{ tomcat_version }}_USER" \ --retry=TERM/20/KILL/5 >/dev/null if [ $? -eq 1 ]; then log_progress_msg "$DESC is not running but pid file exists, cleaning up" @@ -257,7 +271,7 @@ case "$1" in status) set +e start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ - --user $TOMCAT7_USER --exec "$JAVA_HOME/bin/java" \ + --user $TOMCAT{{ tomcat_version }}_USER --exec "$JAVA_HOME/bin/java" \ >/dev/null 2>&1 if [ "$?" = "0" ]; then @@ -282,7 +296,7 @@ case "$1" in ;; try-restart) if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ - --user $TOMCAT7_USER --exec "$JAVA_HOME/bin/java" \ + --user $TOMCAT{{ tomcat_version }}_USER --exec "$JAVA_HOME/bin/java" \ >/dev/null; then $0 start fi diff --git a/tomcat-multiple-instances/templates/tomcat-server.xml.j2 b/tomcat-multiple-instances/templates/tomcat-server.xml.j2 index 7dbc9738..3a7863a0 100644 --- a/tomcat-multiple-instances/templates/tomcat-server.xml.j2 +++ b/tomcat-multiple-instances/templates/tomcat-server.xml.j2 @@ -21,7 +21,9 @@ {% else %} {% endif %} +{% if tomcat_version <= 7 %} +{% endif %} diff --git a/tomcat/tasks/main.yml b/tomcat/tasks/main.yml index a8d51ecc..96f52096 100644 --- a/tomcat/tasks/main.yml +++ b/tomcat/tasks/main.yml @@ -10,10 +10,10 @@ - import_tasks: tomcat-log4j-logging.yml when: - tomcat_use_log4j - - tomcat_version <= '7' + - tomcat_version <= 7 tags: [ 'tomcat', 'tomcat_log4j' ] - import_tasks: tomcat-logger-logging.yml - when: not tomcat_use_log4j or tomcat_version > '7' + when: not tomcat_use_log4j or tomcat_version > 7 - import_tasks: access_log.yml when: tomcat_access_log_enabled - import_tasks: pgsql_jdbc.yml