Skip to content

Commit e1afa2f

Browse files
committed
add support for upgrading database
1 parent ed717da commit e1afa2f

File tree

4 files changed

+82
-8
lines changed

4 files changed

+82
-8
lines changed

defaults/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,9 @@ openhpc_module_system_install: true
101101

102102
# Auto detection
103103
openhpc_ram_multiplier: 0.95
104+
105+
# Database upgrade
106+
openhpc_slurm_accounting_storage_service: ''
107+
openhpc_slurm_accounting_storage_backup_cmd: "{{ undef(hint='openhpc_slurm_accounting_storage_backup_cmd must be defined if openhpc_slurm_accounting_storage_service is set') }}"
108+
openhpc_slurm_accounting_storage_backup_host: "{{ openhpc_slurm_accounting_storage_host }}"
109+
openhpc_slurm_accounting_storage_backup_become: true

handlers/main.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
---
2-
# NOTE: We need this running before slurmdbd
3-
- name: Restart Munge service
4-
service:
5-
name: "munge"
6-
state: restarted
7-
when: openhpc_slurm_service_started | bool
82

93
# NOTE: we need this running before slurmctld start
104
- name: Issue slurmdbd restart command

tasks/runtime.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@
5656
owner: munge
5757
group: munge
5858
mode: 0400
59-
notify:
60-
- Restart Munge service
59+
register: _openhpc_munge_key_copy
6160

6261
- name: Ensure JobComp logfile exists
6362
file:
@@ -159,6 +158,18 @@
159158
changed_when: false # so molecule doesn't fail
160159
become: no
161160

161+
- name: Ensure Munge service is running
162+
service:
163+
name: munge
164+
state: "{{ 'restarted' if _openhpc_munge_key_copy.changed else 'started' }}"
165+
when: openhpc_slurm_service_started | bool
166+
167+
- name: Ensure slurm database is upgraded
168+
import_tasks: upgrade.yml # need import for conditional support
169+
when:
170+
- openhpc_enable.database | default(false)
171+
- openhpc_slurm_accounting_storage_service != ''
172+
162173
- name: Notify handler for slurmd restart
163174
debug:
164175
msg: "notifying handlers" # meta: noop doesn't support 'when'

tasks/upgrade.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
- name: Check slurmdbd is inactive
2+
# only even check for upgrade if slurmdbd isn't already started
3+
command: systemctl is-active slurmdbd
4+
changed_when: false
5+
failed_when: false # rc = 0 when active
6+
register: _openhpc_slurmdbd_state
7+
8+
- name: Check if slurm database requires an upgrade
9+
ansible.builtin.command: slurmdbd -u
10+
register: _openhpc_slurmdbd_check
11+
changed_when: false
12+
failed_when: >-
13+
_openhpc_slurmdbd_check.rc > 1 or
14+
'Slurm Database is somehow higher than expected' in _openhpc_slurmdbd_check.stdout
15+
when: "_openhpc_slurmdbd_state.stdout == 'inactive'"
16+
17+
- name: Set fact for slurm database upgrade
18+
# If -u option doesn't exist it can't be a major upgrade due to existing
19+
# appliance version
20+
# Otherwise from manpage, rc 0 = no conversion, 1 = conversion required
21+
# Default skips upgrade steps if slurmdbd is running
22+
set_fact:
23+
_openhpc_slurmdb_upgrade: >-
24+
{{ false
25+
if (
26+
( _openhpc_slurmdbd_check.rc | default(0) )
27+
or
28+
( "'Usage: slurmdbd' in _openhpc_slurmdbd_check.stderr" )
29+
) else
30+
true
31+
}}
32+
33+
- name: Ensure Slurm database service stopped
34+
ansible.builtin.systemd:
35+
name: "{{ openhpc_slurm_accounting_storage_service }}"
36+
state: stopped
37+
register: _openhpc_slurmdb_state
38+
when: _openhpc_slurmdb_upgrade
39+
40+
- name: Backup Slurm database
41+
ansible.builtin.shell:
42+
cmd: "{{ openhpc_slurm_accounting_storage_backup_cmd }}"
43+
delegate_to: "{{ openhpc_slurm_accounting_storage_backup_host }}"
44+
become: "{{ openhpc_slurm_accounting_storage_backup_become }}"
45+
run_once: true
46+
when: _openhpc_slurmdb_upgrade
47+
48+
- name: Ensure Slurm database service started
49+
ansible.builtin.systemd:
50+
name: mysql
51+
state: started
52+
when: _openhpc_slurmdb_state.changed | default(false)
53+
54+
- name: Run slurmdbd in foreground for upgrade
55+
ansible.builtin.expect:
56+
command: /usr/sbin/slurmdbd -D -vvv
57+
responses:
58+
(?i)Everything rolled up:
59+
# See https://wiki.fysik.dtu.dk/Niflheim_system/Slurm_installation/#upgrade-slurmdbd
60+
# and
61+
# https://github.com/SchedMD/slurm/blob/0ce058c5adcf63001ec2ad211c65e67b0e7682a8/src/plugins/accounting_storage/mysql/as_mysql_usage.c#L1042
62+
become_user: slurm
63+
when: _openhpc_slurmdb_upgrade

0 commit comments

Comments
 (0)