Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

Commit 97f574b

Browse files
committed
Merge branch 'r71691-init-linotp-db-after-upgrade' into r71691-init-linotp-db-after-upgrade-PR-devel-2.x
2 parents e7bbe6a + 5e71b51 commit 97f574b

5 files changed

Lines changed: 29 additions & 29 deletions

File tree

roles/debian/apt_unattended_upgrades/tasks/main.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@
2525
force: true
2626
when: apt_unattended_upgrades.enable
2727

28-
- name: Copy unattended-upgrades linotp configuration file.
28+
- name: Copy unattended-upgrades linotp APT hook script.
2929
ansible.builtin.template:
30-
src: 79linotp-pre-backup.j2
31-
dest: /etc/apt/apt.conf.d/79linotp-pre-backup
30+
src: linotp-apt-hook.sh.j2
31+
dest: /usr/local/sbin/linotp-apt-hook.sh
3232
owner: root
3333
group: root
34-
mode: "0644"
34+
mode: "0755"
3535
force: true
3636
when:
3737
- apt_unattended_upgrades.enable
3838
- apt_unattended_upgrades.linotp
3939

4040
- name: Copy unattended-upgrades linotp configuration file.
4141
ansible.builtin.template:
42-
src: 80linotp-post-init.j2
43-
dest: /etc/apt/apt.conf.d/80linotp-post-init
42+
src: 79linotp-pre-and-post.j2
43+
dest: /etc/apt/apt.conf.d/79linotp-pre-and-post
4444
owner: root
4545
group: root
4646
mode: "0644"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// r71691 Makes sure linotp database is backed up prior to upgrade.
2+
DPkg::Pre-Invoke { "/usr/local/sbin/linotp-apt-hook.sh"; };
3+
DPkg::Post-Invoke { "/usr/local/sbin/linotp-apt-hook.sh"; };

roles/debian/apt_unattended_upgrades/templates/79linotp-pre-backup.j2

Lines changed: 0 additions & 12 deletions
This file was deleted.

roles/debian/apt_unattended_upgrades/templates/80linotp-post-init.j2

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
LOG="/var/log/linotp-upgrade.log"
4+
BACKUP_DIR="/home/deploy/linotp_dbbackups"
5+
CREDS="/home/deploy/.mysql.creds"
6+
7+
if apt list --upgradable 2>/dev/null | grep -q '^linotp/'; then
8+
echo "[linotp-pre] linotp will be upgraded. Backing up database..." | tee -a "$LOG"
9+
mkdir -p "$BACKUP_DIR"
10+
mysqldump --defaults-file="$CREDS" linotp > "$BACKUP_DIR/linotp_backup_$(date +%F_%H-%M-%S).sql" && \
11+
echo "[linotp-pre] Backup complete." | tee -a "$LOG" || \
12+
echo "[linotp-pre] WARNING: Backup failed!" | tee -a "$LOG"
13+
fi
14+
15+
if grep -q 'Upgrade: linotp:' /var/log/apt/history.log; then
16+
echo "[linotp-post] linotp was upgraded. Running database init..." | tee -a "$LOG"
17+
linotp init database && \
18+
echo "[linotp-post] linotp init database completed." | tee -a "$LOG" || \
19+
echo "[linotp-post] linotp init database failed!" | tee -a "$LOG"
20+
fi

0 commit comments

Comments
 (0)