Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce backup handler for upgrade #1125

Merged
merged 21 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[defaults]
inventory = inventory
#timeout = 60
force_handlers = True

[ssh_connection]
pipelining = True
25 changes: 25 additions & 0 deletions roles/api/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: recover backup
synchronize:
src: "{{ fworch_home }}/backup_api/api"
dest: "{{ fworch_home }}"
delegate_to: "{{ inventory_hostname }}"
listen: "api handler"
when: api_handler_guard == "start"
become: yes

- name: delete backup
file:
state: absent
path: "{{ fworch_home }}/backup_api"
listen: "api handler"
become: yes

- name: fail message
debug:
msg:
- "An error occured during the upgrade of role {{ role_name }}"
- "Please restart the server {{ inventory_hostname }}"
- "Try to upgrade {{ product_name }} later or contact the support [email protected]"
listen: "api handler"
when: api_handler_guard == "start"
23 changes: 23 additions & 0 deletions roles/api/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
# this playbook sets up the api
- name: initialize handler for datarecovery
set_fact:
api_handler_guard: start
changed_when: true
notify:
- api handler
when: installation_mode == "upgrade"

- name: backup api dir
synchronize:
src: "{{ fworch_home }}/api"
dest: "{{ fworch_home }}/backup_api"
delegate_to: "{{ inventory_hostname }}"
when: installation_mode == "upgrade"
become: yes

- name: remove api home
file:
Expand Down Expand Up @@ -27,3 +42,11 @@
- name: api create documentation
import_tasks: api-create-docu.yml
when: api_docu | bool

- name: finalize handler for datarecovery
set_fact:
api_handler_guard: stop
changed_when: true
notify: "api handler"
when: installation_mode == "upgrade"

22 changes: 16 additions & 6 deletions roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,28 @@
# meta: end_play
# when: installation_mode == "uninstall"

# - name: remove old backups
# file:
# path: "{{ fworch_parent_dir }}/{{ product_name }}_backup"
# state: absent
# when: installation_mode == "upgrade"

# - name: backup {{ fworch_home }} dir
# command: "cp -rf {{ fworch_parent_dir }}/{{ product_name }} {{ fworch_parent_dir }}/{{ product_name }}_backup"
# when: installation_mode == "upgrade"

- name: remove complete {{ fworch_home }} dir except for etc
file:
state: absent
path: "{{ fworch_home }}/{{ item }}"
loop:
- api
- middleware
# - api
# - middleware
- bin
- importer
- database
- ui
- lib
# - importer
# - database
# - ui
# - lib

- name: include redhat install basics
include_tasks: redhat_preps.yml
Expand Down
25 changes: 25 additions & 0 deletions roles/database/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: recover backup
synchronize:
src: "{{ fworch_home }}/backup_database/database"
dest: "{{ fworch_home }}"
delegate_to: "{{ inventory_hostname }}"
listen: "database handler"
when: database_handler_guard == "start"
become: yes

- name: delete backup
file:
state: absent
path: "{{ fworch_home }}/backup_database"
listen: "database handler"
become: yes

- name: fail message
debug:
msg:
- "An error occured during the upgrade of role {{ role_name }}"
- "Please restart the server {{ inventory_hostname }}"
- "Try to upgrade {{ product_name }} later or contact the support [email protected]"
listen: "database handler"
when: database_handler_guard == "start"
28 changes: 28 additions & 0 deletions roles/database/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
- block:

- name: initialize handler for datarecovery
set_fact:
database_handler_guard: start
changed_when: true
notify:
- database handler
when: installation_mode == "upgrade"

- name: backup database dir
synchronize:
src: "{{ fworch_home }}/database"
dest: "{{ fworch_home }}/backup_database"
delegate_to: "{{ inventory_hostname }}"
when: installation_mode == "upgrade"

- name: remove database dir
file:
state: absent
path: "{{ fworch_home }}/database"
when: installation_mode == "upgrade"

- name: include redhat db install parts
include_tasks: redhat_preps.yml
when: installation_mode == "new" and ansible_os_family == "RedHat"
Expand Down Expand Up @@ -174,3 +195,10 @@

- name: (re)define functions and views
import_tasks: recreate-functions-and-views.yml

- name: finalize handler for datarecovery
set_fact:
database_handler_guard: stop
changed_when: true
notify: "database handler"
when: installation_mode == "upgrade"
25 changes: 25 additions & 0 deletions roles/importer/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: recover backup
synchronize:
src: "{{ fworch_home }}/backup_importer/importer"
dest: "{{ fworch_home }}"
delegate_to: "{{ inventory_hostname }}"
listen: "importer handler"
when: importer_handler_guard == "start"
become: yes

- name: delete backup
file:
state: absent
path: "{{ fworch_home }}/backup_importer"
listen: "importer handler"
become: yes

- name: fail message
debug:
msg:
- "An error occured during the upgrade of role {{ role_name }}"
- "Please restart the server {{ inventory_hostname }}"
- "Try to upgrade {{ product_name }} later or contact the support [email protected]"
listen: "importer handler"
when: importer_handler_guard == "start"
144 changes: 86 additions & 58 deletions roles/importer/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,96 @@
- block:
- name: Install importer perl modules
package: name={{ item }} state=present
loop:
- libdbi-perl
- libdbd-pg-perl
- libdate-calc-perl
- psmisc
- libnet-cidr-perl
- libsys-syslog-perl
- libexpect-perl
- libcgi-pm-perl
- name: initialize handler for datarecovery
set_fact:
importer_handler_guard: start
changed_when: true
notify:
- importer handler
when: installation_mode == "upgrade"

- name: copy importer files
copy:
src: "importer"
dest: "{{ fworch_home }}"
owner: "{{ fworch_user }}"
group: "{{ fworch_group }}"
mode: "0755"
- name: backup importer dir
synchronize:
src: "{{ fworch_home }}/importer"
dest: "{{ fworch_home }}/backup_importer"
delegate_to: "{{ inventory_hostname }}"
when: installation_mode == "upgrade"

- name: set x-flag for importer executables (top level only)
file:
path: "{{ item }}"
state: file
mode: "0755"
with_fileglob: "{{ fworch_home }}/importer/*"
- name: remove importer dir
file:
state: absent
path: "{{ fworch_home }}/importer"
when: installation_mode == "upgrade"

- name: create default /var/{{ product_name }} dirs for importer
file:
path: "{{ item }}"
state: directory
owner: "{{ fworch_user }}"
group: "{{ fworch_group }}"
mode: "0755"
loop:
- /var/{{ product_name }}
- /var/{{ product_name }}/tmp
- /var/{{ product_name }}/import_archive
- name: Install importer perl modules
package: name={{ item }} state=present
loop:
- libdbi-perl
- libdbd-pg-perl
- libdate-calc-perl
- psmisc
- libnet-cidr-perl
- libsys-syslog-perl
- libexpect-perl
- libcgi-pm-perl

- name: copy import.conf
copy:
src: "import.conf"
dest: "{{ fworch_home }}/etc/import.conf"
mode: "0755"
owner: "{{ fworch_user }}"
group: "{{ fworch_group }}"
- name: copy importer files
copy:
src: "importer"
dest: "{{ fworch_home }}"
owner: "{{ fworch_user }}"
group: "{{ fworch_group }}"
mode: "0755"

- name: copy importer systemd service script
template:
src: "{{ product_name }}-importer.service.j2"
dest: "/lib/systemd/system/{{ product_name }}-importer.service"
backup: yes
mode: "0644"
owner: "root"
become: yes
- name: set x-flag for importer executables (top level only)
file:
path: "{{ item }}"
state: file
mode: "0755"
with_fileglob: "{{ fworch_home }}/importer/*"

- name: make importer run at host startup
ansible.builtin.systemd:
name: "{{ product_name }}-importer"
state: started
enabled: yes
- name: create default /var/{{ product_name }} dirs for importer
file:
path: "{{ item }}"
state: directory
owner: "{{ fworch_user }}"
group: "{{ fworch_group }}"
mode: "0755"
loop:
- /var/{{ product_name }}
- /var/{{ product_name }}/tmp
- /var/{{ product_name }}/import_archive

- name: include upgrade script
import_tasks: run-upgrades.yml
when: "installation_mode == 'upgrade'"
- name: copy import.conf
copy:
src: "import.conf"
dest: "{{ fworch_home }}/etc/import.conf"
mode: "0755"
owner: "{{ fworch_user }}"
group: "{{ fworch_group }}"

- name: copy importer systemd service script
template:
src: "{{ product_name }}-importer.service.j2"
dest: "/lib/systemd/system/{{ product_name }}-importer.service"
backup: yes
mode: "0644"
owner: "root"
become: yes

- name: make importer run at host startup
ansible.builtin.systemd:
name: "{{ product_name }}-importer"
state: started
enabled: yes

- name: include upgrade script
import_tasks: run-upgrades.yml
when: "installation_mode == 'upgrade'"

- name: finalize handler for datarecovery
set_fact:
importer_handler_guard: stop
changed_when: true
notify: "importer handler"
when: installation_mode == "upgrade"

become: yes
25 changes: 25 additions & 0 deletions roles/lib/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: recover backup
synchronize:
src: "{{ fworch_home }}/backup_lib/lib"
dest: "{{ fworch_home }}"
delegate_to: "{{ inventory_hostname }}"
listen: "lib handler"
when: lib_handler_guard == "start"
become: yes

- name: delete backup
file:
state: absent
path: "{{ fworch_home }}/backup_lib"
listen: "lib handler"
become: yes

- name: fail message
debug:
msg:
- "An error occured during the upgrade of role {{ role_name }}"
- "Please restart the server {{ inventory_hostname }}"
- "Try to upgrade {{ product_name }} later or contact the support [email protected]"
listen: "lib handler"
when: lib_handler_guard == "start"
Loading