Skip to content

Instantly share code, notes, and snippets.

@zanbaldwin
Last active April 22, 2024 13:18
Show Gist options
  • Save zanbaldwin/7ced7c7daf6fa77be3c887f85b9bdbde to your computer and use it in GitHub Desktop.
Save zanbaldwin/7ced7c7daf6fa77be3c887f85b9bdbde to your computer and use it in GitHub Desktop.
SystemD: Automatic Software Update
  • Install the system-update.service and system-update.timer service files to a directory that SystemD loads service definitions from.
    • The most likely directory on most distros is /etc/systemd/system/ (create this directory if it does not exist).
  • sudo systemctl daemon-reload to tell SystemD to refresh its configuration cache.
  • sudo systemctl enable --now software-update

If SystemD does not know about the software-update service you created, refer to your distros documention about which directories are checked for configuration. Perhaps try /usr/lib/systemd/system/ (not recommended initially)?

# Place this file at: /etc/systemd/system/software-update.service
[Unit]
Description=Automatic Software Update
Wants=network-online.target
After=network-online.target
[Service]
# A "oneshot" service will execute every ExecStart command (one after the other, not in parallel).
Type=oneshot
# The command used to update your system. The example used is to udpate Flatpaks.
ExecStart=/usr/bin/flatpak --system update -y --noninteractive
ExecStart=/usr/bin/snap whatever-godawful-option-you-need-to-invoke
# Perhaps you enjoy The Hat™?
ExecStart=/usr/bin/dnf --assumeyes --refresh
# Or perhaps you basic?
ExecStart=/usr/bin/apt-get update
ExecStart=/usr/bin/apt-get dist-upgrade --assume-yes
# Uncomment the following when using apt-get, to prevent the upgrade from halting if a package wants to ask a question.
#Environment="DEBIAN_FRONTEND=noninteractive"
[Install]
WantedBy=multi-user.target
# Place this file at: /etc/systeemd/systeme/software-update.timer
# This timer triggers the service with the same name.
[Unit]
Description=Automatic Software Update (Trigger)
[Timer]
# A timer that will start 5 minutes after boot, and again every day while the system is running.
OnBootSec=5m
OnUnitActiveSec=1d
Persistent=true
[Install]
WantedBy=timers.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment