1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-12 19:22:24 +00:00

MongoDB / Sugarizer cleanup for Debian 11 etc

This commit is contained in:
root 2020-10-29 21:40:36 -04:00
parent 8d2baf0bfe
commit cb1a57bdab
11 changed files with 76 additions and 88 deletions

View file

@ -35,9 +35,10 @@
path: /etc/iiab/diag
mode: '0777'
- name: Re-read local_facts.facts from /etc/ansible/facts.d
setup:
filter: ansible_local
# 2020-10-29: Appears no longer nec (see 3 above ansible_local.local_facts.*)
#- name: Re-read local_facts.facts from /etc/ansible/facts.d
# setup:
# filter: ansible_local
- name: Pre-check that IIAB's "XYZ_install" + "XYZ_enabled" vars (1) are defined, (2) are boolean-not-string variables, and (3) contain plausible values. Also checks that "XYZ_install" is True when "XYZ_installed" is defined.
include_tasks: validate_vars.yml
@ -167,4 +168,4 @@
when: is_VM is defined
- name: STAGE 0 HAS COMPLETED ======================================
meta: noop
command: echo # "name: XYZ" fails to appear with "meta: noop"

View file

@ -0,0 +1,13 @@
- name: Enable & (Re)Start 'mongodb.service' if mongodb_enabled
systemd:
name: mongodb
enabled: yes
state: restarted
when: mongodb_enabled
- name: Disable & Stop 'mongodb.service' if not mongodb_enabled
systemd:
name: mongodb
enabled: no
state: stopped
when: not mongodb_enabled

View file

@ -114,7 +114,7 @@
- mongodb-org-server
state: present
- name: Change {{ mongodb_conf }} port to {{ mongodb_port }}
- name: Change {{ mongodb_conf }} port to {{ mongodb_port }} -- takes effect on next (re)start of the service -- via enable-or-disable.yml or via Sugarizer starting MongoDB on demand
lineinfile:
path: "{{ mongodb_conf }}"
regexp: "port: 27017"
@ -137,7 +137,7 @@
#- { path: '/var/run/mongodb' }
- /var/lib/mongodb
- /var/log/mongodb
- "{{ mongodb_db_path }}" # i.e. /library/dbdata/mongodb/
- "{{ mongodb_db_path }}" # /library/dbdata/mongodb
- name: Install mongodb.service, /usr/bin/iiab-mongodb-repair-if-no-lock from templates
template:
@ -150,14 +150,9 @@
- { src: 'mongodb.service.j2', dest: '/etc/systemd/system/mongodb.service', mode: '0644' }
- { src: 'iiab-mongodb-repair-if-no-lock.j2', dest: '/usr/bin/iiab-mongodb-repair-if-no-lock', mode: '0755' }
# daemon_reload is used to force systemd to recognize a newly installed .service file
# restarted here to ensure the port has been changed
- name: Disable 'mongodb' systemd service - started on demand by Sugarizer
- name: systemctl daemon_reload, so systemd (re)reads mongodb.service
systemd:
name: mongodb
daemon_reload: yes
enabled: no
state: restarted
# 3. RECORD MongoDB AS INSTALLED

View file

@ -26,6 +26,10 @@
var: mongodb_installed
- debug:
var: rpi_model # 0-init sets it from ansible_local.local_facts.rpi_model
- debug:
var: ansible_local.local_facts.os_ver # Like OS_VER in /etc/iiab/iiab.env
- debug:
var: is_debian
- debug:
@ -39,19 +43,16 @@
ignore_errors: yes
# ELSE...
- name: Install MongoDB if 'mongodb_installed' not defined, e.g. in {{ iiab_state_file }} # /etc/iiab/iiab_state.yml
include_tasks: install.yml
when: mongodb_installed is undefined and not (ansible_architecture == "aarch64" and is_debian_10 and not is_raspbian)
- name: Disable & Stop 'mongodb' service, if not mongodb_enabled
systemd:
name: mongodb
enabled: no
state: stopped
when: not mongodb_enabled and mongodb_installed is defined
#'mongodb' systemd service - started on demand by sugarizer
# Just recording that mongodb should be running
- name: Enable or Disable MongoDB, if mongodb_installed is defined (Sugarizer starts MongoDB on demand, so doesn't need this or care what happens here!)
include_tasks: enable-or-disable.yml
when: mongodb_installed is defined
- name: Add 'mongodb' variable values to {{ iiab_ini_file }}
ini_file:

View file

@ -1,12 +0,0 @@
- name: Enable http://box/sugarizer & http://box/sugar via Apache
command: a2ensite sugarizer.conf
when: sugarizer_enabled
- name: Disable http://box/sugarizer & http://box/sugar via Apache
command: a2dissite sugarizer.conf
when: not sugarizer_enabled
- name: (Re)Start '{{ apache_service }}' systemd service
systemd:
name: "{{ apache_service }}" # apache2 or httpd, as set in /opt/iiab/iiab/vars/<OS>.yml
state: restarted

View file

@ -0,0 +1,32 @@
- name: Enable & (Re)Start 'sugarizer.service' (WHICH AUTO-STARTS BUT DOES NOT ENABLE OR DISABLE 'mongodb.service', LIKEWISE WE DON'T TOUCH ANSIBLE VAR mongodb_enabled) if sugarizer_enabled
systemd:
name: sugarizer
enabled: yes
state: restarted
when: sugarizer_enabled
- name: Disable & Stop 'sugarizer.service' (BUT LEAVE 'mongodb.service' COMPLETETY UNCHANGED, LIKEWISE WE DON'T TOUCH ANSIBLE VAR mongodb_enabled) if not sugarizer_enabled
systemd:
name: sugarizer
enabled: no
state: stopped
when: not sugarizer_enabled
- name: Enable http://box/sugarizer if sugarizer_enabled, by installing {{ nginx_conf_dir }}/sugarizer-nginx.conf from template
template:
src: sugarizer-nginx.conf
dest: "{{ nginx_conf_dir }}/sugarizer-nginx.conf" # /etc/nginx/conf.d
when: sugarizer_enabled
- name: Disable http://box/sugarizer if not sugarizer_enabled, by removing {{ nginx_conf_dir }}/sugarizer-nginx.conf
file:
path: "{{ nginx_conf_dir }}/sugarizer-nginx.conf"
state: absent
when: not sugarizer_enabled
- name: Restart 'nginx' systemd service
systemd:
name: nginx
state: restarted

View file

@ -153,6 +153,10 @@
src: sugarizer.service
dest: /etc/systemd/system
- name: systemctl daemon_reload, so systemd (re)reads sugarizer.service
systemd:
daemon_reload: yes
- name: "Install from template: /etc/{{ apache_conf_dir }}/sugarizer.conf"
template:
src: sugarizer.conf.j2

View file

@ -19,25 +19,22 @@
quiet: yes
# 3 stanzas moved up from install.yml, so Debian finishes "BIG" IIAB install:
# (WITH LOUD RED WARNINGS!)
# 3 stanzas moved up from install.yml, so Debian-or-any-OS-where-MongoDB-fails
# still finish their "BIG-sized" IIAB install: (WITH LOUD RED WARNINGS!)
# If we got here sugarizer_install is True
- name: "Set 'mongodb_install: True'"
set_fact:
mongodb_install: True
# MongoDB auto-started by sugarizer.service - let's set 'mongodb_enabled: True'
# regardless - anticipating that MongoDB (should!) run on demand:
- name: "Set 'mongodb_enabled: True' when sugarizer_enabled"
set_fact:
mongodb_enabled: True
when: sugarizer_enabled
- name: 'CAUTION: IF ''mongodb.service'' IS STOPPED FOR ANY REASON, IT WILL IMMEDIATELY CAUSE SUGARIZER TO FAIL ("502 Bad Gateway") !'
debug:
msg: "/etc/systemd/system/sugarizer.service Line 4 'Requires=mongodb.service' tries to auto-start MongoDB every time Sugarizer starts. IIAB (roles/mongodb/tasks/enable-or-disable.yml) tries its best to keep Ansible var 'mongodb_enabled' in sync with its systemd equivalent, i.e. the output of 'systemctl is-enabled mongodb' (as of 2020-10-29 both are typically disabled, unless other apps/services/operators choose to use MongoDB)."
- name: MONGODB - run 'mongodb' role (attempt to install MongoDB)
include_role:
name: mongodb
- name: EXIT 'sugarizer' ROLE & CONTINUE, IF 'mongodb_installed is undefined'
fail: # FORCE IT RED THIS ONCE!
msg: MongoDB INSTALLATION FAILED, perhaps because your OS is Debian 10 on aarch64? Nevertheless IIAB will continue (consider this a warning!)

View file

@ -2,38 +2,8 @@
include_tasks: install.yml
when: sugarizer_installed is undefined
- block: # 2 STANZAS BELOW, CONDITIONED ON 'when: sugarizer_enabled'
# LIKELY UNNEC: THIS SAME CODE IS IN main.yml (LINES 32-35, ALREADY RUN)
# sugarizer.service line 'Requires=mongodb.service' auto-starts MongoDB (but record that in var too)
- name: "Set 'mongodb_enabled: True' if sugarizer_enabled"
set_fact:
mongodb_enabled: True
- name: Enable & Restart 'sugarizer' systemd service, if sugarizer_enabled
systemd:
name: sugarizer
daemon_reload: yes # In case mongodb.service changed, etc
enabled: yes
state: restarted
when: sugarizer_enabled # CONDITION FOR 2-STANZA block: ABOVE
# Stops 'sugarizer' but not 'mongodb'
- name: Disable & Stop 'sugarizer' systemd service, if not sugarizer_enabled
systemd:
name: sugarizer
enabled: no
state: stopped
when: not sugarizer_enabled
- name: Enable/Disable/Restart Apache if primary
include_tasks: apache.yml
when: not nginx_enabled
- name: Enable/Disable/Restart NGINX if primary
include_tasks: nginx.yml
when: nginx_enabled
- include_tasks: enable-or-disable.yml
- name: Add 'sugarizer' variable values to {{ iiab_ini_file }}

View file

@ -1,16 +0,0 @@
- name: Enable http://box/sugarizer via NGINX, by installing {{ nginx_conf_dir }}/sugarizer-nginx.conf from template
template:
src: sugarizer-nginx.conf
dest: "{{ nginx_conf_dir }}/sugarizer-nginx.conf" # /etc/nginx/conf.d
when: sugarizer_enabled
- name: Disable http://box/sugarizer via NGINX, by removing {{ nginx_conf_dir }}/sugarizer-nginx.conf
file:
path: "{{ nginx_conf_dir }}/sugarizer-nginx.conf" # /etc/nginx/conf.d
state: absent
when: not sugarizer_enabled
- name: Restart 'nginx' systemd service
systemd:
name: nginx
state: restarted

View file

@ -728,6 +728,9 @@ is_fedora_18: False
# 4. Likewise behind the scenes:
# ./iiab-configure (uses iiab-from-cmdline.yml)
# Admin Console (uses iiab-from-console.yml)
# 5. roles/0-init/tasks/main.yml reads from /etc/ansible/facts.d file(s)
# local_facts.facts (but not admin_facts.fact ?)
# 6. /etc/iiab/iiab.env is created by roles/1-prep/templates/iiab.env.j2
#
# More details, including Order of Execution and Precedence:
# https://github.com/iiab/iiab/wiki/IIAB-Variables