You are not logged in.

#1 2025-05-08 16:24:06

Blablabla3012
Member
Registered: 2025-05-08
Posts: 5

Help with .timer and .service files

I have two files:

#cat ~/.config/systemd/user/myAlarm_test.service

[Unit]
Description=execute rickroll
[Service]
ExecStart=/usr/bin/vlc /home/bla/.config/systemd/user/rickroll.mp4
[Install]
WantedBy=multi-user.target
#cat ~/.config/systemd/user/myAlarm_test.timer

[Unit]
Description=timer test
[Timer]
OnCalendar=+5s
AccuracySec=1us
[Install]
WantedBy=timers.target

rickroll.mp4 exists.

I want to execute rickroll.mp4 with vlc media player 5 seconds after using

systemctl --user myAlarm_test.timer

but this doesn't work. i don't know where to look my mistake and how.

Offline

#2 2025-05-08 16:26:04

mithrial
Member
Registered: 2017-03-05
Posts: 151

Re: Help with .timer and .service files

Did you start the timer? What's the log?
Also, I guess it needs the DISPLAY variable to open vlc.

Offline

#3 2025-05-08 16:35:41

Blablabla3012
Member
Registered: 2025-05-08
Posts: 5

Re: Help with .timer and .service files

in the log there is:

/home/bla/.config/systemd/user/myAlarm_test.timer:5: Failed to parse calendar specification, ignoring: +5s
myAlarm_test.timer: Timer unit lacks value setting. Refusing.

also systemd-analyze verify returns:

/home/bla/.config/systemd/user/myAlarm_test.timer:5: Failed to parse calendar specification, ignoring: +5s
myAlarm_test.timer: Timer unit lacks value setting. Refusing.
Unit myAlarm_test.timer has a bad unit file setting.

how do i set the DISPLAY variable?

Offline

#4 2025-05-08 17:59:04

Scimmia
Fellow
Registered: 2012-09-01
Posts: 13,725

Re: Help with .timer and .service files

What does +5s have to do with the calender? It makes no sense. Sounds like you're wanting OnActiveSec.

What is systemctl --user myAlarm_test.timer supposed to do? You didn't tell it to start, enable, get status, etc.

Offline

#5 2025-05-08 18:08:43

Blablabla3012
Member
Registered: 2025-05-08
Posts: 5

Re: Help with .timer and .service files

i did OnCalenar=+5s cause i first had a specified time but then wanted to try if it works and did +5s like it was descriped on docs of systemd.time(7).

"systemctl --user myAlarm_test.timer" was a spelling mistake. meant "systemctl --user enable myAlarm_test.timer".

Offline

#6 2025-05-08 18:29:05

Blablabla3012
Member
Registered: 2025-05-08
Posts: 5

Re: Help with .timer and .service files

I also tried setting

OnCalendar=Thu, my:time

for trying it, but it won't execute vlc.

Offline

#7 2025-05-08 20:14:54

mithrial
Member
Registered: 2017-03-05
Posts: 151

Re: Help with .timer and .service files

Then give a log for the correct OnCalendar.

Offline

#8 2025-05-08 22:39:04

Scimmia
Fellow
Registered: 2012-09-01
Posts: 13,725

Re: Help with .timer and .service files

enable tells it to start the next time the user session starts, it doesn't start it now.

Offline

#9 2025-05-09 03:03:01

dakota
Member
Registered: 2016-05-20
Posts: 417

Re: Help with .timer and .service files

Blablabla3012 wrote:
#cat ~/.config/systemd/user/myAlarm_test.timer

[Unit]
Description=timer test
[Timer]
OnCalendar=+5s
AccuracySec=1us
[Install]
WantedBy=timers.target

rickroll.mp4 exists. I want to execute rickroll.mp4 with vlc media player 5 seconds after using

systemctl --user enable myAlarm_test.timer

but this doesn't work. i don't know where to look my mistake and how.

As Scimmia says, you also need to start the timer.

But shouldn't the timer include some sort of action? I mean, how is it supposed to start myAlarm_test.service? Maybe something in the [Timer] section, like

Unit=myAlarm_test.service

I don't know if that's right (I might be missing something), and you might need to change the syntax for a user service.

Edit -- see next post.

Cheers,

Last edited by dakota (2025-05-09 12:50:53)


"Before Enlightenment chop wood, carry water. After Enlightenment chop wood, carry water." -- Zen proverb

Offline

#10 2025-05-09 11:47:34

mithrial
Member
Registered: 2017-03-05
Posts: 151

Re: Help with .timer and .service files

No, that's just wrong. A timer will start the service with the same name. So the naming is correct here.

myAlarm_test.timer starts the service myAlarm_test.service

What exactly is your goal? It works for me:

# /home/user/.config/systemd/user/myAlarm_test.timer
[Unit]
Description=timer test
[Timer]
OnCalendar=Fri, 13:44
AccuracySec=1us
[Install]
WantedBy=timers.target
# /home/user/.config/systemd/user/myAlarm_test.service
[Unit]
Description=execute rickroll
[Service]
ExecStart=/usr/bin/vlc /home/user/file.mp4
[Install]
WantedBy=multi-user.target

Depending how you create the files, you have to run

systemctl --user daemon-reload

If you have a syntax error, it will tell you in

journalctl --user -f

Then, you can start/enable the timer:

systemctl --user enable --now myAlarm_test.timer

(the --now starts it right away).


But when do you want to run it? In your first post, you gave OnCalendar=+5s which is not a valid date/time.

Offline

#11 2025-05-09 12:26:49

Nikolai5
Member
From: North West, England, UK
Registered: 2024-01-27
Posts: 272

Re: Help with .timer and .service files

Yeah, how often do you want it to run?

I use one with these options:
[Timer]
OnBootSec=10min
OnUnitActiveSec=1h

It runs first time after 10 minutes, and then otherwise runs once an hour. With how you're attempting to use "+5s" it looks like you don't want to use the calendar option but instead have it run after some time has elapsed?
If that's the case check out this article: https://wiki.archlinux.org/title/Systemd/Timers
There are some examples in there of different ways to set the timer.

As others have said it timers execute the .service based on the file name:  test1.timer will execute test1.service.
You don't enable the service, you just enable the timer and leave the service 'disabled'.

You can manually run the service though if you want to test it using the start command.


Ryzen 7 9850X3D | AMD 7800XT | KDE Plasma

Online

#12 2025-05-09 15:15:46

Blablabla3012
Member
Registered: 2025-05-08
Posts: 5

Re: Help with .timer and .service files

got my answere. thanks for the help

Offline

Board footer

Powered by FluxBB