After apt unattended upgrades run, I'd like to reload <REDACTED>
- User
After apt unattended upgrades run, I'd like to reload
- Assistant
To reloadhaproxyafter unattended upgrades, you can use apost-upgrade hookby placing a script in/etc/apt/apt.conf.d/. Here's how to do it:
✅ Step-by-step:
Create a new hook script:
Create a new hook script:
────────────────────────────────────────────────────────────────────
bashCopy codesudo nano /etc/apt/apt.conf.d/99haproxy-reload
Add the following content:
Add the following content:
────────────────────────────────────────────────────────────────────
bashCopy codeDPkgPost-Invoke { "systemctl reload haproxy || true"; };
This will attempt to reload HAProxy after anydpkgoperation, including those done via unattended upgrades. The|| trueensures that the upgrade process doesn’t fail if the reload fails.
Optional: Restrict to specific package
If you only want to reload HAProxywhen it's upgraded, a better approach is to use aAPT hook scriptin:
────────────────────────────────────────────────────────────────────
bashCopy code/etc/apt/apt.conf.d/
Or adpkgtrigger, but that’s trickier.
Alternatively, use a/etc/apt/apt.conf.d/50unattended-upgradesconfiguration with a script in:
────────────────────────────────────────────────────────────────────
bashCopy code/etc/apt/apt.conf.d/99local-haproxy-restart
Or useunattended-upgrades’sPost-Invokeconfiguration by modifying:
────────────────────────────────────────────────────────────────────
bashCopy code/etc/apt/apt.conf.d/50unattended-upgrades
And adding:
────────────────────────────────────────────────────────────────────
bashCopy codeUnattended-UpgradePost-Invoke-Success {"systemctl reload haproxy";};
✅ Summary
For unattended upgrades only, the cleanest is:
────────────────────────────────────────────────────────────────────
bashCopy codesudo nano /etc/apt/apt.conf.d/51reload-haproxy
────────────────────────────────────────────────────────────────────
bashCopy codeUnattended-UpgradePost-Invoke-Success {"systemctl reload haproxy || true";};
Let me know if you'd prefer to restart HAProxy instead of reloading, or if it’s managed via Docker/systemd in a non-standard way.
- User
I only want to run it when tailscale is upgraded via apt
- Assistant
Got it — you only want to reloadhaproxywhen thetailscalepackage is upgradedviaapt(including via unattended upgrades). Here's how to do that cleanly:
✅ Best approach: Use adpkghook
Create anAPT hookthat listens fortailscalebeing upgraded, and then reloadshaproxy.
- Create a new APT hook script:
- User
After nightly apt unattended upgrades, I would like to send a slack notification to our #alerts-backend channel with a summary of what was upgraded.
- Assistant
- User
Add hostname and duration of the upgrades process
- Assistant
Perfect — let’s update the script to include:
Hostname(to identify which server ran the upgrade)
- User
I don't need the duration
- Assistant
Perfect — here’s the cleaned-up version of the scriptwithout the duration, just showing thehostnameandupgrade summary:
✅ Final/usr/local/sbin/notify-upgrades-to-slack.sh
────────────────────────────────────────────────────────────────────
bashCopy code#!/bin/bash
WEBHOOK_URL= # Replace this
Get hostname
HOSTNAME=$(hostname)
Location of log
LOG_FILE="/var/log/unattended-upgrades/unattended-upgrades.log"
Get most recent upgrade summary
UPGRADE_SUMMARY=LOG_FILE" | tail -n 20)