From 7132acbd3b82fd22f3ff88f313b12f1e77a76c24 Mon Sep 17 00:00:00 2001 From: Georgina Date: Wed, 22 May 2019 17:05:01 +0000 Subject: [PATCH] Allow remote detection of repo sync status If a repo container and its data are deleted and recreated then it is not currently possible for a loadbalancer healthcheck to differentiate between an empty repo server and a correctly synchronised one. This patch creates a file 'repo-sync-complete' as part of the process of synchronising repo contents from master repo servers to slaves. The presence of this file on the slave can then be used as the loadbalancer healthcheck to ensure that repo contents are only served once sync has completed. In addition, this patch ensures that synchronisation occurs from the master to a reprovisioned slave by triggering a master repo server lsyncd restart handler during the initial setup of the slave repo server. Currently, a freshly provisioned repo server will remain empty for an indeterminate amount of time, this patch forces a complete re-sync to occur. Change-Id: I6913341674dbde5524c2270e824bda4544211eca --- handlers/main.yml | 2 ++ tasks/repo_post_install.yml | 1 + tasks/repo_pre_install.yml | 9 +++++++++ templates/lsyncd.lua.j2 | 2 +- templates/repo_prepost_cmd.sh.j2 | 2 ++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/handlers/main.yml b/handlers/main.yml index 381a97f..ebfe7a6 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -45,3 +45,5 @@ until: _restart is success retries: 5 delay: 2 + delegate_to: "{{ groups['repo_all'][0] }}" + run_once: true diff --git a/tasks/repo_post_install.yml b/tasks/repo_post_install.yml index 7022468..cd0b191 100644 --- a/tasks/repo_post_install.yml +++ b/tasks/repo_post_install.yml @@ -53,6 +53,7 @@ dest: "/etc/nginx/sites-available/openstack-slushee.vhost" notify: - reload nginx + - reload lsyncd - name: Drop rsyncd configuration file template: diff --git a/tasks/repo_pre_install.yml b/tasks/repo_pre_install.yml index c1222a6..15fdefa 100644 --- a/tasks/repo_pre_install.yml +++ b/tasks/repo_pre_install.yml @@ -50,6 +50,15 @@ - path: "/var/log/nginx" mode: "0775" +- name: Sync file for master repo node + file: + path: "{{ repo_service_home_folder }}/repo/repo_sync_complete" + state: "touch" + owner: "{{ repo_service_user_name }}" + group: "{{ repo_service_group_name }}" + when: inventory_hostname == groups['repo_all'][0] + changed_when: False + - name: Drop repo pre/post command script template: src: repo_prepost_cmd.sh.j2 diff --git a/templates/lsyncd.lua.j2 b/templates/lsyncd.lua.j2 index 5e580b4..032c1d6 100644 --- a/templates/lsyncd.lua.j2 +++ b/templates/lsyncd.lua.j2 @@ -618,7 +618,7 @@ sync { rsync, source = "{{ repo_service_home_folder }}/repo", target = "{{ hostvars[node]['ansible_host'] }}:{{ repo_service_home_folder }}/repo", - exclude = "{{ repo_build_global_links_dirname }}", + exclude = {"{{ repo_build_global_links_dirname }}","/repo_sync_complete"}, rsync = { compress = true, acls = true, diff --git a/templates/repo_prepost_cmd.sh.j2 b/templates/repo_prepost_cmd.sh.j2 index 2b49ce7..9a1a69f 100644 --- a/templates/repo_prepost_cmd.sh.j2 +++ b/templates/repo_prepost_cmd.sh.j2 @@ -6,10 +6,12 @@ case $CMD in pre-www) rm /etc/nginx/sites-enabled/openstack-slushee.vhost systemctl reload nginx + rm -f {{ repo_service_home_folder }}/repo/repo_sync_complete ;; post-www) ln -s /etc/nginx/sites-available/openstack-slushee.vhost /etc/nginx/sites-enabled/openstack-slushee.vhost systemctl reload nginx + touch {{ repo_service_home_folder }}/repo/repo_sync_complete ;; *) echo "Unknown command."