387. Timers
A periodic job on KDOS is one line in a .timer file, and snooze, a program that sleeps until the clock matches its options and then runs one command, does the waiting. There are three tables: the system’s, /etc/kdos/timers.d/, whose jobs run as root under the service supervisor from boot; /etc/kdos/user-services/timers.d/, whose jobs run for every user, as that user; and each user’s own, ~/.config/kdos/timers.d/. The two user tables run under the user’s services from the user’s first login to the last. Users’ crontabs, written with crontab -e or System Settings’ Task Scheduler, are cronie’s, which reads no /etc/crontab, so no job is in both. This page covers the tables: reading and checking a schedule, adding and removing a job, running one now, and finding out why one did not fire.
Installation
- snooze installs
/usr/bin/snoozeand its manual page,snooze(1), which is the reference for every time option. - The base filesystem supplies
/etc/init.d/18_timers.sh, the servicetimers, which starts one supervisedsnoozeper line of the system table at boot; the system table itself with its shipped jobs; the user service/etc/kdos/user-services/30_timers.sh, which runs/usr/local/lib/kdos/user-timersfor the two user tables; the every-user table with its one job; and the user table’s skeleton,/etc/skel/.config/kdos/timers.d/, copied into each new home directory./usr/local/lib/kdos/timers.shis the one parser all three share. - cronie installs
crondand the setuidcrontab, started by/etc/init.d/85_crond.sh, for users’ crontabs; kcron is the Task Scheduler page, which is not in the base the ISO carries (sudo kdos update install kcron; see Installing software). kdos remind, from kdos-tools, writes reminders into the user table.
The services timers and crond are enabled on the live medium and on an installed system alike. On the live medium a job added to any table is kept only when a persistence store exists (kdos persist).
Configuration
The line
Every line of every table has the same shape:
NAME TIMESPEC... -- COMMAND...
NAME is letters, digits, _ and -. TIMESPEC is snooze’s own options, unchanged. -- ends the timespec, and everything after it is the command: an argument vector, split on blanks, never passed to a shell, with no quoting, so an argument cannot contain a space. Blank lines and lines starting with # are ignored. The rules are in /etc/kdos/timers.d/ and ~/.config/kdos/timers.d/.
/etc/kdos/timers.d/
The system table’s own description, fs/etc/kdos/timers.d/README:
Periodic jobs, one per line, read by /etc/init.d/18_timers.sh at boot.
NAME TIMESPEC... -- COMMAND...
NAME names the supervised service, so `service status timers` and
`ksvc check kdos-timer-NAME` can both find it. TIMESPEC is `snooze`'s own
options and nothing else is invented here. `--` ends the timespec: without it
nothing can tell where snooze's options stop and the command begins, because
both are bare words.
THE COMMAND IS AN ARGUMENT VECTOR AND NOT A SHELL LINE. No pipe, no
redirection, no glob, no `&&` — a program that needs to write a file takes a
flag that names it. That is the same rule every other configuration file in
this tree keeps, and it is why this one can be parsed rather than sourced.
A LINE THAT DOES NOT PARSE IS REPORTED AND SKIPPED, never guessed at: a timer
that silently did not start is indistinguishable from one that has not fired
yet, and the difference can be months.
The per-user tables have the same shape and the same parser
(/usr/local/lib/kdos/timers.sh): ~/.config/kdos/timers.d/ for each user's own
jobs, and /etc/kdos/user-services/timers.d/ for jobs every user runs as
themselves. Both run under that user's `timers` service
(/etc/kdos/user-services/30_timers.sh), from the user's first login to the
user's last, or for good once the user lingers.
The two jobs the base system ships:
# The installed packages older than their recipe in the tree already in
# place, which of them the signed binhost index already in the cache covers,
# and the update that makes this system current, into the update document.
# Its readers are kdos-sysupdated (the system update Discover shows, and the
# AppStream file it serves), the update tray (the Discover notifier's KDOS
# plugin) and kdos-notice. It downloads nothing: no tree, no index, no source.
# A newer tree and its index arrive only when somebody asks — Discover's
# "Check for updates", which kdos-sysupdated answers with
# `kdos update check --fetch`, or `kdos update fetch` typed at a shell — so no
# machine reaches the network on a schedule of its own. Nightly and NOT at
# midnight: the job reads the whole ports tree and every package entry.
#
# -s 8h is the missed-run rule and it is snooze's, not ours: a machine that was
# ASLEEP at 04:17 runs the job ONCE when it wakes, if it wakes within eight
# hours of the slot. Not once per missed occurrence — a laptop shut for a
# fortnight would otherwise run fourteen of them at breakfast.
#
# A machine that was OFF is a different case and this line does not cover it: a
# snooze started at boot begins looking one second from now, so the slot it
# slept through is simply tomorrow's. Reaching back needs `-t FILE`, and a
# timefile only the job itself may touch.
update-check -H 4 -M 17 -s 8h -- kdos update check --out /var/lib/kdos/update.json
fs/etc/kdos/timers.d/10-update-check.timer
# Tells every mounted SSD which blocks are free. The installer mounts ext4 and
# xfs without `discard`, so without this a freed block is never reported and
# the drive's write speed and wear degrade as it fills with blocks it believes
# are still in use. btrfs and f2fs already discard as they free blocks, so on
# them this is a cheap second pass. A filesystem whose device cannot discard
# is skipped by fstrim itself.
#
# Daily, and at midday rather than overnight: fstrim cannot touch a timefile,
# so there is no `-t` and a slot the machine was OFF for is simply missed. A
# desktop switched off every night would never reach a 03:00 slot. ext4 skips
# a block group it has trimmed and freed nothing in since, so on a mounted ext4
# the runs after the first cost little.
#
# -s 20h: a machine ASLEEP at the slot runs it once when it wakes, within the
# day.
fstrim -H 12 -M 47 -s 20h -- fstrim -a
fs/etc/kdos/timers.d/20-fstrim.timer
No port adds a system job.
/etc/init.d/18_timers.sh
How a line becomes a supervised job. A command that is not installed is skipped with a [SKIP] line; everything else is handed to supervise as the service kdos-timer-NAME. A status query fails when any one job is down, not only the last one read:
timer_start() { # <name> <spec> <command...>
_n=$1; _s=$2; shift 2
if ! command -v "$1" >/dev/null 2>&1; then
echo "[SKIP] $NAME: $_n needs $1, which is not on this image"
return 0
fi
# $_s IS a word list, which is the point, and it is expanded under
# noglob for the reason the parser splits it under noglob: `-H *` would
# otherwise reach snooze as the names of the files in rcS's directory.
set -f
# shellcheck disable=SC2086
supervise "kdos-timer-$_n" snooze $_s "$@"
set +f
}
timer_stop() { # <name> <spec> <command...>
stop_service "kdos-timer-$1"
}
# Any job down makes the whole status non-zero. timers_each returns whatever
# its last command did, which is the last job's answer or a skipped comment
# row's 0, so the result is collected here rather than taken from it.
timers_rc=0
timer_status() { # <name> <spec> <command...>
check_status "kdos-timer-$1" || timers_rc=1
}
fs/etc/init.d/18_timers.sh, lines 36–61
/etc/kdos/user-services/timers.d/
Rows here run for every user, as that user, beside the user’s own table. The one KDOS ships gives idle boxes back, from fs/etc/kdos/user-services/timers.d/40-box-gc.timer:
# Rows here run for EVERY user, as that user, under the `timers` user service
# (/etc/kdos/user-services/30_timers.sh), beside the user's own
# ~/.config/kdos/timers.d. The shape is /etc/kdos/timers.d's:
#
# NAME TIMESPEC... -- COMMAND...
#
# GIVING IDLE BOXES BACK. `kdos-box gc` stops a box that has run past its
# profile's `autostop` with no window on the screen; nothing else calls it.
# Every ten minutes, from the user's own services rather than from a root
# service, because the boxes are the user's and so is the question asked about
# their windows before any is stopped — a gc that cannot ask leaves every box
# running. nice 10, so a gc that lands during a login does not take the CPU
# from the desktop coming up.
box-gc -H * -M /10 -- nice -n 10 kdos-box gc
fs/etc/kdos/user-services/timers.d/40-box-gc.timer
The user service
From fs/etc/kdos/user-services/30_timers.sh, how the two user tables are run:
# THE USER'S PERIODIC JOBS, for as long as the user has a login — graphical,
# a tty, or the linger file that keeps the user's services up with none.
#
# One supervised daemon, /usr/local/lib/kdos/user-timers, runs every row of
# /etc/kdos/user-services/timers.d and ~/.config/kdos/timers.d as a loop of
# its own, in its process group: stopping this service ends every loop and
# every waiting snooze with the one group signal. The table's shape and its
# rules are /etc/kdos/timers.d's; the file that says what each row may hold is
# the README beside the user's table.
#
# `service --user restart timers` reads both tables again, and so does a
# SIGHUP to the pid in $XDG_RUNTIME_DIR/kdos/user-timers.pid; both stop a job
# that is running at that moment. A SIGUSR1 to the same pid starts only the
# files that have no loops yet, which is what `kdos remind` sends.
fs/etc/kdos/user-services/30_timers.sh, lines 4–17
~/.config/kdos/timers.d/
The user table’s description, from the skeleton:
Your own periodic jobs, one per line, run by your `timers` user service from
your first login to your last.
NAME TIMESPEC... -- COMMAND...
The shape is /etc/kdos/timers.d's, and TIMESPEC is `snooze`'s own options —
`-H 9 -M 0` for nine in the morning, `-d /2` for every second day. `snooze(1)`
is the whole reference; nothing is invented here. There is no `--help`.
`-s SLACK` IS NOT ENOUGH ON ITS OWN. A snooze that has just started begins
looking one second from now, so a slot already past is simply the same slot
next time round, whatever the slack says. `-t FILE` is what changes that: it
starts looking from that file's modification time, and the slack then covers
the gap. The file must be one the job's own program writes after every run:
a file nothing touches, such as a .timer table, leaves each restart of the
loop finding the same slot inside the slack and running the job again until
the slack has passed. Write its path out in full, since a row never goes
through a shell and `~` or `$HOME` reach snooze as those characters. With the
job writing /home/you/.cache/mine.stamp, `-s 4h -t /home/you/.cache/mine.stamp`
means "if the machine was off at the slot, run it once when I log in, up to
four hours late".
THE COMMAND IS AN ARGUMENT VECTOR. No pipe, no redirection, no `&&`: a program
that writes a file takes a flag naming it. That is what lets this file be
parsed instead of sourced, and it is why a line here cannot run something you
did not write.
EVERY SLOT WHILE YOU ARE LOGGED IN. `snooze` waits for its slot, runs the
command once and exits, so /usr/local/lib/kdos/user-timers runs each row in a
loop that starts it again: a job here fires at every occurrence of its slot,
not once per login. It is the `timers` service of your own services
(/etc/kdos/user-services, `service --user status timers`), which start at your
first login of any kind — the desktop, a console, either — and stop at your
last, unless you linger (`loginctl enable-linger`), and then they run with no
login at all. A file added or edited while you are logged in is read at the
next start, or now with `service --user restart timers`. A job's error output
is in $XDG_RUNTIME_DIR/ksvc/kdos-svc.timers.log and in syslog. Use
/etc/kdos/timers.d for a job that must run whether or not anybody is logged in.
A COMMAND HERE CANNOT TAKE AN ARGUMENT WITH A SPACE IN IT. The row is split
into words and never quoted, so `-- kdos notify "Good morning"` reaches the
command as `"Good` and `morning"`. A program that needs a sentence reads it
from a file of its own; `kdos remind` writes its text as this file's first
comment line for exactly that reason.
An example, commented out because a table with a job in it is a decision:
# weather -H 7 -M 30 -s 2h -- kdos notify --time
fs/etc/skel/.config/kdos/timers.d/README
Replace /home/you in the -t example with your own home directory, written out in full: a row is never given to a shell, so ~ and $HOME would reach snooze as those characters. The file a -t names must be one the job itself writes after each run; see Tips.
The two jobs in the skeleton. The backup job is commented out:
# The file index `plocate` searches, rebuilt nightly.
#
# ENABLED, unlike the backup beside it, and the difference is what it costs and
# what it holds. It walks $HOME ONLY — never the whole filesystem — writes into
# this user's own cache, and can therefore contain nothing this user could not
# already list. There is no shared database and no setgid binary to read one;
# the decision is in docs/kdos/03-architecture/security-model.md.
#
# kdos-updatedb rather than `updatedb` directly, because THIS TABLE IS AN
# ARGUMENT VECTOR AND IS NEVER SOURCED: a `$HOME` written on this line would be
# four literal characters. The wrapper resolves the two paths and is where the
# scoping rule is written down.
#
# 03:05, which is neither the update check's 04:17 nor the backup's 03:40: two
# jobs at the same second on a laptop that has just woken are two jobs
# competing for one disk. -s 8h is snooze's missed-run rule — once when the
# machine WAKES, not once per missed occurrence, and not at all for a machine
# that was off across the slot; see the README beside this file. An account
# with no index yet gets its first one at login, from the timers service
# (`kdos-updatedb --if-missing`), not from this row.
updatedb -H 3 -M 5 -s 8h -- kdos-updatedb
fs/etc/skel/.config/kdos/timers.d/20-updatedb.timer
# The nightly backup, and it is COMMENTED OUT on a shipped image.
#
# A backup nobody asked for is a surprise, and the first run over a home
# directory can be hours. Uncomment this line once ~/.config/kdos/backup.conf
# names a repository and ~/.config/kdos/backup.pass holds its password at mode
# 0600 — `kdos backup run` refuses to run without both, so an enabled timer
# with no configuration writes a message and stops rather than half-running.
#
# NOT AT MIDNIGHT, and not at 04:17 either: 04:17 is the update check's slot
# and two jobs at the same second on a laptop that has just woken is two jobs
# competing for the same disk.
#
# -s 8h is snooze's missed-run rule, written down rather than reimplemented: a
# machine ASLEEP at the slot runs the job ONCE when it wakes, if it wakes
# within eight hours. Not once per missed occurrence. A machine that was OFF is
# not covered — see the README beside this file.
#
# THIS IS THE USER'S TABLE, NOT THE SYSTEM'S. It runs under the user's own
# services, from the first login to the last — a job writing into $HOME has no
# business firing on a machine its person has logged out of, unless that
# person asked for it with `loginctl enable-linger`.
# backup -H 3 -M 40 -s 8h -- kdos backup run
fs/etc/skel/.config/kdos/timers.d/10-backup.timer
Usage
Seeing what is scheduled
List every system job and whether its
snoozeis waiting:service status timersEach job prints
[ OK ] kdos-timer-NAME (pid N)or[DOWN] kdos-timer-NAME. For the five seconds after a run whose command failed, beforesnoozestarts again, it prints[FAIL] kdos-timer-NAME (exited with code N; restarting); a run that succeeded leaves it[ OK ]. The command exits 0 only when every job is[ OK ]; one[DOWN]or[FAIL]job anywhere in the list makes it exit 1, so a script can test it withif service status timers.Ask about one system job:
ksvc check kdos-timer-update-checkPrint the next five times a timespec matches, without running anything:
snooze -n -H 4 -M 17Each line is a time, its weekday and how far away it is, such as
2026-10-22T04:17:00+0000 Thu 0d 9h 4m 12s.snooze -nexits non-zero for a timespec it does not accept:snooze -n -H 99printsnumber outside 0 <= n < 24and exits 1.
Adding a system job
Check the timespec with
snooze -n, as above.Write the line into a new file under
/etc/kdos/timers.d/, as root. The file name must end in.timer; the job’s name is the first word of the line, not the file name. For a run every day at 06:30, up to two hours late after a sleep:mybackup -H 6 -M 30 -s 2h -- /usr/local/sbin/mybackup --quietRestart the service, which stops every system job and starts the table again:
sudo service restart timersCheck that the job is waiting:
ksvc check kdos-timer-mybackup
Removing or changing a system job
service stop timers stops only the jobs it finds in the table as it is when it runs, so stop a job before removing its line:
Stop the job:
sudo ksvc stop-supervised kdos-timer-mybackupDelete or edit the line.
If you edited it, start the table again with
sudo service restart timers.
Running a job now
A job’s command is an ordinary command. To run it once now, type the part after -- as root, for example:
sudo fstrim -a
To stop every system job until the next boot, run sudo service stop timers; to stop them at every boot, sudo service disable timers.
Adding a job of your own
Write the line into a file ending
.timerunder~/.config/kdos/timers.d/.Check it, since a line the runner cannot use is skipped, and the only word about it is a line in the service’s log (see Troubleshooting):
snooze -n -H 7 -M 30 command -v <the command's first word>Read the tables again:
service --user restart timersThis stops every user job running at that moment. The loops run from the user’s first login to the last, whether that is the desktop, a console or both.
A reminder needs none of this: kdos remind in 20m tea writes a row of its own and also starts a snooze for it at once; see kdos remind.
Tips
- A job that must run even when the machine was off across its slot needs
-t FILEas well as-s.snoozethen counts from the file’s modification time, and the job must update that file itself, sincesnoozenever touches it. A command on the line cannot runtouchas well, so such a job is a script that does its work and then touches the file. If nothing touches it, every restart ofsnoozefinds the slot just run still inside the slack and runs the job again, until the slack has passed. - No
~and no$HOME. Nothing on a line is expanded, so a path in a timespec or a command is written in full,/home/you/...; a program that needs the home directory finds it itself, askdos-updatedbdoes. - Give each job a minute of its own. A laptop that wakes after several slots have passed runs every job whose slack covers the gap at the same moment.
*is safe in a timespec.18_timers.shand the user runner both split the line with pathname expansion off, so-M *reachessnoozeas written.- A command that needs a pipe or a redirection has to be a script of its own, named on the line.
- The times are local times.
snoozereads the clock through the machine’s time zone,/etc/localtime, which a time-zone change through timedate1 sets. kdos why /etc/kdos/timers.d/10-update-check.timerreports that no package owns the file; it is part of the base filesystem.
Troubleshooting
A system job never fires. Read what 18_timers.sh printed at boot:
cat /run/kdos-init.timers.log
Each complaint names the file and the line:
[KDOS] (kdos-timers) /etc/kdos/timers.d/91-test.timer:2: bad timer name 'bad.name'
[KDOS] (kdos-timers) /etc/kdos/timers.d/91-test.timer:3: no '--' or no command; skipped
[SKIP] kdos-timers: missing needs /usr/bin/nonexistent-x, which is not on this image
bad timer name means the name holds a character other than letters, digits, _ and -; a line ending skipped has no -- or nothing after it; the [SKIP] line means the command’s first word is not installed, and that job is then listed [DOWN] by service status timers, which therefore exits 1 until the line is corrected or removed. Correct the line and run sudo service restart timers. The file holds the boot’s output only: a restart prints the same lines to the terminal and leaves the file as the boot wrote it.
A system job fired but did nothing useful. Its output went to the supervisor’s log for the job and to the system log, tagged kdos-timer-NAME:
sudo cat /run/kdos-svc.kdos-timer-NAME.log
sudo grep kdos-timer-NAME /var/log/messages
A user job never fires. service --user status timers must say the service runs; its log is $XDG_RUNTIME_DIR/ksvc/kdos-svc.timers.log. Check the timespec with snooze -n and the command with command -v, as in Adding a job of your own, and check that the file name ends in .timer. Its standard output is discarded and its standard error goes to that log and to syslog, so a job that must leave a trace writes it to standard error.
A job missed its slot while the machine was off. That is how -s behaves; add -t FILE, as in Tips.
Known gaps
- Nothing installs updates on a timer: the update-check job only fetches the ports tree and reports what is behind. See Security.
- The user tables’ loops run only while the user has a login, unless the user lingers.
See also
- Periodic jobs: the shipped jobs and why each runs when it does
- /etc/kdos/timers.d/ and ~/.config/kdos/timers.d/: the format and the two tiers
- kdos remind: one-off reminders through the user table
- Supervision and logging: how each system job is supervised
- Services, Logs