From c13b556fc84a31dc5ae88512e1282016f8301827 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Mon, 18 Jul 2022 18:41:12 +0200 Subject: [PATCH] Fix the restart sequence. --- defaults/main.yml | 3 ++- handlers/main.yml | 33 +++++++++------------------------ tasks/main.yml | 40 ++++++++++++++-------------------------- 3 files changed, 25 insertions(+), 51 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 6b35a88..5390b15 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -40,7 +40,8 @@ tomcat_m_shutdown_port: -1 tomcat_m_shutdown_pwd: "{{ lookup('password', '/tmp/passwordfile chars=ascii_letters,digits,hexdigits,punctuation') }}" tomcat_m_max_threads: 200 tomcat_m_min_heap_size: 2048m -tomcat_m_heap_size: '{{ tomcat_m_min_heap_size }}' +catalina_tomcat_m_heap_size: '{{ tomcat_m_min_heap_size }}' +tomcat_m_heap_size: '{{ catalina_tomcat_m_heap_size }}' tomcat_m_permgen_size: 512m tomcat_m_file_encoding: 'UTF-8' tomcat_m_restart_timeout: 300 diff --git a/handlers/main.yml b/handlers/main.yml index 35d8704..7aea0ad 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,28 +1,13 @@ --- -- name: tomcat restart instances with changed configs - service: name='tomcat-instance-{{ item.item.http_port }}' state=restarted sleep=20 - with_items: '{{ restart_needed.results }}' - when: item is changed - ignore_errors: True - -- name: tomcat restart instances with changed jmx config - service: name='tomcat-instance-{{ item.item.http_port }}' state=restarted sleep=20 - with_items: '{{ jmx_restart_needed.results }}' - when: item is changed - ignore_errors: True - -- name: tomcat instances restart - service: name='tomcat-instance-{{ item.http_port }}' state=restarted sleep=20 - with_items: '{{ tomcat_m_instances }}' - ignore_errors: True - -- name: enable tomcat instances - service: name='tomcat-instance-{{ item.http_port }}' state=started enabled=yes sleep=20 - with_items: '{{ tomcat_m_instances }}' - ignore_errors: True +- name: tomcat multiple-instances restart + service: + name: 'tomcat-instance-{{ item.http_port }}' + state: restarted + sleep: 20 + loop: '{{ tomcat_m_instances }}' + ignore_errors: true - name: disable tomcat instances service: name='tomcat-instance-{{ item.http_port }}' state=stopped enabled=no sleep=20 - with_items: '{{ tomcat_m_instances }}' - ignore_errors: True - + loop: '{{ tomcat_m_instances }}' + ignore_errors: true diff --git a/tasks/main.yml b/tasks/main.yml index 2f8b20e..b64c4c5 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -6,7 +6,7 @@ service: name='tomcat{{ tomcat_version }}' state=stopped enabled=no when: not tomcat_service_enabled tags: [ 'tomcat', 'tomcat_instances' ] - + - name: Create a tomcat user for each instance if needed user: name={{ item.user }} home={{ item.user_home }} createhome=false shell={{ item.user_shell | default('/bin/false') }} with_items: '{{ tomcat_m_instances }}' @@ -82,8 +82,7 @@ with_nested: - '{{ tomcat_m_instances }}' - [ 'context.xml' ] - register: restart_needed - notify: tomcat restart instances with changed configs + notify: tomcat multiple-instances restart tags: [ 'tomcat', 'tomcat_instances' ] - name: Install catalina.properties @@ -91,8 +90,7 @@ with_nested: - '{{ tomcat_m_instances }}' - [ 'catalina.properties' ] - register: restart_needed - notify: tomcat restart instances with changed configs + notify: tomcat multiple-instances restart tags: [ 'tomcat', 'tomcat_instances', 'tomcat_catalina_properties' ] - name: Populate the instances conf/policy.d directory @@ -100,8 +98,7 @@ with_nested: - '{{ tomcat_m_instances }}' - [ '01system.policy', '02debian.policy', '03catalina.policy', '04webapps.policy', '50local.policy' ] - register: restart_needed - notify: tomcat restart instances with changed configs + notify: tomcat multiple-instances restart tags: [ 'tomcat', 'tomcat_instances' ] - name: Install logging.properties if we do not use log4j for the tomcat logging @@ -112,22 +109,19 @@ when: - tomcat_use_log4j is defined - not tomcat_use_log4j | bool - register: restart_needed - notify: tomcat restart instances with changed configs + notify: tomcat multiple-instances restart tags: [ 'tomcat', 'tomcat_instances' ] - name: Install the server.xml conf file template: src=tomcat-server.xml.j2 dest={{ item.instance_path }}/conf/server.xml owner={{ item.user }} group={{ item.user }} mode=0640 with_items: '{{ tomcat_m_instances }}' - register: restart_needed - notify: tomcat restart instances with changed configs + notify: tomcat multiple-instances restart tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_serverxml' ] - name: Install the web.xml file template: src=tomcat-web.xml.j2 dest={{ item.instance_path }}/conf/web.xml owner={{ item.user }} group={{ item.user }} mode=0640 with_items: '{{ tomcat_m_instances }}' - register: restart_needed - notify: tomcat restart instances with changed configs + notify: tomcat multiple-instances restart tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_serverxml' ] - name: Install the tomcat-admin package if the host-manager or manager apps are required @@ -138,24 +132,21 @@ - name: Install the catalina configuration for the tomcat manager template: src=tomcat-manager.xml.j2 dest={{ item.instance_path }}/conf/Catalina/localhost/manager.xml owner={{ item.user }} group={{ item.user }} mode=0640 with_items: '{{ tomcat_m_instances }}' - register: restart_needed when: tomcat_m_manager_install | bool - notify: tomcat restart instances with changed configs + notify: tomcat multiple-instances restart tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_manager' ] - name: Install the catalina configuration for the tomcat host manager template: src=tomcat-host-manager.xml.j2 dest={{ item.instance_path }}/conf/Catalina/localhost/host-manager.xml owner={{ item.user }} group={{ item.user }} mode=0640 with_items: '{{ tomcat_m_instances }}' - register: restart_needed when: tomcat_m_host_manager_install | bool - notify: tomcat restart instances with changed configs + notify: tomcat multiple-instances restart tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_host_manager' ] - name: Install the catalina configuration for the tomcat manager template: src=tomcat-users.xml.j2 dest={{ item.instance_path }}/conf/tomcat-users.xml owner={{ item.user }} group={{ item.user }} mode=0640 with_items: '{{ tomcat_m_instances }}' - register: restart_needed - notify: tomcat restart instances with changed configs + notify: tomcat multiple-instances restart tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_host_manager', 'tomcat_manager' ] - name: Install the instances startup scripts @@ -167,7 +158,7 @@ - name: Install the tomcat instances default file template: src=tomcat-default.j2 dest=/etc/default/tomcat-instance-{{ item.http_port }} mode=0640 owner=root group={{ item.user }} with_items: '{{ tomcat_m_instances }}' - notify: tomcat instances restart + notify: tomcat multiple-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 @@ -179,8 +170,7 @@ - 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 }}' - register: restart_needed - notify: tomcat restart instances with changed configs + notify: tomcat multiple-instances restart when: tomcat_m_jndi_pool | bool tags: [ 'tomcat', 'tomcat_instances', 'tomcat_conf', 'tomcat_contextxml', 'jdk' ] @@ -197,8 +187,7 @@ - item.jmx_auth_enabled is defined - item.jmx_enabled | bool - item.jmx_auth_enabled | bool - register: jmx_restart_needed - notify: tomcat restart instances with changed jmx config + notify: tomcat multiple-instances restart tags: [ 'tomcat', 'tomcat_instances', 'tomcat_jmx' ] - name: Install the jmx role file @@ -209,8 +198,7 @@ - item.jmx_auth_enabled is defined - item.jmx_enabled | bool - item.jmx_auth_enabled | bool - register: jmx_restart_needed - notify: tomcat restart instances with changed jmx config + notify: tomcat multiple-instances restart tags: [ 'tomcat', 'tomcat_instances', 'tomcat_jmx' ] - name: Start all the tomcat instances