mirror of
https://github.com/iiab/iiab.git
synced 2025-02-12 19:22:24 +00:00
kiwix rework and add iiab_installed
This commit is contained in:
parent
493d97ff7e
commit
68a62c32bb
3 changed files with 109 additions and 117 deletions
90
roles/kiwix/tasks/kiwix_enable.yml
Normal file
90
roles/kiwix/tasks/kiwix_enable.yml
Normal file
|
@ -0,0 +1,90 @@
|
|||
- name: Create softlink kiwix.conf from sites-enabled to sites-available - for Kiwix Proxy in Apache - is disabled by turning off service kiwix-serve (debuntu)
|
||||
file:
|
||||
src: /etc/apache2/sites-available/kiwix.conf
|
||||
path: /etc/apache2/sites-enabled/kiwix.conf
|
||||
state: link
|
||||
when: kiwix_enabled | bool and not nginx_enabled | bool
|
||||
|
||||
- name: Install nginx support
|
||||
template:
|
||||
backup: no
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ item.dest }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "{{ item.mode }}"
|
||||
with_items:
|
||||
- { src: 'kiwix-nginx.conf', dest: '/etc/nginx/conf.d/kiwix-nginx.conf', mode: '0644' }
|
||||
when: kiwix_enabled | bool and nginx_enabled | bool
|
||||
|
||||
- name: Remove symlink /etc/apache2/sites-enabled/kiwix.conf
|
||||
file:
|
||||
path: /etc/apache2/sites-enabled/kiwix.conf
|
||||
state: absent
|
||||
when: not kiwix_enabled | bool or nginx_enabled | bool
|
||||
|
||||
- name: Enable & Restart 'kiwix-serve' service
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
name: kiwix-serve
|
||||
enabled: yes
|
||||
state: restarted
|
||||
when: kiwix_enabled | bool
|
||||
|
||||
- name: Disable 'kiwix-serve' service
|
||||
systemd:
|
||||
name: kiwix-serve
|
||||
enabled: no
|
||||
state: stopped
|
||||
when: not kiwix_enabled
|
||||
# IN THEORY: 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.
|
||||
# @mgautierfr & others suggest kiwix-serve might be auto-restarted w/o cron in
|
||||
# future, whenever service fails, if this really catches all cases??
|
||||
# https://github.com/iiab/iiab/issues/484#issuecomment-342151726
|
||||
- name: Make a crontab entry to restart kiwix-serve at 4AM (debuntu)
|
||||
lineinfile:
|
||||
# mn hr dy mo day-of-week[Sunday=0] username command-to-be-executed
|
||||
line: "0 4 * * * root /bin/systemctl restart kiwix-serve.service"
|
||||
dest: /etc/crontab
|
||||
when: kiwix_enabled and is_debuntu
|
||||
|
||||
- name: Make a crontab entry to restart kiwix-serve at 4AM (redhat)
|
||||
# * * * * * user-name command to be executed
|
||||
lineinfile:
|
||||
# mn hr dy mo day-of-week[Sunday=0] username command-to-be-executed
|
||||
line: "0 4 * * * root /usr/bin/systemctl restart kiwix-serve.service"
|
||||
dest: /etc/crontab
|
||||
when: kiwix_enabled and is_redhat
|
||||
|
||||
- name: Restart Apache, so it picks up kiwix.conf
|
||||
service:
|
||||
name: "{{ apache_service }}"
|
||||
state: restarted
|
||||
|
||||
# 5. FINALIZE
|
||||
|
||||
- name: Add 'kiwix' variable values to {{ iiab_ini_file }}
|
||||
ini_file:
|
||||
path: "{{ iiab_ini_file }}"
|
||||
section: kiwix
|
||||
option: "{{ item.option }}"
|
||||
value: "{{ item.value }}"
|
||||
with_items:
|
||||
- option: name
|
||||
value: Kiwix
|
||||
- option: description
|
||||
value: '"Part of https://github.com/kiwix/kiwix-tools/ - kiwix-serve is the most used web server for ZIM files."'
|
||||
- option: kiwix_url
|
||||
value: "{{ kiwix_url }}"
|
||||
- option: kiwix_path
|
||||
value: "{{ kiwix_path }}"
|
||||
- option: kiwix_port
|
||||
value: "{{ kiwix_port }}"
|
||||
- option: iiab_zim_path
|
||||
value: "{{ iiab_zim_path }}"
|
||||
- option: kiwix_library_xml
|
||||
value: "{{ kiwix_library_xml }}"
|
||||
- option: kiwix_enabled
|
||||
value: "{{ kiwix_enabled }}"
|
|
@ -27,16 +27,6 @@
|
|||
force: no
|
||||
when: not kiwix_xml.stat.exists
|
||||
|
||||
- name: Check for /opt/iiab/kiwix/bin/kiwix-serve binary
|
||||
stat:
|
||||
path: "{{ kiwix_path }}/bin/kiwix-serve"
|
||||
register: kiwix_bin
|
||||
|
||||
- name: Set fact kiwix_force_install if kiwix-serve not found
|
||||
set_fact:
|
||||
kiwix_force_install: True
|
||||
when: not kiwix_bin.stat.exists
|
||||
|
||||
- name: Install {{ iiab_zim_path }}/content/test.zim if kiwix_force_install
|
||||
copy:
|
||||
src: test.zim
|
||||
|
@ -99,106 +89,7 @@
|
|||
- { src: 'iiab-make-kiwix-lib.py', dest: '/usr/bin/iiab-make-kiwix-lib.py', mode: '0755'}
|
||||
- { src: 'kiwix.conf.j2', dest: '/etc/{{ apache_config_dir }}/kiwix.conf', mode: '0644'}
|
||||
|
||||
- name: Create softlink kiwix.conf from sites-enabled to sites-available - for Kiwix Proxy in Apache - is disabled by turning off service kiwix-serve (debuntu)
|
||||
file:
|
||||
src: /etc/apache2/sites-available/kiwix.conf
|
||||
path: /etc/apache2/sites-enabled/kiwix.conf
|
||||
state: link
|
||||
when: kiwix_enabled | bool and not nginx_enabled | bool
|
||||
|
||||
- name: Install nginx support
|
||||
template:
|
||||
backup: no
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ item.dest }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "{{ item.mode }}"
|
||||
with_items:
|
||||
- { src: 'kiwix-nginx.conf', dest: '/etc/nginx/conf.d/kiwix-nginx.conf', mode: '0644' }
|
||||
when: kiwix_enabled | bool and nginx_enabled | bool
|
||||
|
||||
- name: Remove symlink /etc/apache2/sites-enabled/kiwix.conf
|
||||
file:
|
||||
path: /etc/apache2/sites-enabled/kiwix.conf
|
||||
state: absent
|
||||
when: not kiwix_enabled | bool or nginx_enabled | bool
|
||||
|
||||
- name: Enable & Restart 'kiwix-serve' service
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
name: kiwix-serve
|
||||
enabled: yes
|
||||
state: restarted
|
||||
when: kiwix_enabled | bool
|
||||
|
||||
- name: Disable 'kiwix-serve' service
|
||||
systemd:
|
||||
name: kiwix-serve
|
||||
enabled: no
|
||||
state: stopped
|
||||
when: not kiwix_enabled
|
||||
# IN THEORY: 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.
|
||||
# @mgautierfr & others suggest kiwix-serve might be auto-restarted w/o cron in
|
||||
# future, whenever service fails, if this really catches all cases??
|
||||
# https://github.com/iiab/iiab/issues/484#issuecomment-342151726
|
||||
- name: Make a crontab entry to restart kiwix-serve at 4AM (debuntu)
|
||||
lineinfile:
|
||||
# mn hr dy mo day-of-week[Sunday=0] username command-to-be-executed
|
||||
line: "0 4 * * * root /bin/systemctl restart kiwix-serve.service"
|
||||
dest: /etc/crontab
|
||||
when: kiwix_enabled and is_debuntu
|
||||
|
||||
- name: Make a crontab entry to restart kiwix-serve at 4AM (redhat)
|
||||
# * * * * * user-name command to be executed
|
||||
lineinfile:
|
||||
# mn hr dy mo day-of-week[Sunday=0] username command-to-be-executed
|
||||
line: "0 4 * * * root /usr/bin/systemctl restart kiwix-serve.service"
|
||||
dest: /etc/crontab
|
||||
when: kiwix_enabled and is_redhat
|
||||
|
||||
- name: Restart Apache, so it picks up kiwix.conf
|
||||
systemd:
|
||||
name: "{{ apache_service }}"
|
||||
state: restarted
|
||||
when: not nginx_enabled | bool
|
||||
|
||||
- name: Remove nginx support for kiwix
|
||||
file:
|
||||
path: /etc/nginx/conf.d/kiwix-nginx.conf
|
||||
state: absent
|
||||
when: not kiwix_enabled | bool
|
||||
|
||||
- name: Restart nginx, so it picks up kiwix-nginx.conf state
|
||||
systemd:
|
||||
name: nginx
|
||||
state: restarted
|
||||
when: nginx_enabled | bool
|
||||
|
||||
# 5. FINALIZE
|
||||
|
||||
- name: Add 'kiwix' variable values to {{ iiab_ini_file }}
|
||||
- name: Add 'kiwix_installed' variable values to {{ iiab_installed }}
|
||||
ini_file:
|
||||
path: "{{ iiab_ini_file }}"
|
||||
section: kiwix
|
||||
option: "{{ item.option }}"
|
||||
value: "{{ item.value }}"
|
||||
with_items:
|
||||
- option: name
|
||||
value: Kiwix
|
||||
- option: description
|
||||
value: '"Part of https://github.com/kiwix/kiwix-tools/ - kiwix-serve is the most used web server for ZIM files."'
|
||||
- option: kiwix_url
|
||||
value: "{{ kiwix_url }}"
|
||||
- option: kiwix_path
|
||||
value: "{{ kiwix_path }}"
|
||||
- option: kiwix_port
|
||||
value: "{{ kiwix_port }}"
|
||||
- option: iiab_zim_path
|
||||
value: "{{ iiab_zim_path }}"
|
||||
- option: kiwix_library_xml
|
||||
value: "{{ kiwix_library_xml }}"
|
||||
- option: kiwix_enabled
|
||||
value: "{{ kiwix_enabled }}"
|
||||
path: "{{ iiab_installed }}"
|
||||
value: kiwix_installed
|
||||
|
|
|
@ -28,18 +28,29 @@
|
|||
url: "{{ iiab_download_url }}/{{ kiwix_src_file }}"
|
||||
dest: "{{ downloads_dir }}/{{ kiwix_src_file }}"
|
||||
timeout: "{{ download_timeout }}"
|
||||
when: internet_available | bool
|
||||
when: internet_available | bool and kiwix_install | bool and not kiwix_installed is defined
|
||||
|
||||
- name: Check for /opt/iiab/downloads/{{ kiwix_src_file }}
|
||||
stat:
|
||||
path: "{{ downloads_dir }}/{{ kiwix_src_file }}"
|
||||
register: kiwix_src
|
||||
|
||||
- name: FAIL (force Ansible to exit) IF /opt/iiab/downloads/{{ kiwix_src_file }} doesn't exist
|
||||
fail:
|
||||
msg: "{ downloads_dir }}/{{ kiwix_src_file }} is REQUIRED in order to install Kiwix."
|
||||
when: not kiwix_src.stat.exists
|
||||
- name: Check for /opt/iiab/kiwix/bin/kiwix-serve binary
|
||||
stat:
|
||||
path: "{{ kiwix_path }}/bin/kiwix-serve"
|
||||
register: kiwix_bin
|
||||
|
||||
- name: Set fact kiwix_force_install if kiwix-serve not found
|
||||
set_fact:
|
||||
kiwix_force_install: True
|
||||
when: not kiwix_bin.stat.exists
|
||||
|
||||
- include_tasks: kiwix_install.yml
|
||||
when: kiwix_install | bool and (not kiwix_installed is defined or kiwix_force_install | bool)
|
||||
tags:
|
||||
- kiwix
|
||||
|
||||
- include_tasks: kiwix_enable.yml
|
||||
when: kiwix_install | bool or kiwix_installed is defined
|
||||
tags:
|
||||
- kiwix
|
||||
|
|
Loading…
Reference in a new issue