brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Unit= lets one systemd timer start a service with another name

Systemd
~/tips/tip-systemd-timer-unit

[Timer]

Trigger any service from a timer, so two timers can share one job.

By default backup.timer starts backup.service, matched by name. Sometimes I want two schedules for the same job, or a timer with a clearer name than the service.

The Unit= setting in the [Timer] section names the unit to start:

# /etc/systemd/system/backup-weekend.timer
[Timer]
OnCalendar=Sat,Sun 10:00
Unit=backup.service

[Install]
WantedBy=timers.target

Now backup.timer can run the job every night and backup-weekend.timer adds an extra daytime run on weekends, both starting the same service. systemctl list-timers shows the target in its ACTIVATES column, so a nightly.timer with Unit=once.service lists once.service there.

One thing helps here: if a timer fires while the service is still running from the other timer, systemd does not start a second copy. A unit is either running or not, so the two schedules can not overlap.

The default without Unit= is a service with the same name as the timer. If you rename the service, update this line too: a timer pointing at a service that does not exist simply refuses to start, with Job failed.

Further reading: systemd.timer man page

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link