You are not logged in.

#1 2014-06-25 20:48:24

fede
Member
Registered: 2007-06-29
Posts: 126

[SOLVED] systemd/cron as user: timer doesn't start after boot

Hello,

I've tried to follow the wiki's systemd/cron functionality article to have a systemd service to run hourly.
Everything seems to be working ok, except that the hourly timer doesn't start automatically : I have to issue a

systemctl --user timer-hourly.timer start

command every time I start the machine to get the timer running.
Can you help me understand what I'm missing to get the (user) timer to start automatically after boot?

Thanks!

---------------------------------------------------
My setup consists of the following files:
/home/myuser/.config/systemd/user:

drwxr-xr-x 2 myuser users 4096 Jun 25 17:30 basic.target.wants/
-rw-r--r-- 1 myuser users  217 Jun 25 10:08 db_backup.service
-rw-r--r-- 1 myuser users  232 Jun 25 10:08 test.service
-rw-r--r-- 1 myuser users   61 Jun 19 12:14 timer-hourly.target
drwxr-xr-x 2 myuser users 4096 Jun 25 10:10 timer-hourly.target.wants/
-rw-r--r-- 1 myuser users  134 Jun 19 12:14 timer-hourly.timer

/home/myuser/.config/systemd/user/basic.target.wants/:

lrwxrwxrwx 1 myuser users 50 Jun 25 10:08 timer-hourly.timer -> /home/myuser/.config/systemd/user/timer-hourly.timer

/home/myuser/.config/systemd/user/timer-hourly.target.wants/:

lrwxrwxrwx 1 myuser users 49 Jun 13 15:51 db_backup.service -> /home/myuser/.config/systemd/user/db_backup.service
lrwxrwxrwx 1 myuser users 44 Jun 25 10:10 test.service -> /home/myuser/.config/systemd/user/test.service

timer-hourly.timer:

[Unit]
Description=Hourly Timer

[Timer]
OnBootSec=5min
OnCalendar=hourly
Unit=timer-hourly.target

[Install]
WantedBy=basic.target

timer-hourly.target:

[Unit]
Description=Hourly Timer Target
StopWhenUnneeded=yes

test.service:

[Unit]
Description=Run a test (echo) job every hour
Wants=timer-hourly.timer

[Service]
Nice=19
IOSchedulingClass=2
IOSchedulingPriority=7
ExecStart=/usr/bin/python /home/myuser/test_service.py

[Install]
WantedBy=timer-hourly.target

db_backup.service:

[Unit]
Description=Backups databases
Wants=timer-hourly.timer

[Service]
Nice=19
IOSchedulingClass=2
IOSchedulingPriority=7
ExecStart=/home/myuser/source/db_backups/db_backup.sh

[Install]
WantedBy=timer-hourly.target

test_service.py is a simple python script that appends the current time to a file, to check if the service is being run by the timer. (it is after I start the timer after boot, and runs correctly every hour)
db_backup.sh is a script that dumps a database into a text file in a mercurial repository, commits the change and pushes it to backup locations.

Last edited by fede (2014-06-25 21:06:09)

Offline

#2 2014-06-25 21:00:14

ids1024
Member
From: California
Registered: 2013-08-16
Posts: 243
Website

Re: [SOLVED] systemd/cron as user: timer doesn't start after boot

Have you tried this:

systemctl --user enable timer-hourly.timer

"Only wimps use tape backup: _real_ men just upload their important stuff on ftp, and let the rest of the world mirror it."—Linus Torvalds
s/ftp/git/

https://iandouglasscott.com | https://github.org/ids1024 | https://keybase.io/ids1024

Offline

#3 2014-06-25 21:05:43

fede
Member
Registered: 2007-06-29
Posts: 126

Re: [SOLVED] systemd/cron as user: timer doesn't start after boot

That's it!

Thanks a lot!

Offline

Board footer

Powered by FluxBB