29.6. Maintaining and Retiring Long-Lived Systems
A host that survives several releases accumulates trust relationships, accounts, certificates, open ports, and assumptions. Maintenance is the periodic review of those accumulations. Retirement is the deliberate removal of the host from service without leaving a credential, a DNS record, or a copy of the data behind.
29.6.1. Reviewing Repository Trust, Accounts, and Exposed Services
Repository trust starts with the keys APT uses. On life1, as john, list the installed keyrings:
$ sudo ls -l /etc/apt/keyrings
total 4
-rw-r--r-- 1 root root 656 Nov 24 08:48 handbook-repo.gpg
The signed-by field in the source file names this keyring, so the repository's
metadata is accepted only when it is signed by the corresponding key. Inspect
the key's identity and fingerprint - in a root shell:
# gpg --show-keys --with-fingerprint /etc/apt/keyrings/handbook-repo.gpg
pub rsa2048 2026-11-24 [SC] [expires: 2027-11-24]
67B2 9A09 490D 7D4F 42C7 729E F541 3BAC D660 A126
uid Handbook Repository <repo@example.test>
The key expires in one year in this example. An expired key makes the repository
unusable until the metadata is signed by a valid replacement. Record the
fingerprint, the owner, the expiry date, and the person responsible for renewal.
A keyring in /etc/apt/trusted.gpg.d/ is trusted for all repositories, while a
keyring named by signed-by is scoped to one source; prefer the scoped form.
Chapter 6 covers repository signing and key
rotation.
Accounts accumulate in the same way. Start with the reader account and the groups that grant privilege:
$ getent passwd john
john:x:1001:1001::/home/john:/bin/bash
A real review also checks the shell, the home directory ownership, the account's expiry, the sudo policy, and the authorized keys. The following commands are read-only and can be run as root:
| Command | What it shows |
|---|---|
passwd -S john |
Password status and last-change date for the account. |
getent group sudo |
Members of the sudo group. |
ls -l /etc/sudoers.d |
Drop-in sudo policy files and their permissions. |
find /home -name authorized_keys -ls |
Authorized-key files and their ownership. |
lastlog or last -n 20 |
Recent login records, where the login database is available. |
The login history on life1, read in a root shell, shows system boots rather than interactive logins:
# last -n 3
reboot system boot 6.12.118+deb13-a Tue Nov 24 08:57 - still running
reboot system boot 6.12.86+deb13-am Tue Nov 24 08:30 - 08:57 (00:26)
reboot system boot 6.12.86+deb13-am Tue Nov 24 08:25 - crash
wtmpdb begins Tue Nov 24 08:25:48 2026
The list also documents the kernel switch from Section 29.2.2: the boot at
08:57 runs 6.12.118 where the earlier boots ran 6.12.86. The crash marker on
the 08:25 entry means the previous shutdown was not clean - here the lab
recreated the virtual machine - and the marker persists until a clean shutdown
overwrites it. An empty or boot-only history is not proof that no one logged in;
it may mean that the login database was rotated or that access uses a path that
does not record there. Correlate it with the SSH journal and the authentication
log. Look for accounts that should have expired, keys that belong to former
staff, and sudo rules that grant more than the current role requires.
Chapter 5 covers account lifecycle and sudo
policy.
Exposed services are reviewed from the socket table, not from the list of installed packages. On life1, in a root shell:
# ss -lntup | grep LISTEN | head -12
tcp LISTEN 0 511 0.0.0.0:8080 0.0.0.0:* users:(("nginx",pid=619,fd=7),("nginx",pid=618,fd=7))
tcp LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=619,fd=5),("nginx",pid=618,fd=5))
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=622,fd=6))
tcp LISTEN 0 511 [::]:80 [::]:* users:(("nginx",pid=619,fd=6),("nginx",pid=618,fd=6))
tcp LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=622,fd=7))
The list is shortened to TCP listeners. A UDP service, a socket-activated
service, or a service bound only to a Unix socket does not appear here; use
ss -lntup without the filter and systemctl list-sockets for those. For every
listener, record the owning unit, the intended clients, and the firewall rule
that permits it. A service bound to 127.0.0.1 is not reachable from another
host even when its port is open in the firewall; a service bound to 0.0.0.0
is reachable on every interface unless a firewall or network policy blocks it.
Chapter 18 covers the packet filter and
Chapter 26 covers service hardening.
29.6.2. Tracking Capacity, Certificate Expiry, and Hardware Health
Capacity is a trend, not a single reading. Record the filesystem usage and the size of the service's own data. On life1, as john:
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 98G 2.7G 91G 3% /
The service's own data is measured separately:
$ sudo du -sh /srv/lifecycle /home/john/debian-handbook/lifecycle
20K /srv/lifecycle
404K /home/john/debian-handbook/lifecycle
The root filesystem has ample space, and the service data is small. The useful number is the growth rate between reviews, not the percentage alone. A service whose data grows by 2 GB per week will fill a 100 GB filesystem in under a year, even though today's 3 percent looks comfortable. Memory is reviewed separately:
$ free -m
total used free shared buff/cache available
Mem: 1469 229 543 1 846 1240
Swap: 0 0 0
available is a better measure than free because it includes reclaimable page
cache. A host with no swap can still be healthy, but a memory spike has no
cushion; Chapter 9 covers memory pressure and
cgroup limits. Track the service's own memory with the monitoring system from
Chapter 28, not only the host total.
Certificates expire on a schedule that has nothing to do with the release schedule. On life2, in a root shell, check the service certificate's subject and expiry, and ask whether it is valid for at least the next renewal window:
# openssl x509 -in /etc/ssl/lifecycle/lifecycle.crt -noout -subject -enddate -checkend 604800
subject=CN=life2.lifecycle.lab
notAfter=Dec 24 05:20:10 2026 GMT
Certificate will not expire
-checkend 604800 asks whether the certificate will still be valid in seven
days (604800 seconds). The command exits zero and prints "Certificate will not
expire" when the answer is yes; it exits nonzero and prints a warning when the
answer is no. Choose the threshold from the renewal process: this lab
certificate was issued with a 30-day lifetime, so a threshold of 30 days would
fail during the normal renewal window. -enddate prints the expiry in UTC;
compare it with the renewal automation and the monitoring alert, not with the
local time zone.
Hardware health depends on the hardware. On a physical disk with SMART support,
smartctl -H /dev/sda reports an overall health assessment, and smartctl -a
shows the attributes and the error log. Still on life2, in the root shell, the
practice guest's virtio disk reports:
# smartctl -H /dev/vda
smartctl 7.4 2023-08-01 r5530 [x86_64-linux-6.12.86+deb13-amd64] (local build)
Copyright (C) 2002-23, Bruce Allen, Christian Franke, www.smartmontools.org
/dev/vda: Unable to detect device type
Please specify device type with the -d option.
That result means the virtual device does not implement the SMART command set;
it is not evidence that the physical disk behind the hypervisor is healthy or
unhealthy. On physical hardware, use the device name from lsblk and the
controller type from lspci; a RAID controller may require a different tool or
a -d option. For virtual machines, monitor the hypervisor's disk health and
the guest's filesystem errors instead.
Kernel messages add context. On life2, in a root shell, a scan for errors is a starting point, not a diagnosis:
# dmesg | grep -i -E 'error|fail' | tail -5
[15785.891748] systemd-ssh-generator[30011]: Failed to query local AF_VSOCK CID: Cannot assign requested address
[17024.076332] systemd-ssh-generator[31924]: Failed to query local AF_VSOCK CID: Cannot assign requested address
[17024.690825] systemd-ssh-generator[31950]: Failed to query local AF_VSOCK CID: Cannot assign requested address
[17026.711015] systemd-ssh-generator[32047]: Failed to query local AF_VSOCK CID: Cannot assign requested address
[17031.879152] systemd-ssh-generator[32210]: Failed to query local AF_VSOCK CID: Cannot assign requested address
These messages come from a virtual-machine SSH generator that cannot find a VSOCK address; they are not disk or filesystem failures. Read the full message and its unit before deciding that a host is failing. A repeated I/O error, a filesystem remount to read-only, or a machine-check exception is actionable; a single probe failure for an optional device may not be.
A maintenance review can use a compact schedule:
| Check | Suggested interval | Evidence |
|---|---|---|
| Release and point-release status | Monthly and before each window | /etc/debian_version, apt-cache policy, Debian release page |
| Package updates and reboot marker | Weekly | apt list --upgradable, /var/run/reboot-required |
| Filesystem and inode growth | Weekly | df -h, df -i, trend graph |
| Certificate expiry | Daily via monitoring, monthly by hand | openssl x509 -checkend, renewal logs |
| Backup completion and restore | Daily completion, quarterly restore drill | Timer status, checksum, restored application check |
| Account and key review | Quarterly and on staff change | getent, last, authorized_keys, sudo policy |
| Hardware health | Monthly on physical hosts | SMART or controller tool, kernel log, monitoring |
The intervals are starting points. A certificate with a 90-day lifetime needs a different review cadence from a private CA certificate with a five-year lifetime, and a host with a failing disk needs daily attention regardless of the calendar.
29.6.3. Refreshing Recovery Documentation and Testing Backups
Recovery documentation is part of the system. The practice record names the host, the service, the configuration, the data, the backup path, the restore check, and the management access path:
$ grep -E '^(Host|Backups|Restore check):' ~/debian-handbook/lifecycle/RECOVERY.md
Host: life2.lifecycle.lab
Backups: /home/john/debian-handbook/lifecycle/backups
Restore check: sha256sum -c latest.sha256, then extract into a staging directory
The record should also name the person who owns the service, the escalation path, the credentials or key locations (not the secrets themselves), the dependencies on other hosts, and the last restore-test date. Store it outside the host it describes. A recovery document that exists only on the failed disk is not a recovery document.
A backup is not verified until it has been restored. The minimum drill is: verify the archive checksum, extract it into a staging directory, compare a representative file's checksum with the source, start the application against the restored copy, and run the application's consistency check. The practice drill does the first three in Section 29.2.5 and the application test in Section 29.7.4. Record the result, including the time taken; that measurement is the evidence for the RTO, not a guess made during the outage.
Retention is a policy decision. Keep enough daily, weekly, and monthly archives to cover the RPO and the restore time, and keep at least one copy off the host and off the primary storage system. A backup on the same SAN as the production data does not protect against a SAN failure or a ransomware event that reaches both. Encrypt backups that leave a trusted network, and test that the recovery key is available to the people who will need it. Chapter 15 covers backup tools, retention, and restore procedures in depth.
29.6.4. Migrating Services and Securely Decommissioning Hosts
Migration is a traffic and data operation. Lower the DNS TTL or prepare the load balancer before the cutover, replicate or restore the data, start the new service, and test it from an independent client. Keep the old service running until the new one has passed the application tests. Then drain the old service: stop accepting new sessions, wait for in-flight requests to finish, and only then stop the listener.
The practice replacement from Section 29.7 is already serving, so the legacy listener can be retired. On life1, as john, disable the legacy site by removing its enabled symlink and reloading nginx:
$ sudo rm -f /etc/nginx/sites-enabled/lifecycle.conf
The removal is silent. Apply the change:
$ sudo systemctl reload nginx
The reload is silent too. The old listener disappears:
$ curl -fsS http://127.0.0.1:8080/
curl: (7) Failed to connect to 127.0.0.1 port 8080 after 0 ms: Could not connect to server
The nonzero exit status is the expected result: the connection was refused because nothing is listening on the old port. If the old service were behind a load balancer, you would remove it from the pool before stopping the listener and confirm that the balancer's health check marks it down. A DNS change alone may take longer than the maintenance window because of cached records and client resolvers.
Data removal is a destructive operation. Before erasing anything, confirm that the replacement has the data and that the backup is readable - the restore drill in Section 29.2.5 did both. Then erase the legacy copy:
$ sudo shred -u /srv/lifecycle/data/records.csv
The command overwrites the file and removes it, producing no output on success. Verify that the live path is gone:
$ test -e /srv/lifecycle/data/records.csv
test prints nothing; its exit status is the result. A nonzero status means the
file does not exist, which is the intended state after the erase. If the command
returns zero, the file is still present and must not be ignored. The replacement
continues to serve its restored copy:
$ curl -fsS http://192.168.229.20:8080/
<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Lifecycle service</title></head>
<body>
<h1>Lifecycle service release 2.4</h1>
<p>Managed host: life2</p>
<p>Configuration is versioned and deployed by Ansible.</p>
</body>
</html>
shred is not a secure erase on every storage type. On a copy-on-write
filesystem, a log-structured filesystem, a thin-provisioned volume, or an SSD
with wear leveling, overwriting a file does not guarantee that every physical
copy is gone. Use full-disk encryption and destroy the key (cryptographic erase),
use the storage device's secure-erase command, or physically destroy the media.
For a virtual machine, delete the virtual disk and its snapshots after
confirming that no backup still contains the data. The same rule applies to
backups: a decommissioned host's data may still exist in an old archive.
The remaining decommissioning steps are administrative:
- Remove the host from monitoring, alerting, and the configuration-management inventory so that it does not generate false failures.
- Remove DNS records, load-balancer pool members, firewall rules, and backup jobs that target the host.
- Revoke SSH host keys and user keys that were trusted only for this host;
remove the host from
known_hostsfiles on administrative workstations after confirming that it will not return. - Disable or delete service accounts, database users, API tokens, and certificates that belonged to the host. Rotate any shared secret that was stored on it.
- Preserve the recovery record, the final backup manifest, and the change record according to the retention policy, then erase the disks.
- Remove the virtual machine, its snapshots, and its volumes, or wipe and reinstall the physical host before it leaves the controlled environment.
Retirement is complete when the service is gone, the data is accounted for, and the credentials no longer work. Powering off a host is not retirement; it is a pause during which the old keys and data remain available.