From e501fe119196c488c40a2aaa51b14e5c28fee253 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 9 Nov 2020 06:20:57 -0500 Subject: [PATCH] Fix counting of /library/zims/content/*.zim + in-line clarifs --- roles/kiwix/tasks/enable-or-disable.yml | 9 ++--- roles/kiwix/tasks/install.yml | 33 ++++++++++--------- .../{library.xml => library.xml.deprecated} | 0 3 files changed, 22 insertions(+), 20 deletions(-) rename roles/kiwix/templates/{library.xml => library.xml.deprecated} (100%) diff --git a/roles/kiwix/tasks/enable-or-disable.yml b/roles/kiwix/tasks/enable-or-disable.yml index 04ea1d5df..0ca34930c 100644 --- a/roles/kiwix/tasks/enable-or-disable.yml +++ b/roles/kiwix/tasks/enable-or-disable.yml @@ -4,18 +4,19 @@ enabled: no state: stopped -- name: Update {{ kiwix_library_xml }} +- name: Run /usr/bin/iiab-make-kiwix-lib to update {{ kiwix_library_xml }} # /library/zims/library.xml command: /usr/bin/iiab-make-kiwix-lib when: kiwix_enabled -# the above starts the service +# The above stops then starts kiwix-serve.service -- name: Enable & Ensure 'kiwix-serve' systemd service is started +- name: Enable & Ensure 'kiwix-serve.service' is running systemd: name: kiwix-serve enabled: yes - state: started + state: started # Not needed...but can't hurt when: kiwix_enabled + # TO DO: BOTH CRON ENTRIES BELOW *SHOULD* BE DELETED "when: not kiwix_enabled" # In the past kiwix-serve did not stay running, so we'd been doing this hourly. diff --git a/roles/kiwix/tasks/install.yml b/roles/kiwix/tasks/install.yml index 4ade28e37..011c356f9 100644 --- a/roles/kiwix/tasks/install.yml +++ b/roles/kiwix/tasks/install.yml @@ -30,41 +30,41 @@ kiwix_src_file: "{{ kiwix_src_dir }}.tar.gz" -# 1. PUT IN PLACE: ESSENTIAL DIRS, library.xml, test.zim +# 1. PUT IN PLACE: /opt/iiab/downloads/kiwix-tools_linux-*.tar.gz, essential dirs, and test.zim if nec (library.xml is created later, by enable-or-disable.xml) - name: Download {{ iiab_download_url }}/{{ kiwix_src_file }} to /opt/iiab/downloads get_url: url: "{{ iiab_download_url }}/{{ kiwix_src_file }}" # http://download.iiab.io/packages - dest: "{{ downloads_dir }}/{{ kiwix_src_file }}" + dest: "{{ downloads_dir }}/{{ kiwix_src_file }}" # /opt/iiab/downloads timeout: "{{ download_timeout }}" when: internet_available -- name: Create dir {{ iiab_zim_path }} and subdirs {content, index} for Kiwix ZIM files +- name: "Create dirs, including parent dirs: {{ kiwix_path }}/bin (executables), {{ iiab_zim_path }}/content (ZIM files), {{ iiab_zim_path }}/index (legacy indexes)" file: path: "{{ item }}" state: directory with_items: - - "{{ kiwix_path }}/bin" # /opt/iiab/kiwix - - "{{ iiab_zim_path }}" # /library/zims - - "{{ iiab_zim_path }}/content" + - "{{ kiwix_path }}/bin" # /opt/iiab/kiwix + - "{{ iiab_zim_path }}/content" # /library/zims - "{{ iiab_zim_path }}/index" -- name: Check for {{ iiab_zim_path }}/content/*.zim - stat: - path: "{{ iiab_zim_path }}/content/*.zim" +- name: Count *.zim files in {{ iiab_zim_path }}/content + find: + paths: "{{ iiab_zim_path }}/content" + patterns: '*.zim' register: kiwix_zims -- name: Install {{ iiab_zim_path }}/content/test.zim +- name: If there were none, install {{ iiab_zim_path }}/content/test.zim copy: src: test.zim dest: "{{ iiab_zim_path }}/content/test.zim" - force: no - when: not kiwix_zims.stat.exists + #force: no + when: kiwix_zims.matched == 0 # 2. INSTALL KIWIX-TOOLS EXECUTABLES -- name: Unarchive {{ kiwix_src_file }} to /tmp # e.g. kiwix-tools_linux-armhf-0.6.1-1.tar.gz +- name: Unarchive {{ kiwix_src_file }} to /tmp # e.g. kiwix-tools_linux-armhf-3.1.2-3.tar.gz unarchive: src: "{{ downloads_dir }}/{{ kiwix_src_file }}" dest: /tmp @@ -100,14 +100,14 @@ - { src: 'iiab-make-kiwix-lib', dest: '/usr/bin/iiab-make-kiwix-lib', mode: '0755' } - { src: 'iiab-make-kiwix-lib3.py', dest: '/usr/bin/iiab-make-kiwix-lib.py', mode: '0755' } -- name: Reload systemd for new kiwix-serve.service file +- name: daemon_reload, so systemd (re)reads kiwix-serve.service systemd: daemon_reload: yes -- name: "Install from template: Apache's kiwix.conf" +- name: "Install from template: /etc/{{ apache_conf_dir }}/kiwix.conf" template: src: kiwix.conf.j2 - dest: "/etc/{{ apache_conf_dir }}/kiwix.conf" + dest: "/etc/{{ apache_conf_dir }}/kiwix.conf" # apache2/sites-available #mode: '0644' when: apache_installed is defined @@ -116,6 +116,7 @@ include_tasks: kiwix-apk.yml when: kiwix_incl_apk + # 5. RECORD Kiwix AS INSTALLED - name: "Set 'kiwix_installed: True'" diff --git a/roles/kiwix/templates/library.xml b/roles/kiwix/templates/library.xml.deprecated similarity index 100% rename from roles/kiwix/templates/library.xml rename to roles/kiwix/templates/library.xml.deprecated