Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.
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 roles/debian/apt_unattended_upgrades/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ _apt_unattended_upgrades_default_origins:
- "origin=Debian,codename=${distro_codename}-security,label=Debian-Security"
apt_unattended_upgrades:
enable: true
linotp: "false"
# unattended-upgrades template vars.
# booleans must be strings to avoid Jinja2 interpretting.
origins: "{{ _apt_unattended_upgrades_default_origins }}"
Expand Down
24 changes: 24 additions & 0 deletions roles/debian/apt_unattended_upgrades/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@
force: true
when: apt_unattended_upgrades.enable

- name: Copy unattended-upgrades linotp APT hook script.
ansible.builtin.template:
src: linotp-apt-hook.sh.j2
dest: /usr/local/sbin/linotp-apt-hook.sh
owner: root
group: root
mode: "0755"
force: true
when:
- apt_unattended_upgrades.enable
- apt_unattended_upgrades.linotp

- name: Copy unattended-upgrades linotp configuration file.
ansible.builtin.template:
src: 79linotp-pre-and-post.j2
dest: /etc/apt/apt.conf.d/79linotp-pre-and-post
owner: root
group: root
mode: "0644"
force: true
when:
- apt_unattended_upgrades.enable
- apt_unattended_upgrades.linotp

- name: Enable and start service unattended-upgrades.
ansible.builtin.service:
name: unattended-upgrades
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// r71691 Makes sure linotp database is backed up prior to upgrade then initialised.
DPkg::Pre-Invoke { "/usr/local/sbin/linotp-apt-hook.sh"; };
DPkg::Post-Invoke { "/usr/local/sbin/linotp-apt-hook.sh"; };
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

LOG="/var/log/linotp-upgrade.log"
BACKUP_DIR="/home/deploy/linotp_dbbackups"
CREDS="/home/deploy/.mysql.creds"

if apt list --upgradable 2>/dev/null | grep -q '^linotp/'; then
echo "[linotp-pre] linotp will be upgraded. Backing up database..." | tee -a "$LOG"
mkdir -p "$BACKUP_DIR"
mysqldump --defaults-file="$CREDS" linotp > "$BACKUP_DIR/linotp_backup_$(date +%F_%H-%M-%S).sql" && \
echo "[linotp-pre] Backup complete." | tee -a "$LOG" || \
echo "[linotp-pre] WARNING: Backup failed!" | tee -a "$LOG"
export LINOTP_UPGRADING=1
fi

if [ "$LINOTP_UPGRADING" = "1" ]; then
echo "[linotp-post] linotp was upgraded. Running database init..." | tee -a "$LOG"
linotp init database && \
echo "[linotp-post] linotp init database completed." | tee -a "$LOG" || \
echo "[linotp-post] linotp init database failed!" | tee -a "$LOG"
export LINOTP_UPGRADING=0
fi