Skip to content

Instantly share code, notes, and snippets.

@txhammer68
Last active June 10, 2025 01:04
Show Gist options
  • Save txhammer68/7a8712ccd3f9541b6e8d52112c880959 to your computer and use it in GitHub Desktop.
Save txhammer68/7a8712ccd3f9541b6e8d52112c880959 to your computer and use it in GitHub Desktop.
Setup kubuntu for automated/unattended updates

Setup Kubuntu for automated/unattended updates

For stable desktop PC, make updates more like windows/ios, don't need to deal with discover/app store or apt updates cli

Disable and mask kubuntu apt daily updates to prevent re-activation during updates

sudo systemctl disable apt-daily.timer
sudo systemctl mask apt-daily.timer
sudo systemctl disable apt-daily.service
sudo systemctl mask apt-daily.service
sudo systemctl disable apt-daily-upgrade.timer
sudo systemctl mask apt-daily-upgrade.timer
sudo systemctl disable apt-daily-upgrade.service
sudo systemctl mask apt-daily-upgrade.service
sudo systemctl disable apt-xapian-index.timer
sudo systemctl mask apt-xapian-index.timer
sudo systemctl disable apt-xapian-index.service
sudo systemctl mask apt-xapian-index.service
sudo systemctl disable cloud-init.service
sudo systemctl mask cloud-init.service

Create your own systemd timer/service units to perform the updates

Create /etc/systemd/system/sysUpdates.timer Change timer to when you want updates to occur - 2:15am

[Unit]
Description=System Updates
Requires=network-online.target
After=network-online.target
 
[Timer]
OnCalendar=*-*-* 02:15
RandomizedDelaySec=1h
Persistent=true
Unit=sysUpdates.service
 
[Install]
WantedBy=timers.target

Create /etc/systemd/system/sysUpdates.service

[Install]
WantedBy=multi-user.target
Also=sysUpdates.timer

[Unit]
Description=System Updates
After=network.target network-online.target
Requires=network-online.target

[Service]
LogLevelMax=4
Type=oneshot
ExecStart=/usr/bin/apt update -y
ExecStart=/usr/bin/apt full-upgrade -y
KillMode=process
TimeoutStopSec=960

After, Run

sudo systemctl enable sysUpdates.timer
sudo systemctl start sysUpdates.timer

Verify systemctl status sysUpdates.timer

One last step Remove Discover notifier from autostart rm /etc/xdg/autostart/discover-notifier.desktop

Bonus Set up system to clean up apt caches and auto purge removed apps/kernels quarterly

Create /etc/systemd/system/apt-cleaner.timer

[Unit]
Description=Apt Cache Cleaner Timer - Quarterly
 
[Timer]
OnCalendar=quarterly
RandomizedDelaySec=7200
AccuracySec=8h
Persistent=true
Unit=apt-cleaner.service
 
[Install]
WantedBy=timers.target

Create /etc/systemd/system/apt-cleaner.service

[Install]
WantedBy=multi-user.target
Also=apt-cleaner.timer

[Unit]
Description=Apt Cache Cleaner Service

[Service]
LogLevelMax=4
Type=oneshot
ExecStart=apt clean -y
ExecStart=apt autoclean -y
ExecStart=aptitude purge ‘~c’
ExecStart=apt autoremove -y --purge
KillMode=process
TimeoutStopSec=960

After, Run

sudo systemctl enable apt-cleaner.timer
sudo systemctl start apt-cleaner.timer

Setup System to go into Sleep/Suspend Mode at specified time.

Create $HOME/.config/systemd/user/dailySuspend.timer

[Unit]
Description=Suspend PC Daily 3am
# Requires=dailySuspend.service
 
[Timer]
OnCalendar=*-*-* 03:00:00
AccuracySec=120sec
# Persistent=true
RandomizedDelaySec=10sec
Unit=dailySuspend.service
 
[Install]
WantedBy=default.target

Create $HOME/.config/systemd/user/dailySuspend.service

[Unit]
Description=Suspend PC Daily 3am

[Service]
Type=simple
ExecStart=/usr/bin/systemctl suspend

[Install]
WantedBy=multi-user.target
Also=dailySuspend.timer

After, Run

sudo systemctl enable dailySuspend.timer
sudo systemctl start dailySuspend.timer

Now system will auto update and purge old caches/apps/kernels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment