Chapter 10. Timekeeping and Scheduled Work
Two administrative jobs depend on each other more than they appear to.
Keeping the clock right - the system clock, the hardware clock, the time
zone, and a network time source - decides whether certificates validate,
logs correlate, and scheduled work fires when it should. Running work at
chosen times - systemd timers, cron, anacron, and one-shot at jobs - is
the other half: a schedule only means something if the clock it reads is
correct, and a system that is not always powered needs schedules that
catch up on missed work. This chapter takes both in order: how Debian
keeps time and how to configure it, how to choose and run a time
synchronization service, how systemd timers schedule unit activations,
how the classic cron stack behaves (including its mail-based failure
notifications), and finally a complete exercise that builds a scheduled
service with a dedicated account, resource limits, a failure alert, and
a clean teardown.
The examples run on two small Debian 13 systems, both kernel
6.12.86+deb13-amd64, systemd 257.13, chrony 4.6.1-3+deb13u2,
systemd-timesyncd 257.13-1~deb13u1, cron 3.0pl1-197, anacron 2.3-43,
at 3.2.5-2.2, and a local Exim 4.98.2 for cron mail:
| Role | Host name | Address | Time service |
|---|---|---|---|
| Main example system | clock | 192.168.121.19 | chrony (client, later a small server) |
| Second example system | simple | 192.168.121.207 | systemd-timesyncd |
Those addresses are examples from the lab network; replace them with your
own. One system is enough for everything except the two-host
synchronization walkthrough in Section 10.2, where one machine acts as
the server and the other as its client - any second Debian system works,
including a container or a small virtual machine. Commands entered in
john's ordinary shell begin with $, commands entered in a root shell
begin with #, and a single elevated command is written
$ sudo command; the prompt marker itself is not typed. When a
procedure says "in the root shell", enter sudo -i from john's shell
and leave that shell with exit. John's account and sudo access were
established during installation (Chapter 2
created them; Chapter 5 covers granting
them). Each console block shows one command (or one explicitly
bounded sequence) followed by its own output. Example files that belong
to john live under ~/debian-handbook/timekeeping, created the first
time they are needed; when more than one host is involved, each file's
destination is named where it is created. Chapter 3
covered the shell operators used here, and Chapter 8
covered systemd unit files, drop-ins, daemon-reload, and the journal;
both are assumed from here on. The journal reads in this chapter use
sudo throughout, because this john's account is not in the
journal-access groups (Chapter 8, Section 8.4.3,
covers the group alternative).