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.
- 66,199
- 35
- 114
- 250
- 203
- 2
- 7
3 Answers
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.
- 49,672
- 2
- 52
- 114
The accepted answer (remove the files and do a daemon-reload) did not work for me - instead I was able to remove the timer using systemd --user stop unitfile; this might differ in that I was already using a unit file, however.
Because my question, 'Systemd as at replacement' has been marked as an "exact duplicate", I shall delete it and post the content below.
I'd like to use systemd like at. I've created a unit file in ~/.config/systemd/user/[email protected] which runs a shell script (passing "%I"), but am having trouble scheduling it. If I use systemd-run --user --unit say@'test message' --on-calendar='13:54' it keeps the timer active to run tomorrow as well, instead of deleting it once it has run.
How should I instruct systemd to run a unit file exactly once at a specific time today? I would like a solution which automatically cleans up the transient timer as well, so I don't have to systemd --user stop say@'test message' afterwards.
Answer: I had to specify the full date. So - ... --on-calendar='2018-04-16 13:54:00'. This appears to clean up after itself properly as well.
- 300
- 3
- 12
-
I had to solve this same problem a week ago and I couldn't quickly find or remember how to use `systemd` as an `at` replacement... so I just installed `at`. – Iiridayn Dec 16 '21 at 22:22
I had to do
systemctl --user stop Remove_Me.{service,timer}
with systemd version 245 to remove the transient timer unit.
The {service,timer} part is a Bash feature: brace expansion
Iiridayn's answer of running systemctl --user stop Remove_Me did not work for me, I got this:
Warning: Stopping Remove_Me.service, but it can still be activated by: Remove_Me.timer
and the unit still showed up with systemctl --user list-timers *Remove*.
Reading meuh's answer, I found the .timer and .service file in /run/user/1000/systemd/transient/. After deleting the files and doing systemctl --user daemon-reload there was still the Remove_Me.timer (but no Remove_Me.service) in the output of systemctl --user list-timers.
I got rid of that lingering timer by readding the unit with
systemd-run --user --on-calendar=2025-01-01 -u "Remove_Me" touch ~/test_file
and then removing it with
systemctl --user stop Remove_Me.{service,timer}
Now, systemctl --user list-timers *Remove* shows no units.
- 7,797
- 7
- 45
- 54