diff --git a/roles/deploy_code/defaults/main.yml b/roles/deploy_code/defaults/main.yml index f1f7cdb4..f9b84739 100644 --- a/roles/deploy_code/defaults/main.yml +++ b/roles/deploy_code/defaults/main.yml @@ -25,11 +25,14 @@ deploy_code: # Path that you want to make sure has 755 permissions. Make sure to include the webroot WITHOUT the slash. perms_fix_path: "" # perms_fix_path: "www/sites/default" - # List of services to reload to free the loop device for 'squashfs' builds, post lazy umount. + # List of services to manipulate to free the loop device for 'squashfs' builds, post lazy umount. # @see the squashfs role in ce-provision where special permissions for deploy user to manipulate services get granted. services: [] # services: # - php8.0-fpm + # What action to take against the services, 'reload' or 'stop'. + # Busy websites will require a hard stop of services to achieve the umount command. + service_action: reload # Trigger an API call to rebuild infra after a deploy, e.g. if you need to repack an AMI. rebuild_infra: false # Details of API call to trigger. See api_call role. diff --git a/roles/deploy_code/tasks/cleanup.yml b/roles/deploy_code/tasks/cleanup.yml index 353854b3..a5da0d87 100644 --- a/roles/deploy_code/tasks/cleanup.yml +++ b/roles/deploy_code/tasks/cleanup.yml @@ -144,6 +144,23 @@ loop_var: www_service become: true when: + - deploy_code.service_action == "reload" + - deploy_code.mount_sync is defined + - deploy_code.mount_sync | length > 1 + - deploy_code.mount_type == "squashfs" + - _deploy_code_mount_check is succeeded + - deploy_code.services | length > 0 + +- name: Stop any services that might be keeping the loop device busy. + ansible.builtin.service: + name: "{{ www_service }}" + state: stopped + with_items: "{{ deploy_code.services }}" + loop_control: + loop_var: www_service + become: true + when: + - deploy_code.service_action == "stop" - deploy_code.mount_sync is defined - deploy_code.mount_sync | length > 1 - deploy_code.mount_type == "squashfs" @@ -169,6 +186,22 @@ - deploy_code.mount_sync | length > 1 - deploy_code.mount_type == "squashfs" +- name: Start any services we stopped. + ansible.builtin.service: + name: "{{ www_service }}" + state: started + with_items: "{{ deploy_code.services }}" + loop_control: + loop_var: www_service + become: true + when: + - deploy_code.service_action == "stop" + - deploy_code.mount_sync is defined + - deploy_code.mount_sync | length > 1 + - deploy_code.mount_type == "squashfs" + - _deploy_code_mount_check is succeeded + - deploy_code.services | length > 0 + - name: Trigger an infrastructure rebuild. ansible.builtin.include_role: name: api_call