You are not logged in.

#1 2015-07-10 13:58:22

StonedAstronaut
Member
Registered: 2015-07-10
Posts: 4

[SOLVED]systemd user timer after reboot start and stop after 1 minute.

Hi everybody.
I creted in $HOME/.config/systemd/user/ 3 files:

  1. my_timer.timer

  2. my_timer.service

  3. backup_script.sh


code my_timer.timer:

[Unit]
Description=Run every day for backup some folders to cloud
After=timer-sync.target

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timer.target

code my_timer.service:

[Unit]
Description=service for timer

[Service]
Type=simple
ExecStart=/home/user/.config/systemd/user/backup_script.sh

Code of backup_script.sh does not matter.

Then I did:

$ systemctl --user daemon-reload
$ systemctl --user enable my_timer.timer
$ systemctl --user start my_timer.timer

After this manipulation all is Ok. My timer appeared in the:

$ systemctl --user timers-list

But after reboot I checked timers-list and did not find there my timer. After I checked status of timer and service:

$ systemctl --user status my_timer.timer
 my_timer.timer - Run every day for backup some folders to cloud
   Loaded: loaded (/home/user/.config/systemd/user/my_timer.timer; enabled; vendor preset: enabled)
   Active: inactive (dead)

$ systemctl --user status my_timer.service
 my_timer.service - service for timer
   Loaded: loaded (/home/user/.config/systemd/user/my_timer.service; static; vendor preset: enabled)
   Active: inactive (dead)

Then I checked log for timer:

$ journalctl --user-unit my_timer.timer
...
jul 10 18:03:02 comp systemd[580]: Started Run every day for backup some folders to cloud.
jul 10 18:03:02 comp systemd[580]: Starting Run every day for backup some folders to cloud.
jul 10 18:04:11 comp systemd[580]: Stopped Run every day for backup some folders to cloud.
jul 10 18:04:11 comp systemd[580]: Stopping Run every day for backup some folders to cloud.

I do not understant it. Why systemd start my timer, then stop it after 1 minute? WAIDW?

Last edited by StonedAstronaut (2015-07-11 07:49:36)

Offline

#2 2015-07-10 21:33:15

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,304

Re: [SOLVED]systemd user timer after reboot start and stop after 1 minute.

Try:

[Unit]
Description=Run every day for backup some folders to cloud
#After=time-sync.target

[Timer]
OnCalendar=daily
Persistent=true

#[Install]
#WantedBy=timers.target

Last edited by berbae (2015-07-10 21:33:48)

Offline

#3 2015-07-11 01:15:49

Buddlespit
Member
From: Chesapeake, Va.
Registered: 2014-02-07
Posts: 501

Re: [SOLVED]systemd user timer after reboot start and stop after 1 minute.

berbae wrote:

Try:

[Unit]
Description=Run every day for backup some folders to cloud
#After=time-sync.target

[Timer]
OnCalendar=daily
Persistent=true

#[Install]
#WantedBy=timers.target

If you remove the [Install], the timer will not load on reboot. I don't use timers.target, I use default.target and I've:

# loginctl enable-linger username

edit: but after googling a bit, I think I'll change my [Install] to WantedBy=timers.target

Last edited by Buddlespit (2015-07-11 01:19:00)

Offline

#4 2015-07-11 06:25:44

StonedAstronaut
Member
Registered: 2015-07-10
Posts: 4

Re: [SOLVED]systemd user timer after reboot start and stop after 1 minute.

berbae wrote:

Try:

[Unit]
Description=Run every day for backup some folders to cloud
#After=time-sync.target

[Timer]
OnCalendar=daily
Persistent=true

#[Install]
#WantedBy=timers.target

Hi. Thank you for answer.
Directive After= is recommend by systemd man.

...
Timer units with at least one OnCalendar= directive will have an additional After= dependency on timer-sync.target to avoid being started before the system clock has been correctly set.
...

WantedBy=timers.target I took from archwiki.

Last edited by StonedAstronaut (2015-07-11 06:28:40)

Offline

#5 2015-07-11 06:42:03

StonedAstronaut
Member
Registered: 2015-07-10
Posts: 4

Re: [SOLVED]systemd user timer after reboot start and stop after 1 minute.

Buddlespit wrote:
# loginctl enable-linger username

I tried this command. But it has no effect. After reboot I check:

$ systemctl --user list-timers
0 timers listed.
Pass --all to see loaded but inactive timers, too.

$ systemctl --user status my_timer.timer 
● my_timer.timer - Run every day for backup some folders to cloud                                                                     
   Loaded: loaded (/home/user/.config/systemd/user/my_timer.timer; enabled; vendor preset: enabled)                                         
   Active: inactive (dead)   

Maybe is it a bug in systemd? I will check the same configuration on another distro with systemd.

Last edited by StonedAstronaut (2015-07-11 06:45:19)

Offline

#6 2015-07-11 07:06:02

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED]systemd user timer after reboot start and stop after 1 minute.

StonedAstronaut wrote:

Directive After= is recommend by systemd man.

...
Timer units with at least one OnCalendar= directive will have an additional After= dependency on timer-sync.target to avoid being started before the system clock has been correctly set.
...

It says that dependency is implicit when you have at least one OnCalendar directive, so you don't have to add it yourself.

WantedBy=timers.target I took from archwiki.

Yes, that's good, but you had a typo: timer.target without the 's'. I don't expect that to be the cause of this (I don't know what it could be), but make sure to check it anyway.

Offline

#7 2015-07-11 07:48:46

StonedAstronaut
Member
Registered: 2015-07-10
Posts: 4

Re: [SOLVED]systemd user timer after reboot start and stop after 1 minute.

Raynman wrote:

...
Yes, that's good, but you had a typo: timer.target without the 's'. I don't expect that to be the cause of this (I don't know what it could be), but make sure to check it anyway.

Yes you are right. This is typo. I have to be careful in next time.
Thanks for all. This "problem" is solved.

PS: Maybe systemd must log such errors?

Offline

Board footer

Powered by FluxBB