From 4b0c1ca055cf7b3c8ce3d8b970b53f342286e6ea Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Wed, 14 Dec 2016 18:32:15 +0100 Subject: [PATCH] library/roles/smartgears/smartgears: Now the container.xml is generated by the get-scopes script. Only if a token was passed. See https://support.d4science.org/issues/6203. library/roles/smartgears/smartgears: Fix the tasks so that a multiple tomcat instances installation is possible, having smartgears running on only one tomcat instance. --- smartgears/smartgears/defaults/main.yml | 2 +- .../smartgears/tasks/smartgears-app.yml | 24 ++++++++--------- smartgears/smartgears/templates/get-scopes.j2 | 27 +++++++++++++++++-- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/smartgears/smartgears/defaults/main.yml b/smartgears/smartgears/defaults/main.yml index 87720fbd..40ee6b5e 100644 --- a/smartgears/smartgears/defaults/main.yml +++ b/smartgears/smartgears/defaults/main.yml @@ -44,7 +44,7 @@ http_port: '{{ smartgears_http_port }}' tomcat_m_webapps_unpack: True tomcat_m_instances: - - { http_enabled: True, http_port: '{{ smartgears_http_port }}', http_address: '0.0.0.0', ajp_enabled: False, ajp_port: '8109', ajp_address: '127.0.0.1', restart_timeout: '{{ tomcat_m_restart_timeout }}', shutdown_port: '-1', java_home: '{{ jdk_java_home }}', user: '{{ smartgears_user }}', user_home: '{{ smartgears_user_home }}', user_shell: '{{ tomcat_m_default_user_shell }}', instance_path: '{{ smartgears_instance_path }}', max_threads: '{{ tomcat_m_max_threads }}', autodeploy: '{{ tomcat_m_webapps_autodeploy }}', unpack: '{{ tomcat_m_webapps_unpack }}', default_conf: True, java_opts: '{{ tomcat_m_java_opts }}', java_gc_opts: '{{ tomcat_m_java_gc_opts }}', other_java_opts: '{{ tomcat_m_other_java_opts }}', jmx_enabled: '{{ tomcat_m_jmx_enabled }}', jmx_disable_additional_ports: '{{ tomcat_m_jmx_disable_additional_ports }}', jmx_port: '{{ tomcat_m_jmx_port }}', jmx_use_ssl: '{{ tomcat_m_jmx_use_ssl }}', jmx_auth_enabled: '{{ tomcat_m_jmx_auth_enabled }}', jmx_auth_dir: '{{ tomcat_m_instances_base_path }}/{{ smartgears_http_port }}/conf', jmx_monitorpass: '{{ tomcat_m_jmx_monitorpass | default(omit) }}', jmx_controlpass: '{{ tomcat_m_jmx_controlpass | default(omit) }}', remote_debugging: '{{ tomcat_m_enable_remote_debugging }}', remote_debugging_port: '{{ smartgears_debugging_port }}' , access_log_enabled: True, log_rotation_freq: daily, log_retain: 30, allowed_hosts: [ '0.0.0.0/0' ], app_contexts: '{{ smartgears_tomcat_contexts }}' , servername: '{{ ansible_fqdn }}' } + - { http_enabled: True, http_port: '{{ smartgears_http_port }}', http_address: '0.0.0.0', ajp_enabled: False, ajp_port: '8109', ajp_address: '127.0.0.1', restart_timeout: '{{ tomcat_m_restart_timeout }}', shutdown_port: '-1', java_home: '{{ jdk_java_home }}', user: '{{ smartgears_user }}', user_home: '{{ smartgears_user_home }}', user_shell: '{{ tomcat_m_default_user_shell }}', instance_path: '{{ smartgears_instance_path }}', max_threads: '{{ tomcat_m_max_threads }}', autodeploy: '{{ tomcat_m_webapps_autodeploy }}', unpack: '{{ tomcat_m_webapps_unpack }}', default_conf: True, java_opts: '{{ tomcat_m_java_opts }}', java_gc_opts: '{{ tomcat_m_java_gc_opts }}', other_java_opts: '{{ tomcat_m_other_java_opts }}', jmx_enabled: '{{ tomcat_m_jmx_enabled }}', jmx_disable_additional_ports: '{{ tomcat_m_jmx_disable_additional_ports }}', jmx_port: '{{ tomcat_m_jmx_port }}', jmx_use_ssl: '{{ tomcat_m_jmx_use_ssl }}', jmx_auth_enabled: '{{ tomcat_m_jmx_auth_enabled }}', jmx_auth_dir: '{{ tomcat_m_instances_base_path }}/{{ smartgears_http_port }}/conf', jmx_monitorpass: '{{ tomcat_m_jmx_monitorpass | default(omit) }}', jmx_controlpass: '{{ tomcat_m_jmx_controlpass | default(omit) }}', remote_debugging: '{{ tomcat_m_enable_remote_debugging }}', remote_debugging_port: '{{ smartgears_debugging_port }}' , access_log_enabled: True, log_rotation_freq: daily, log_retain: 30, allowed_hosts: [ '0.0.0.0/0' ], app_contexts: '{{ smartgears_tomcat_contexts }}', skip_smartgears: False, servername: '{{ ansible_fqdn }}' } # To enable debugging: # - Set diff --git a/smartgears/smartgears/tasks/smartgears-app.yml b/smartgears/smartgears/tasks/smartgears-app.yml index bb617d3a..5f1adf7d 100644 --- a/smartgears/smartgears/tasks/smartgears-app.yml +++ b/smartgears/smartgears/tasks/smartgears-app.yml @@ -12,6 +12,8 @@ become_user: '{{ smartgears_user }}' unarchive: copy=no src={{ smartgears_url }} dest={{ smartgears_user_home }} creates={{ smartgears_user_home }}/smartgears-distribution-{{ smartgears_distribution_version }} register: new_smartgears_distribution + with_items: '{{ tomcat_m_instances }}' + when: not item.skip_smartgears tags: [ 'smartgears', 'tomcat' ] - name: Stop the smartgears container before launching the upgrade script @@ -24,6 +26,7 @@ - name: Install the additional tomcat default file template: src=tomcat-instance-default.j2 dest=/etc/default/tomcat-instance-{{ item.http_port }}.local with_items: '{{ tomcat_m_instances }}' + when: not item.skip_smartgears notify: Restart smartgears tags: [ 'smartgears', 'tomcat', 'smartgears_env' ] @@ -32,12 +35,15 @@ become_user: '{{ smartgears_user }}' template: src=tomcat-instance-default.j2 dest={{ item.user_home }}/.bashrc mode=0444 with_items: '{{ tomcat_m_instances }}' + when: not item.skip_smartgears tags: [ 'smartgears', 'tomcat', 'smartgears_env' ] - name: Install the smartgears app shell: cd {{ item.user_home }}/smartgears-distribution-{{ smartgears_distribution_version }} ; . /{{ item.user_home }}/.bashrc ; ./install -s tomcat ; chown -R gcube:gcube '{{ item.user_home }}/smartgears-distribution-{{ smartgears_distribution_version }}' '{{ item.user_home }}/SmartGears/' '{{ item.user_home }}/tomcat/lib/' '{{ item.user_home }}/tomcat/webapps/' with_items: '{{ tomcat_m_instances }}' - when: ( new_smartgears_distribution | changed ) + when: + - ( new_smartgears_distribution | changed ) + - not item.skip_smartgears register: install_smartgears_app notify: Restart smartgears tags: [ 'smartgears', 'tomcat' ] @@ -61,13 +67,6 @@ template: src=scopes.list.j2 dest=/usr/local/etc/scopes.list owner=root group={{ smartgears_user }} mode=0444 tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ] -- name: Get the scope tokens from the authorization service - become: True - become_user: '{{ smartgears_user }}' - shell: /usr/local/bin/get-scopes {{ gcube_admin_token | default(omit) }} - when: gcube_admin_token is defined - tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ] - - name: Install the smartgears template configuration. First part become: True become_user: '{{ smartgears_user }}' @@ -82,13 +81,13 @@ with_items: '{{ tomcat_m_instances }}' tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ] -- name: Assemble the smartgears container.xml +- name: Get the scope tokens from the authorization service and assemble the container.xml file become: True become_user: '{{ smartgears_user }}' - assemble: src={{ smartgears_user_home }}/.containerxml dest={{ smartgears_install_path }}/container.xml - register: containerxml_state + shell: /usr/local/bin/get-scopes {{ gcube_admin_token | default(omit) }} + when: gcube_admin_token is defined tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ] - + - name: Remove the smartgears application state if the configuration changed file: dest={{ smartgears_install_path }}/state state=absent when: smartgears_remove_state @@ -98,6 +97,7 @@ - name: Install the script that manages the smartgears loglevel template: src=change-logback-loglevel.sh.j2 dest=/usr/local/bin/change-logback-loglevel owner=root group=root mode=0755 with_items: '{{ tomcat_m_instances }}' + when: not item.skip_smartgears tags: [ 'smartgears', 'smartgears_loglevel', 'tomcat' ] - name: Change the smartgears log level diff --git a/smartgears/smartgears/templates/get-scopes.j2 b/smartgears/smartgears/templates/get-scopes.j2 index d2c297c0..c72de226 100644 --- a/smartgears/smartgears/templates/get-scopes.j2 +++ b/smartgears/smartgears/templates/get-scopes.j2 @@ -1,17 +1,28 @@ #!/bin/bash -DESTFILE={{ smartgears_user_home }}/.containerxml/2-container.xml +CONTAINER_XML_HEAD={{ smartgears_user_home }}/.containerxml/1-container.xml +SCOPES_FILE={{ smartgears_user_home }}/.containerxml/2-container.xml +CONTAINER_XML_TAIL={{ smartgears_user_home }}/.containerxml/3-container.xml LOCAL_LIB=/usr/local/lib LOCAL_ETC=/usr/local/etc +LOG_PREFIX="get-scopes: " + +CONTAINER_XML_FILE={{ smartgears_install_path }}/container.xml + +RETVAL= SCOPES_LIST="" if [ -f $LOCAL_ETC/scopes.list ] ; then . $LOCAL_ETC/scopes.list +else + logger "$LOG_PREFIX There is no token list, aborting" + exit 1 fi if [ $# -ne 1 ] ; then echo "The token must be passed as the sole argument" + logger "$LOG_PREFIX The token must be passed as the sole argument" exit 1 fi TOKEN=$1 @@ -38,6 +49,18 @@ done cd $LOCAL_LIB -java TokenGenerator {{ smartgears_hostname }} $TOKEN $HTTP_PORT $DESTFILE $SCOPES_LIST +java TokenGenerator {{ smartgears_hostname }} $TOKEN $HTTP_PORT $SCOPES_FILE $SCOPES_LIST +RETVAL=$? +if [ $RETVAL -eq 0 ] ; then + logger "$LOG_PREFIX We got the scope tokens" +else + logger "$LOG_PREFIX Unable to obtain the scope tokens, aborting" + exit 1 +fi + +# Now that we have the tokens, we can assemble the container.xml file +cat $CONTAINER_XML_HEAD $SCOPES_FILE $CONTAINER_XML_TAIL > $CONTAINER_XML_FILE +chmod 440 $CONTAINER_XML_FILE +logger "$LOG_PREFIX $CONTAINER_XML_FILE updated" exit 0