You are not logged in.

#1 2016-03-10 16:21:39

barefly
Member
Registered: 2014-08-16
Posts: 59

[SOLVED] User timer in systemd not persistent on boot?

I made a simple timer and service file to backup my home folder at certain times throughout the day. I noticed today though that when I run systemctl --user list-timers the timer is not listed. When I last checked the timer yesterday, after enabling and starting the .timer and .service files, they were showing as running. I went ahead and re-enabled and re-started both files again today, and rebooted just to see if I could recreate the issue, and sure enough it showed enabled before reboot, and after reboot it's not enabled. The .service file is showing up in default.target.wants/ and the timer file is showing up as a stamp file in the timers/ directory as well. Do user timers do not persist after boot? Or is there something I am missing when setting up my timer?

Here is list-timers showing the timer as enabled.

NEXT                         LEFT       LAST                         PASSED  UNIT                     ACTIVATES
Thu 2016-03-10 10:00:00 MST  45min left Wed 2016-03-09 11:05:33 MST  22h ago backup-laptop-home.timer backup-laptop-home.service

1 timers listed.
Pass --all to see loaded but inactive timers, too.

The timer file.

[Unit]
Description=Backup Laptop Home Daily Timer 10:00

[Timer]
OnCalendar=10:00
Persistent=True

The service file.

[Unit]
Description=Backup Laptop Home Daily

[Service]
Type=simple
ExecStart=$HOME/scripts/backup-laptop.home.sh

[Install]
WantedBy=default.target

EDIT:

Well scratch that it looks like my timer is working but I am a bit unclear on just what is going on. It ran at boot during my last restart, and my script did generate a proper backup. But systemctl --user is showing that the .service file failed, which may be due to the service file only being initiated by the timer, and systemctl --user list-timers is still not showing the timer. systemctl --user also does not show the the timer enabled. This is getting confusing now.

EDIT 2:

Ok I'm pretty sure I figured out the issue, and that was just that I was missing the [Install] section in my .timer file. I added WantedBy=default.target, then re-enabled and a sym link was created. I confirmed it was running in list-timers then rebooted and checked again, and sure enough it was running on boot.

EDIT 3:
Just wanted to add that it wasn't necessary to enable the service file. The timer file enabled alone seems to take care of it.

Last edited by barefly (2016-03-10 18:22:20)

Offline

#2 2016-03-10 16:24:54

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,552

Re: [SOLVED] User timer in systemd not persistent on boot?

I have no idea what effect enabling the service file would have on a timer. Why would you do that?

Online

#3 2016-03-10 16:29:36

barefly
Member
Registered: 2014-08-16
Posts: 59

Re: [SOLVED] User timer in systemd not persistent on boot?

Scimmia wrote:

I have no idea what effect enabling the service file would have on a timer. Why would you do that?

Really just covering my bases. I'm pretty new to systemd and I'm trying to get used to using it. I've seen conflicting information online on enabling the service file, and in other places not having to.

Offline

#4 2016-03-10 19:18:22

branch
Member
Registered: 2014-03-16
Posts: 209

Re: [SOLVED] User timer in systemd not persistent on boot?

Surely the .service should be "Type=oneshot" not simple right? Simple services are supposed to be persistent which does not make much sense for something triggered by a timer.

Is your --user session set to Linger? You can check with

loginctl show-user -p Linger $USER

If not then your timer will only be active when you are logged on.

Offline

#5 2016-03-10 20:46:50

barefly
Member
Registered: 2014-08-16
Posts: 59

Re: [SOLVED] User timer in systemd not persistent on boot?

branch wrote:

Surely the .service should be "Type=oneshot" not simple right? Simple services are supposed to be persistent which does not make much sense for something triggered by a timer.

Is your --user session set to Linger? You can check with

loginctl show-user -p Linger $USER

If not then your timer will only be active when you are logged on.

From what I can tell, on the man page at least, the only difference between simple and oneshot is that when a process is set to oneshot systemd waits until the process is completed before continuing on with another. My knowledge with systemd is limited though so there might be something I do not understand, but for the most part my timer(s) are now working as they should.

And my user session is set to Linger=no.

Offline

Board footer

Powered by FluxBB