SaferComputing.com

Reference · Linux servers

Silent failures on an Ubuntu server: failed units, unattended upgrades, certbot and pending restarts

Find the failures an Ubuntu server does not announce: systemctl --failed, the unattended-upgrades log and a dry run, certbot.timer and certbot renew --dry-run, /var/run/reboot-required and reboot-required.pkgs, and needrestart.

Published
Updated
Last checked
Applies to
Ubuntu Server 24.04 LTS with Ubuntu's systemd, unattended-upgrades, needrestart and certbot packages
Technical specification
Target artifactThe background jobs of an Ubuntu server: systemd units, the daily security update run, certbot's renewal timer, restarts that updates are waiting for, and services still running replaced libraries.
Default behaviourUbuntu Server installs security updates daily through apt-daily-upgrade.timer, and on 24.04 needrestart restarts affected services itself. Nothing reboots the server: Unattended-Upgrade::Automatic-Reboot is false, and a pending restart shows only as a file and a line in the login message. No report is emailed unless Unattended-Upgrade::Mail is set.
Safe statesystemctl --failed lists 0 units; the unattended-upgrades log shows a run within the last day and no ERROR lines; certbot renew --dry-run succeeds; /var/run/reboot-required is absent, or a reboot is planned; needrestart -r l lists no services.
Check on Linuxsystemctl --failed
Check on Linuxsudo tail -n 20 /var/log/unattended-upgrades/unattended-upgrades.log
Check on Linuxsudo certbot renew --dry-run
Check on Linuxcat /var/run/reboot-required /var/run/reboot-required.pkgs
Fix on Linuxfix the cause, then sudo systemctl reset-failed UNIT_NAME; reboot in a planned window while /var/run/reboot-required exists

Failed units

Ubuntu
systemctl --failed
systemctl is-system-running
journalctl -u UNIT_NAME -b --no-pager -n 50
  • --failed lists units in the failed state. is-system-running prints degraded when one or more units have failed, and exits with a non-zero code, which suits monitoring scripts.
  • systemd's manual says a unit whose process exits with a non-zero code, ends abnormally or times out enters the failed state, and stays there until it is restarted or reset.
  • After fixing the cause, clear the state with sudo systemctl reset-failed UNIT_NAME. Guide 5 explains why: a list that is never empty hides the next failure.

Timers start services too: certbot.timer starts certbot.service, and certbot renew exits with 1 when a renewal fails, so a failed renewal leaves certbot.service in this list.

Unattended upgrades

unattended-upgrades.service is not the daily job. On 24.04 its unit is described as "Unattended Upgrades Shutdown" and only handles shutdown. The daily run comes from apt-daily-upgrade.timer, which starts apt-daily-upgrade.service; the unattended-upgrade manual says it is designed to run from that service.

Ubuntu, as a user with sudo
systemctl list-timers apt-daily.timer apt-daily-upgrade.timer
cat /etc/apt/apt.conf.d/20auto-upgrades
sudo tail -n 20 /var/log/unattended-upgrades/unattended-upgrades.log
  • list-timers shows when each timer last ran and runs next. On 24.04, apt-daily.timer downloads package lists at 06:00 and 18:00 with up to 12 hours of random delay, and apt-daily-upgrade.timer installs updates at 06:00 with up to 60 minutes of delay. A run missed while the server was off may happen at the next start.
  • In 20auto-upgrades, each value is a number of days: "1" runs daily, "0" turns the action off.
  • The log records every run. The line with Packages that will be upgraded: names what each run upgrades; look for WARNING and ERROR lines. The folder is readable only by root and the adm group.

Test a run

Ubuntu, as a user with sudo
sudo unattended-upgrade --dry-run --debug

--dry-run simulates the run without installing anything, and --debug adds detail, which also goes into the log. The output lists the allowed origins, the archives it takes updates from (on 24.04, noble, noble-security and the Expanded Security Maintenance archives), then the packages it would upgrade. A dry run still ends with All upgrades installed, although nothing was installed.

To get a report after each real run, set Unattended-Upgrade::Mail in /etc/apt/apt.conf.d/50unattended-upgrades; Ubuntu's documentation notes that the server then needs a mail package to send it.

Certificate renewals

Ubuntu, as a user with sudo
systemctl list-timers certbot.timer
sudo certbot renew --dry-run
sudo certbot certificates
  • Ubuntu's certbot package installs certbot.timer, which runs certbot -q renew twice a day at random times. Certbot installed another way has its own timer or cron job; Certbot's documentation says to look in systemctl list-timers or the crontab.
  • certbot renew only renews certificates close to expiry. From Certbot 4.0.0, that means less than a third of the lifetime left, or less than half for certificates that last 10 days or less; earlier versions, including the 2.9.0 package in Ubuntu 24.04, used a fixed 30 days.
  • --dry-run tests whether future renewals will succeed. With no certificates it reports No simulated renewals were attempted.
  • certbot certificates shows each certificate's Expiry Date with the days left, as (VALID: 30 days). If the days left stay below the renewal threshold, renewals are failing.
  • certbot renew exits with 1 only if a renewal attempt failed. Its logs are in /var/log/letsencrypt.

Pending restarts

Ubuntu
cat /var/run/reboot-required /var/run/reboot-required.pkgs 2>/dev/null
  • A package that needs a reboot, such as a new kernel, runs update-notifier's notify-reboot-required. It writes *** System restart required *** to /var/run/reboot-required and adds the package name to /var/run/reboot-required.pkgs. Ubuntu's login message prints the first file.
  • /var/run points to /run, which is cleared at every boot, so both files disappear after the restart.
  • With Canonical Livepatch, the client can remove the reboot notice after a kernel update, when it proves that Livepatch already covers the flaws the new kernel fixes; Livepatch's own message then shows Protected or Reboot required. The notice stays when other packages need the restart, when the check fails, or with the livepatch-agnostic policy. Canonical notes that once the notice is removed, unattended-upgrades' automatic reboot does not restart the machine and monitoring tools no longer report it.
  • Unattended upgrades reboot on their own, without confirmation, only when Unattended-Upgrade::Automatic-Reboot is "true" and /var/run/reboot-required exists after the upgrade: at once, or at the time set in Unattended-Upgrade::Automatic-Reboot-Time.

Services on replaced libraries

Ubuntu, as a user with sudo
sudo needrestart -r l
  • From Ubuntu 24.04, needrestart runs after updates and restarts affected services automatically, Ubuntu's documentation says. -r l only lists what still needs a restart; it also checks the kernel and the processor microcode.
  • To keep a service from being restarted, Ubuntu's documentation says to add a file in /etc/needrestart/conf.d/ instead of editing needrestart.conf, and to set that service's $nrconf{override_rc} entry to 0. To have needrestart only list, and restart services yourself:
Contents of /etc/needrestart/conf.d/50-list-only.conf
$nrconf{restart} = 'l';

What runs when

JobWhen it runs on 24.04Where to look
Security updates, apt-daily-upgrade.timerDaily at 06:00, up to 60 minutes late/var/log/unattended-upgrades/
Package lists, apt-daily.timer06:00 and 18:00, up to 12 hours latesystemctl list-timers
Certificate renewal, certbot.timerTwice a day at random timessystemctl --failed, certbot certificates
Service restarts, needrestartAfter each package installationneedrestart -r l
Reboot requiredWhen a package asks for one/var/run/reboot-required and the login message

The times in this table come from the packages' timer units; Ubuntu's documentation gives no interval for checking them. Updates and renewals run every day, and a failure stays silent until someone runs the checks on this page or reads an emailed report.

Sources