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: systemd-analyze timespan turns 1h30min into plain microseconds

Systemd
~/tips/tip-systemd-analyze-timespan-units

systemd-analyze timespan 1h30min

Parses a time span like the ones in unit files and prints it normalized.

I never fully trust a duration I typed into a unit file until I have seen it normalized. OnUnitActiveSec= and TimeoutStopSec= take values like 90min, and a typo is easy to make.

systemd-analyze timespan 1h30min

The man page says the command parses a time span, a difference between two timestamps, and prints the normalized form and the equivalent value in microseconds. It prints three lines. On systemd 255 my run gave:

Original: 1h30min
      μs: 5400000000
   Human: 1h 30min

You can pass several values in one call. The manual’s own example uses 1s 300s '1year 0.000001s' and shows that 300s becomes 5min and the mixed value becomes 1y 1us. The syntax is the one from systemd.time(7), section parsing time spans. Values without a unit are seconds, so 90 means 90 seconds and not 90 minutes. That is the mistake this command catches fastest.

It also tells you how long a year is for systemd: the example shows 1year as 31557600000000 microseconds plus the added 1 microsecond, so the value is 365.25 days. Keep that in mind when you use y in a timeout.

The caveat: it only checks a duration. For a calendar expression like Mon *-*-* 03:00 you use systemd-analyze calendar, and for a single point in time there is systemd-analyze timestamp, which also prints the difference from now.

Further reading: systemd-analyze: timespan

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

Link