-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
squid: Handle the start of the service gracefully (#1526)
Signed-off-by: Gondermann <[email protected]>
- Loading branch information
Showing
5 changed files
with
104 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,44 @@ | ||
--- | ||
# handlers file for squid | ||
- name: Restart squid service | ||
become: true | ||
ansible.builtin.service: | ||
name: "{{ squid_service_name }}" | ||
state: restarted | ||
register: result | ||
until: result.status.ActiveState == "active" | ||
retries: 10 | ||
delay: 20 | ||
when: squid_service_restart|bool | ||
notify: | ||
- Wait for squid service to start | ||
- Register that squid service was restarted | ||
|
||
- name: Wait for squid service to start | ||
ansible.builtin.pause: | ||
minutes: 1 | ||
changed_when: true | ||
notify: | ||
- Wait for an healthy squid service | ||
|
||
# NOTE: This handler prevents a squid restart when the service | ||
# was already started via ansible.builtin.service. | ||
- name: Register that squid service was restarted | ||
ansible.builtin.set_fact: | ||
squid_service_restart: false | ||
|
||
# NOTE: The command returns a list of IDs of containers from the service | ||
# that are currently starting or unhealthy. As long as the list is not empty | ||
# the service is not in a good state. | ||
- name: Wait for an healthy squid service | ||
ansible.builtin.shell: | | ||
set -o pipefail | ||
docker compose --project-directory /opt/squid \ | ||
ps --all --format json | \ | ||
jq '. | select(.State=="created" or .State=="exited" or .Health=="starting" or .Health=="unhealthy") | .Name' | ||
args: | ||
executable: /bin/bash | ||
register: result | ||
until: "result.stdout | length == 0" | ||
retries: 60 | ||
delay: 10 | ||
changed_when: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
- name: Install required packages | ||
become: true | ||
ansible.builtin.apt: | ||
name: "{{ squid_required_packages }}" | ||
state: present | ||
lock_timeout: "{{ apt_lock_timeout | default(300) }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
- name: Install required packages | ||
become: true | ||
ansible.builtin.dnf: | ||
name: "{{ squid_required_packages }}" | ||
state: present | ||
lock_timeout: "{{ dnf_lock_timeout | default(300) }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters