From e14220a01b7cde09e030af144d5226ac938884f5 Mon Sep 17 00:00:00 2001 From: Guido Grazioli Date: Tue, 14 Dec 2021 16:01:41 +0100 Subject: [PATCH] Rewrite initd/systemd scripts interaction --- .github/workflows/ci.yml | 2 +- roles/keycloak/tasks/systemd.yml | 30 ++++--------------- .../keycloak/templates/keycloak-service.sh.j2 | 18 ++++++----- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 27f622a..9034acc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: working-directory: ./ansible_collections/middleware_automation/keycloak - name: Run molecule test - run: molecule test --all -- -vvvvv + run: molecule test --all working-directory: ./ansible_collections/middleware_automation/keycloak env: PY_COLORS: '1' diff --git a/roles/keycloak/tasks/systemd.yml b/roles/keycloak/tasks/systemd.yml index 777f6a6..67fd2e1 100644 --- a/roles/keycloak/tasks/systemd.yml +++ b/roles/keycloak/tasks/systemd.yml @@ -38,30 +38,12 @@ daemon_reload: yes when: systemdunit.changed -- block: - - name: start keycloak - systemd: - name: keycloak - enabled: yes - state: started - become: yes - rescue: - - command: "systemctl status keycloak" - changed_when: False - ignore_errors: True - - command: "journalctl -xe -ukeycloak" - changed_when: False - ignore_errors: True - - command: "tail -n 100 /opt/keycloak/keycloak.log" - changed_when: False - ignore_errors: True - - debug: - msg: "Virt type: {{ ansible_facts.virtualization_type }} - {{ ansible_facts['virtualization_type'] }}" - changed_when: False - ignore_errors: True - - command: "cat /opt/keycloak/keycloak-service.sh" - changed_when: False - ignore_errors: True +- name: start keycloak + systemd: + name: keycloak + enabled: yes + state: started + become: yes - command: "systemctl status keycloak" register: keycloak_service_status diff --git a/roles/keycloak/templates/keycloak-service.sh.j2 b/roles/keycloak/templates/keycloak-service.sh.j2 index 051af77..60adab2 100755 --- a/roles/keycloak/templates/keycloak-service.sh.j2 +++ b/roles/keycloak/templates/keycloak-service.sh.j2 @@ -75,14 +75,16 @@ startKeycloak() { if [ "$(isKeyCloakRunning)" -eq 1 ]; then statusKeycloak else - JLAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=${KEYCLOAK_PIDFILE} ${KEYCLOAK_HOME}/bin/standalone.sh \ - -Djboss.bind.address=${KEYCLOAK_BIND_ADDRESS} \ - -Djboss.http.port=${KEYCLOAK_HTTP_PORT} \ - -Djboss.https.port=${KEYCLOAK_HTTPS_PORT} \ - -Djboss.management.http.port=${KEYCLOAK_MANAGEMENT_HTTP_PORT} \ - -Djboss.management.https.port=${KEYCLOAK_MANAGEMENT_HTTPS_PORT} \ - -Djboss.node.name={{ inventory_hostname }} {% if ansible_facts.virtualization_type in ['docker','containerd'] %}-Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true {% endif %}\ - 2>&1 >> "${KEYCLOAK_LOGFILE}" & + LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=${KEYCLOAK_PIDFILE} ${KEYCLOAK_HOME}/bin/standalone.sh \ + -Djboss.bind.address=${KEYCLOAK_BIND_ADDRESS} \ + -Djboss.http.port=${KEYCLOAK_HTTP_PORT} \ + -Djboss.https.port=${KEYCLOAK_HTTPS_PORT} \ + -Djboss.management.http.port=${KEYCLOAK_MANAGEMENT_HTTP_PORT} \ + -Djboss.management.https.port=${KEYCLOAK_MANAGEMENT_HTTPS_PORT} \ + -Djboss.node.name={{ inventory_hostname }} \ + {% if ansible_facts.virtualization_type in ['docker','oci','containerd'] %}-Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true {% endif %}\ + 2>&1 >> "${KEYCLOAK_LOGFILE}" & + while [ ! -f ${KEYCLOAK_PIDFILE} ]; do sleep 1; done fi }