|
| 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