You are not logged in.

#26 2020-01-21 19:31:27

walteweiss
Member
Registered: 2019-09-07
Posts: 32

Re: [SOLVED] .timer and .service

Just a quick reply to my questions:

1.

Should I mark those two — .service and .timer — files as executables or not?

No, you shouldn't. It's not written in the wiki. You can check your .timer and .service files with

systemd-analyze verify ~/.config/systemd/user/daily.service

(as far as I got it, it checks both files).

Use the calendar command of systemd-analyze(1) to validate and normalize calendar time specifications for testing purposes. The tool also calculates when a specified calendar event would elapse next.

— the very end of man systemd.time(7)

To check whether your timer is present, you can use

systemctl --user list-timers

, which is (again) not in the wiki, it is not specified you need to make

--user

. Maybe when you have enough understanding it'll be obvious, I don't know, but it wasn't for me.


2. Also, I was confused whether the timer works or not, and I didn't know how to check it further than analyze it. I thought

systemctl --user start daily.timer

will trigger it at least once, but seems like it waits for the midnight, even though

Persistent=true

.

3.

mkdir $(date +"%m-%d-%a")

This command didn't work for me, I used it this way:

[Service]
Type=oneshot
ExecStart=/bin/sh -c  'mkdir $(date +"%m-%d-%a")'

I tried it with double quote marks as well, no difference for me. I put this into a .sh file, which I run like this:

[Service]
ExecStart=/path/to/the/file.sh

Also, I don't understand whether I need to specify Type= at all, or not. I didn't understand the difference between simple, exec and oneshot. May try to give it a re-read one day later. At this point I'm trying to do my .service file without Type=

***

Those links may be useful for someone, who will read Arch Wiki, and will have more questions, finding this thread:

- man systemd.time(7)
- man systemd.service(5)
- Gentoo Wiki on Systemd Timers
- systemd.unit — Unit configuration

P.S. Didn't expect the forum formatting being so uncomfortable to use! I assume it has no in-line code tag.

Last edited by walteweiss (2020-01-22 10:48:48)


Russia is committing genocide on Ukraine right now (2022—2023), please help Ukraine as much as you can. That’s the turning point of the democracy vs tyranny war, and if Ukraine loses, everyone in the democracy world will. You can donate to Ukraine here: savelife.in.ua/en/donate or help with spreading the information about the ongoing events.

Offline

#27 2020-01-23 17:52:10

walteweiss
Member
Registered: 2019-09-07
Posts: 32

Re: [SOLVED] .timer and .service

One last add from me, I think. My daily timer works, but today it wasn’t triggered at the midnight, but at the time I tried to check why it wasn’t by doing

systemctl --user list-timers
NEXT                         LEFT     LAST                         PASSED  UNIT          >
Fri 2020-01-24 00:00:00 EET  16h left Thu 2020-01-23 07:58:01 EET  23s ago notes_daily.ti>

I have no idea why that happened. Anyone has any ideas?

My files, just in case.

daily.service

[Unit]
Description=Add Day Directory

[Service]
WorkingDirectory=/home/walter/
ExecStart=/home/walter/.scripts/daily.sh

daily.timer

[Unit]
Description=Add Day Directory

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

Russia is committing genocide on Ukraine right now (2022—2023), please help Ukraine as much as you can. That’s the turning point of the democracy vs tyranny war, and if Ukraine loses, everyone in the democracy world will. You can donate to Ukraine here: savelife.in.ua/en/donate or help with spreading the information about the ongoing events.

Offline

Board footer

Powered by FluxBB