How do I set up systemd service with systemd timer?

I already set up a system timer that trigger a systemd service. I use only debian-13 for template. So I put 2 systemd files at /etc/systemd/system/ folder inside debian-13. Systemd service run a bash script. Systemd timer use OnCalendar=--* that runs at specific times.

Those 3 files I used only one AppVM. It works perfect with one problem. Persistent=true inside timer not save to hard disk then when I reboot qubes or AppVm systemd service run again.

How do I solve that?

systemd timer

[Unit]
Description=

[Timer]
OnCalendar=--* 07:00:00
OnCalendar=--* 14:00:00
OnCalendar=--* 21:00:00
OnCalendar=Sat,Sun 18:00
RandomizedDelaySec=10m
Persistent=true
Unit=backup_untrusted.service

[Install]
WantedBy=timers.target

Systemd service

[Unit]
Description=Backup bookmarks from librewolf software

[Service]
User=user
Group=user
Type=oneshot
RemainAfterExit=yes
StartLimitBurst=2
StartLimitInterval=50
ExecStart=/usr/local/bin/backup_untrusted.sh
Restart=on-failure
#StandardOutput=null
StandardError=journal
Environment=“DISPLAY=:0”

I don’t follow.
persistent=true means that you want missed timer events to be run as soon as the system is running again.

I suppose the persistent timer feature can’t work because the state file is certainly outside the persistent storage of the AppVM.

As a workaround and given the frequency, this could be started from /rw/config/rc.local at every qube start.

@barto yes. but run again and again. I want to run ONLY the time oncalendar. If timer events to be run as soon as the system is running again but only ONCE .

The problem is that run again and again.

@solene

Would you like to be more analytic? I have 3 files. Bash script and 2 systemd files (service and timer) Where to put 2 systemdd files ???

Do you want the systemd files to be in the template and used by multiple qubes, or in the $HOME directory of the qube that need the systemd units?

@solene

I want to be in template and used by multiple qubes

You can put your systemd units in /etc/systemd/system/ and enable the timer only with

sudo systemctl enable my-unit.timer

When you start a qube using this template, the timer should be running, you can check with sudo systemctl status my-unit.timer

@solene

Are you kidding me? First of all THANK YOU. It is the second question that you don’t read . I said in my firrst question that I put the same folder that I have the problem.

Rude.
If you take time to read what was written in this thread, you will understand why do you have the problem you have. A problem which you should have taken time to properly explain in the first post, instead of being rude later. We are not in your head. Bye.

1 Like

@barto

I am not english speaker so I wrote wrong. I am sorry. I say again.

system timer runs specific times as see in my first post. When I reboot my machine or sometimes reboot Appvm runs again and again.

I want run ONLY specific times.

Would you like to help me?

Try creating the .timer and .service files as user units (in /etc/systemd/user/ in the TemplateVM), and run sudo systemctl --user --global enable your.timer (also in the TemplateVM).

The timestamp state files for user timers are saved in ~/.local/share/systemd/timers/ on the AppVM’s ‘private’ volume, so they’ll survive a reboot of the AppVM.

2 Likes

@rustybird

I put the directory you said. When I try to enable then I show the error message.
Failed to enable unit: Unit /etc/systemd/user/timers.target.wants/backup_untrusted.timer does not exist

If you ran

systemctl --user --global enable /etc/systemd/user/timers.target.wants/backup_untrusted.timer

it should be this instead:

systemctl --user --global enable backup_untrusted.timer

Edit:

Please keep language professional and as you would have others talk to you. I note from your other replies that English is not your first language, so just to make you aware that your reply does come over as rude and confrontational. People here are a community who are helping voluntarily, please bear in mind how you reply to those giving their time to you by trying to help you

4 Likes

@rustybird

It doesn’t work. I made the changes on debian-13 right?

@rustybird

I create manually the dir timers.target.wants. Then I sucessfully enable the timer.

Now I go to AppVM but if write ‘systemctl list-timers’ I the timer is not appear.

Try systemctl --user list-timers

It’s also journalctl --user BTW, in case you need to look at the logs.

Apparently it needs to be sudo systemctl --user --global enable your.timer if the directory doesn’t already exist.

@rustybird

Thank you for help. Where to put bash script? Now I have problem with below message.

backup_untrusted.service: Failed at step GROUP spawning /usr/local/bin/backup_untrusted.sh: Operation not permitt>

It’s saying that the systemd service failed to change the group to user before running the script.

You can probably remove the lines

User=user
Group=user

from the service. It’s a user unit, so it should already run as user user, group user by default.