2019-09-05 05:02:18 +00:00
- 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
2020-01-04 01:47:25 +00:00
when : kiwix_enabled and not nginx_enabled
2019-09-05 05:02:18 +00:00
- name : Install nginx support
template :
backup : no
src : "{{ item.src }}"
dest : "{{ item.dest }}"
owner : root
group : root
mode : "{{ item.mode }}"
with_items :
2020-01-04 01:47:25 +00:00
- { src: 'kiwix-nginx.conf', dest : '{{ nginx_config_dir }}/kiwix-nginx.conf' , mode : '0644' }
when : kiwix_enabled and nginx_enabled
2019-09-05 05:02:18 +00:00
- name : Remove symlink /etc/apache2/sites-enabled/kiwix.conf
file :
path : /etc/apache2/sites-enabled/kiwix.conf
state : absent
2020-01-04 01:47:25 +00:00
when : not kiwix_enabled or nginx_enabled
- name : Remove {{ nginx_config_dir }}/kiwix-nginx.conf
file :
path : "{{ nginx_config_dir }}/kiwix-nginx.conf"
state : absent
when : not kiwix_enabled and nginx_enabled
2019-09-05 05:02:18 +00:00
- name : Enable & Restart 'kiwix-serve' service
systemd :
daemon_reload : yes
name : kiwix-serve
enabled : yes
state : restarted
2020-01-04 01:47:25 +00:00
when : kiwix_enabled
2019-09-05 05:02:18 +00:00
- 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
2020-01-04 01:47:25 +00:00
systemd :
2019-09-05 05:02:18 +00:00
name : "{{ apache_service }}"
state : restarted
2020-01-04 01:47:25 +00:00
daemon-reload : yes
when : not nginx_enabled
- name : Restart nginx service
systemd :
name : nginx
state : restarted
daemon-reload : yes
when : nginx_enabled
2019-09-05 05:02:18 +00:00
# 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 }}"