Removing a timer created with “systemd-run –on-calendar”

systemdsystemd-timer

I've created a systemd job using systemd-run --on-calendar .... Now I've replaced it with proper .timer and .service files, but I'm not able to remove the old one. I can stop it and disable it, but when I call systemctl list-timers it still appears with its arbitrary name run-r0d0dc22.... I also looked for its .timer file, but I couldn't find them.

Best Answer

The transient files end up in /run/user/ and do not seem to ever be removed until the user logs out (for systemd-run --user) or until a reboot, when /run is recreated.

For example, if you create a command to run once only at a given time:

systemd-run --user --on-calendar '2017-08-12 14:46' /bin/bash -c 'echo done >/tmp/done'

You will get files owned by you in /run:

/run/user/1000/systemd/user/run-28810.service
/run/user/1000/systemd/user/run-28810.service.d/50-Description.conf
/run/user/1000/systemd/user/run-28810.service.d/50-ExecStart.conf
/run/user/1000/systemd/user/run-28810.timer
/run/user/1000/systemd/user/run-28810.timer.d/50-Description.conf
/run/user/1000/systemd/user/run-28810.timer.d/50-OnCalendar.conf

For non --user the files are in /run/systemd/system/

You can remove the files, do a systemctl [--user] daemon-reload and then list-timers will show only the Unit name, with their last history if they have already run. This information is probably held within systemd's internal status or journal files.

Related Question