feat: enhance Nextcloud maintenance checks and add Collabora endpoint validations
This commit is contained in:
@@ -11,28 +11,86 @@
|
||||
vm_password: "{{ lookup('ansible.builtin.env', 'vm_pass') }}"
|
||||
vm_use_sudo: "{{ use_sudo | default(false) | bool }}"
|
||||
|
||||
nextcloud_container: "nextcloud"
|
||||
nextcloud_db_container: "nextcloud-db"
|
||||
redis_container: "redis"
|
||||
|
||||
nextcloud_local_status_url: "http://127.0.0.1:8080/status.php"
|
||||
|
||||
collabora_url: "https://collabora.martinfencl.eu/"
|
||||
collabora_discovery_url: >-
|
||||
https://collabora.martinfencl.eu/hosting/discovery
|
||||
|
||||
vm_commands:
|
||||
- >-
|
||||
docker exec -u www-data nextcloud
|
||||
php -f /var/www/html/cron.php
|
||||
- name: Run Nextcloud cron
|
||||
command: >-
|
||||
docker exec -u www-data
|
||||
{{ nextcloud_container }}
|
||||
php -f /var/www/html/cron.php
|
||||
|
||||
- >-
|
||||
docker exec -u www-data nextcloud
|
||||
php occ app:update --all
|
||||
- name: Update Nextcloud applications
|
||||
command: >-
|
||||
docker exec -u www-data
|
||||
{{ nextcloud_container }}
|
||||
php occ app:update --all
|
||||
|
||||
- >-
|
||||
docker exec -u www-data nextcloud
|
||||
php occ maintenance:repair --include-expensive
|
||||
- name: Run Nextcloud maintenance repair
|
||||
command: >-
|
||||
docker exec -u www-data
|
||||
{{ nextcloud_container }}
|
||||
php occ maintenance:repair --include-expensive
|
||||
|
||||
- >-
|
||||
docker exec -u www-data nextcloud
|
||||
php occ status
|
||||
- name: Read Nextcloud status
|
||||
command: >-
|
||||
docker exec -u www-data
|
||||
{{ nextcloud_container }}
|
||||
php occ status
|
||||
|
||||
- >-
|
||||
set -o pipefail;
|
||||
timeout 180s
|
||||
bash -x /data/compose/nextcloud/stack-health.sh
|
||||
</dev/null
|
||||
- name: Check required containers
|
||||
command: >-
|
||||
set -o pipefail;
|
||||
for container in
|
||||
{{ nextcloud_container | quote }}
|
||||
{{ nextcloud_db_container | quote }}
|
||||
{{ redis_container | quote }};
|
||||
do
|
||||
docker ps
|
||||
--filter "name=^/${container}$"
|
||||
--filter "status=running"
|
||||
--format '{% raw %}{{.Names}}{% endraw %}'
|
||||
| grep -qx "${container}"
|
||||
|| {
|
||||
echo "Container ${container} is not running" >&2;
|
||||
exit 1;
|
||||
};
|
||||
done
|
||||
|
||||
- name: Check MariaDB readiness
|
||||
command: >-
|
||||
docker exec
|
||||
{{ nextcloud_db_container }}
|
||||
sh -c
|
||||
'mariadb-admin ping -h 127.0.0.1 --silent 2>/dev/null
|
||||
|| mysqladmin ping -h 127.0.0.1 --silent 2>/dev/null'
|
||||
|
||||
- name: Check Redis readiness
|
||||
command: >-
|
||||
set -o pipefail;
|
||||
docker exec
|
||||
{{ redis_container }}
|
||||
redis-cli -h 127.0.0.1 ping
|
||||
| grep -qx PONG
|
||||
|
||||
- name: Check Nextcloud local status endpoint
|
||||
command: >-
|
||||
set -o pipefail;
|
||||
curl
|
||||
--fail
|
||||
--silent
|
||||
--show-error
|
||||
--max-time 15
|
||||
{{ nextcloud_local_status_url | quote }}
|
||||
| grep -q '"installed":true'
|
||||
|
||||
pre_tasks:
|
||||
- name: Validate VM connection variables
|
||||
@@ -56,7 +114,7 @@
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Run Nextcloud commands on VM
|
||||
- name: Run Nextcloud checks on VM
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- sshpass
|
||||
@@ -67,6 +125,8 @@
|
||||
- -o
|
||||
- UserKnownHostsFile=/dev/null
|
||||
- -o
|
||||
- LogLevel=ERROR
|
||||
- -o
|
||||
- ConnectTimeout=15
|
||||
- -o
|
||||
- ServerAliveInterval=10
|
||||
@@ -75,26 +135,27 @@
|
||||
- "{{ vm_user }}@{{ vm_ip }}"
|
||||
- >-
|
||||
{{
|
||||
('sudo -n bash -lc ' ~ (item | quote))
|
||||
('sudo -n bash -lc ' ~ (item.command | quote))
|
||||
if vm_use_sudo
|
||||
else
|
||||
('bash -lc ' ~ (item | quote))
|
||||
('bash -lc ' ~ (item.command | quote))
|
||||
}}
|
||||
environment:
|
||||
SSHPASS: "{{ vm_password }}"
|
||||
loop: "{{ vm_commands }}"
|
||||
loop_control:
|
||||
label: "{{ item }}"
|
||||
label: "{{ item.name }}"
|
||||
register: vm_cmds
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
no_log: true
|
||||
|
||||
- name: Show outputs for each command
|
||||
- name: Show outputs for each VM command
|
||||
ansible.builtin.debug:
|
||||
msg: |
|
||||
CMD: {{ item.item }}
|
||||
RC: {{ item.rc }}
|
||||
CHECK: {{ item.item.name }}
|
||||
CMD: {{ item.item.command }}
|
||||
RC: {{ item.rc }}
|
||||
|
||||
STDOUT:
|
||||
{{ item.stdout | default('') | trim }}
|
||||
@@ -103,14 +164,15 @@
|
||||
{{ item.stderr | default('') | trim }}
|
||||
loop: "{{ vm_cmds.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item }}"
|
||||
label: "{{ item.item.name }}"
|
||||
|
||||
- name: Fail play if any command failed
|
||||
- name: Fail if any Nextcloud VM command failed
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- item.rc == 0
|
||||
fail_msg: |
|
||||
Command failed on VM: {{ item.item }}
|
||||
Nextcloud check failed: {{ item.item.name }}
|
||||
Command: {{ item.item.command }}
|
||||
RC: {{ item.rc }}
|
||||
|
||||
STDERR:
|
||||
@@ -118,4 +180,51 @@
|
||||
quiet: true
|
||||
loop: "{{ vm_cmds.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item }}"
|
||||
label: "{{ item.item.name }}"
|
||||
|
||||
- name: Check external Collabora root endpoint
|
||||
ansible.builtin.uri:
|
||||
url: "{{ collabora_url }}"
|
||||
method: GET
|
||||
return_content: true
|
||||
validate_certs: true
|
||||
status_code: 200
|
||||
timeout: 20
|
||||
register: collabora_root
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
changed_when: false
|
||||
failed_when: >-
|
||||
collabora_root.status | default(0) != 200
|
||||
or
|
||||
'OK' not in (collabora_root.content | default(''))
|
||||
|
||||
- name: Check external Collabora discovery endpoint
|
||||
ansible.builtin.uri:
|
||||
url: "{{ collabora_discovery_url }}"
|
||||
method: GET
|
||||
return_content: true
|
||||
validate_certs: true
|
||||
status_code: 200
|
||||
timeout: 20
|
||||
register: collabora_discovery
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
changed_when: false
|
||||
failed_when: >-
|
||||
collabora_discovery.status | default(0) != 200
|
||||
or
|
||||
'<wopi-discovery' not in
|
||||
(collabora_discovery.content | default(''))
|
||||
|
||||
- name: Show final health summary
|
||||
ansible.builtin.debug:
|
||||
msg: |
|
||||
Nextcloud VM checks: OK
|
||||
Nextcloud containers: OK
|
||||
MariaDB: OK
|
||||
Redis: OK
|
||||
Nextcloud local HTTP: OK
|
||||
Collabora root endpoint: OK
|
||||
Collabora discovery endpoint: OK
|
||||
run_once: true
|
||||
Reference in New Issue
Block a user