Skip to content

Commit

Permalink
Merge pull request #9 from wcm-io-devops/feature/restricted-mode
Browse files Browse the repository at this point in the history
Add restricted mode, reimplement wait for AEM service stop
  • Loading branch information
Tobias Richter authored Aug 5, 2019
2 parents 430c2c1 + 640c8bb commit d6140be
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 6 deletions.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ This role controls an Adobe Experience Manager (AEM) 6.x service on Linux server
## Requirements

This role requires Ansible 2.0 or higher and works with AEM 6.1 or higher. The role requires an AEM service that can be controlled with the Ansible `service` module to be installed on the target machine.
This role requires Ansible 2.4 or higher and works with AEM 6.1 or
higher. The role requires an AEM service that can be controlled with the
Ansible `service` module to be installed on the target machine.

## Role Variables

Expand All @@ -34,6 +36,35 @@ The desired state of the service after this role finishes, one of `started`, `st

The time to wait for the startup or shutdown to finish (in seconds).

aem_service_restricted_mode: false

Enables / disables the restricted mode to work with customized commands like `sudo`.

# aem_service_start_command:

Overwrites the default (service manager related) start command.

# aem_service_stop_command:

Overwrites the default (service manager related) stop command.

# aem_service_status_command:

Overwrites the default (service manager related) status command.

# aem_service_status_stopped_status_codes:

Overwrites the default (service manager related) stopped status codes
when set.

# aem_service_status_started_status_codes:

Overwrites the default (service manager related) started status codes
when set.

aem_service_status_valid_status_codes: "{{ _aem_service_status_stopped_status_codes | union(_aem_service_status_started_status_codes) | unique }}"

# List of all valid AEM status codes.

## Dependencies

Expand Down
21 changes: 21 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,24 @@ aem_service_state: started
aem_service_timeout: 1200
# URL to poll while waiting for startup
aem_service_login_url: "http://localhost:{{ aem_service_port }}/libs/granite/core/content/login.html"

# Enables / disables the restricted mode to work with customized commands like sudo
aem_service_restricted_mode: false

# Overwrites the default (service manager related) start command
# aem_service_start_command:

# Overwrites the default (service manager related) stop command
# aem_service_stop_command:

# Overwrites the default (service manager related) status command
# aem_service_status_command:

# Overwrites the default (service manager related) stopped status codes
# aem_service_status_stopped_status_codes:

# Overwrites the default (service manager related) started status codes
# aem_service_status_started_status_codes:

# List of all valid AEM status codes.
aem_service_status_valid_status_codes: "{{ _aem_service_status_stopped_status_codes | union(_aem_service_status_started_status_codes) | unique }}"
6 changes: 6 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
- name: Include service manager specific variables.
include_vars: "{{ item }}"
with_first_found:
- "service_mgr_{{ ansible_service_mgr | mandatory }}.yml"
- service_mgr_default.yml

- include_tasks: start_aem.yml
when: aem_service_state == 'started'

Expand Down
22 changes: 19 additions & 3 deletions tasks/start_aem.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
- name: Start AEM.
- name: Start AEM (escalated).
service:
name: "{{ aem_service_name }}"
state: started
register: aem_service_start_result
register: aem_service_start_result_escalated
when: not aem_service_restricted_mode

- name: Start AEM (restricted).
block:
- name: Retrieve AEM status (restricted).
raw: "{{ _aem_service_status_command }}"
changed_when: false
register: _aem_status_result_1
failed_when: _aem_status_result_1.rc not in aem_service_status_valid_status_codes

- name: Start AEM (restricted).
raw: "{{ _aem_service_start_command }}"
when: _aem_status_result_1.rc != 0
register: aem_service_start_result_restricted

when: aem_service_restricted_mode

- name: "Wait for AEM startup. [{{ inventory_hostname }}]"
uri:
Expand All @@ -12,6 +28,6 @@
until: result.content.find("QUICKSTART_HOMEPAGE") != -1
retries: "{{ aem_service_timeout // 10 }}"
delay: 10
when: aem_service_start_result.changed
when: aem_service_start_result_escalated.changed or aem_service_start_result_restricted.changed
tags:
- skip_ansible_lint
31 changes: 29 additions & 2 deletions tasks/stop_aem.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
- name: Stop AEM.
- name: Stop AEM (escalated).
service:
name: "{{ aem_service_name }}"
state: stopped
register: aem_service_stop_result
register: aem_service_stop_result_escalated
when: not aem_service_restricted_mode

- name: Stop AEM (restricted).
block:
- name: Retrieve AEM status (restricted).
raw: "{{ _aem_service_status_command }}"
changed_when: false
failed_when: _aem_status_result.rc not in aem_service_status_valid_status_codes
register: _aem_status_result

- name: Stop AEM (restricted).
raw: "{{ _aem_service_stop_command }}"
when: _aem_status_result.rc == 0
register: aem_service_stop_result_restricted

when: aem_service_restricted_mode

- name: Wait for AEM shutdown.
wait_for:
port: "{{ aem_service_port }}"
state: stopped
delay: 0
sleep: 10
timeout: "{{ aem_service_timeout }}"
when: aem_service_stop_result_escalated.changed or aem_service_stop_result_restricted.changed
tags:
- skip_ansible_lint
5 changes: 5 additions & 0 deletions vars/service_mgr_default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_aem_service_start_command: "{{ aem_service_start_command | default('sudo -n /etc/init.d/'+aem_service_name+' start') }}"
_aem_service_stop_command: "{{ aem_service_stop_command | default('sudo -n /etc/init.d/'+aem_service_name+' stop') }}"
_aem_service_status_command: "{{ aem_service_status_command | default('sudo -n /etc/init.d/'+aem_service_name+' status') }}"
_aem_service_status_stopped_status_codes: "{{ aem_service_status_stopped_status_codes | default([4]) }}"
_aem_service_status_started_status_codes: "{{ aem_service_status_started_status_codes | default([0]) }}"
5 changes: 5 additions & 0 deletions vars/service_mgr_systemd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_aem_service_start_command: "{{ aem_service_start_command | default('sudo -n /bin/systemctl start '+aem_service_name ) }} && echo $?"
_aem_service_stop_command: "{{ aem_service_stop_command | default('sudo -n /bin/systemctl stop '+aem_service_name ) }} && echo $?"
_aem_service_status_command: "{{ aem_service_status_command | default('sudo -n /bin/systemctl is-active '+aem_service_name) }}"
_aem_service_status_stopped_status_codes: "{{ aem_service_status_stopped_status_codes | default([3]) }}"
_aem_service_status_started_status_codes: "{{ aem_service_status_started_status_codes | default([0]) }}"

0 comments on commit d6140be

Please sign in to comment.