Skip to content

Commit

Permalink
PMM-12221 User isn't logged out during upgrade anymore. (#2432)
Browse files Browse the repository at this point in the history
* PMM-12221 User isn't logged out during upgrade anymore.

* Update update/ansible/playbook/tasks/roles/nginx/files/conf.d/pmm.conf

Co-authored-by: Alex Tymchuk <[email protected]>

* Update update/ansible/playbook/tasks/update.yml

Co-authored-by: Alex Tymchuk <[email protected]>

* Update update/ansible/playbook/tasks/files/maintenance.html

Co-authored-by: Alex Tymchuk <[email protected]>

* Update update/ansible/playbook/tasks/files/maintenance.html

* PMM-12221 rename variable.

---------

Co-authored-by: Alex Tymchuk <[email protected]>
  • Loading branch information
BupycHuk and Alex Tymchuk authored Aug 30, 2023
1 parent 12a3523 commit b08a274
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 74 deletions.
14 changes: 14 additions & 0 deletions update/ansible/playbook/tasks/files/maintenance.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="refresh" content="5" />
<title>Maintenance Mode</title>
</head>
<body>
<h1>PMM is being upgraded</h1>
<p>Please wait until the upgrade process is finished.</p>
</body>
</html>
2 changes: 1 addition & 1 deletion update/ansible/playbook/tasks/init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
become: true
gather_facts: true
tasks:
- name: Run initializaion role
- name: Run initialization role
include_role:
name: initialization
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@
state: present
when: not ansible_check_mode

- name: Create working directory for Alertmanager
file: path=/srv/alertmanager/data state=directory owner=pmm group=pmm

- name: Create working directory for VictoriaMetrics
file: path=/srv/victoriametrics/data state=directory owner=pmm group=pmm

- name: Create empty configuration file for VictoriaMetrics
file: path=/etc/victoriametrics-promscrape.yml state=touch owner=pmm group=pmm

- name: Run SQLite -> Postgres only for docker upgrade
block:
- name: Check that the SQLite grafana database exists
Expand Down
23 changes: 23 additions & 0 deletions update/ansible/playbook/tasks/roles/nginx/files/conf.d/pmm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,29 @@
ssl_trusted_certificate /srv/nginx/ca-certs.pem;
ssl_dhparam /srv/nginx/dhparam.pem;

# this block checks for maintenance.html file and, if it exists, it redirects all requests to the maintenance page
# there are two exceptions for it /v1/Updates/Status and /auth_request endpoints
set $maintenance_mode 0;

if (-f /usr/share/pmm-server/maintenance/maintenance.html) {
set $maintenance_mode 1;
}

if ($request_uri ~* "^/v1/Updates/Status|^/auth_request") {
set $maintenance_mode 0;
}

if ($maintenance_mode = 1) {
return 503;
}

error_page 503 @maintenance;

location @maintenance {
root /usr/share/pmm-server/maintenance;
rewrite ^(.*)$ /maintenance.html break;
}


# Enable passing of the remote user's IP address to all
# proxied services using the X-Forwarded-For header
Expand Down
121 changes: 48 additions & 73 deletions update/ansible/playbook/tasks/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,59 @@
is_docker: True
when: is_docker is undefined
tasks:
# we need install this package here because it contain VERSION file
- name: Enable maintenance mode
copy:
src: maintenance.html
dest: /usr/share/pmm-server/maintenance/
mode: 0644

- name: Remove percona-dashboard without architecture
yum:
name: percona-dashboards.*noarch
state: absent

# see https://jira.percona.com/browse/PMM-8492 for details about a issue
- name: Delete experimental repo file in 2.16 version
file:
path: "/etc/yum.repos.d/percona-original-experimental.repo"
state: absent
register: experimental_repo_existed

- name: Update percona-dashboards package
yum:
name:
- percona-dashboards
- percona-grafana
state: latest

- name: Cleanup yum metadata
command: yum clean metadata
register: yum_clean_result
changed_when: "'Cleaning repos' in yum_clean_result.stdout"
when: experimental_repo_existed.changed
tags:
- skip_ansible_lint # '503 Tasks that run when changed should likely be handlers'.
# The handler looks bad in this case

# TODO: join with the command above
- name: Cleanup yum metadata
command: yum clean metadata
become: true
tags:
- skip_ansible_lint

# Split download and update to produce a bit more of progress output.
- name: Download pmm2 packages
yum:
name: "{{ pmm_packages }}"
state: latest
download_only: yes

- name: Update pmm2 packages
yum:
name: "{{ pmm_packages }}"
state: latest

- name: Create supervisord dir
file:
path: /etc/supervisord.d/
Expand All @@ -62,27 +102,12 @@
src: pmm.ini
dest: /etc/supervisord.d/pmm.ini

# restart pmm-managed-init and pmm-managed first as they may update supervisord configuration on start
- name: Generate new supervisor config
command: pmm-managed-init
register: managed_init_result
changed_when: True

- name: Update postgresql version_1
command: sed -i 's:-D /srv/postgres$:-D /srv/postgres14:' /etc/supervisord.d/pmm.ini
changed_when: true

- name: Update postgresql version_2
command: sed -i 's:/usr/pgsql/bin/postgres:/usr/pgsql-14/bin/postgres:' /etc/supervisord.d/pmm.ini
changed_when: true

- name: Update postgresql version_3
command: sed -i 's:/srv/logs/postgresql.log:/srv/logs/postgresql14.log:' /etc/supervisord.d/pmm.ini
changed_when: true

- name: Update postgresql version_4
command: sed -i 's:/usr/pgsql-11/bin/postgres:/usr/pgsql-14/bin/postgres:' /etc/supervisord.d/pmm.ini
changed_when: true

- name: Disable pmm-update-perform-init
ini_file:
path: /etc/supervisord.d/pmm.ini
Expand Down Expand Up @@ -195,48 +220,6 @@
- name: Check reread results
debug: var=reread_result.stdout_lines

# see https://jira.percona.com/browse/PMM-8492 for details about a issue
- name: Delete experimental repo file in 2.16 version
file:
path: "/etc/yum.repos.d/percona-original-experimental.repo"
state: absent
register: experimental_repo_existed

- name: Cleanup yum metadata
command: yum clean metadata
register: yum_clean_result
changed_when: "'Cleaning repos' in yum_clean_result.stdout"
when: experimental_repo_existed.changed
tags:
- skip_ansible_lint # '503 Tasks that run when changed should likely be handlers'.
# The handler looks bad in this case

# TODO: join with the command above
- name: Cleanup yum metadata
command: yum clean metadata
become: true
tags:
- skip_ansible_lint

# Split download and update to produce a bit more of progress output.
- name: Download pmm2 packages
yum:
name: "{{ pmm_packages }}"
state: latest
download_only: yes

- name: Update pmm2 packages
yum:
name: "{{ pmm_packages }}"
state: latest


# restart pmm-managed-init and pmm-managed first as they may update supervisord configuration on start
- name: Generate new supervisor config
command: pmm-managed-init
register: managed_init_result
changed_when: True

- name: Restart pmm-managed EL7
when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '7'
command: supervisorctl {{ item }} pmm-managed
Expand All @@ -254,7 +237,7 @@
# give pmm-managed time to update supervisord configuration,
# and give update UI time to catch up after pmm-managed restart
- name: Wait for pmm-managed
pause: seconds=5
pause: seconds=10

- name: Update system packages
yum:
Expand Down Expand Up @@ -325,19 +308,6 @@
regexp: "set -o errexit"
replace: ""

# TODO: Create /srv/alertmanager/data and /srv/victoriametrics/data in pmm-managed
# to support Docker-way (swap image) updates.
# https://jira.percona.com/browse/PMM-7024

- name: Create working directory for Alertmanager
file: path=/srv/alertmanager/data state=directory owner=pmm group=pmm

- name: Create working directory for VictoriaMetrics
file: path=/srv/victoriametrics/data state=directory owner=pmm group=pmm

- name: Create empty configuration file for VictoriaMetrics
file: path=/etc/victoriametrics-promscrape.yml state=touch owner=pmm group=pmm

- name: Reread supervisord configuration again EL7
when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '7'
command: supervisorctl reread
Expand Down Expand Up @@ -460,6 +430,11 @@
register: maintail_result
changed_when: False

- name: Disable maintenance mode
file:
state: absent
path: /usr/share/pmm-server/maintenance/maintenance.html

- name: Print supervisord logs
debug: var=maintail_result.stdout_lines

Expand Down

0 comments on commit b08a274

Please sign in to comment.