You are not logged in.

#1 2015-02-07 20:17:24

mamr
Member
Registered: 2008-08-16
Posts: 63

[SOLVED] How to enable systemd's *.timer files for a user?

I want to run offlineimap periodically to backup my emails.

I've written two files. One offlineimap.service which looks like this:

[Unit]
Description=Run offlineimap (used in conjunction with a timer file)

[Service]
Type=simple
ExecStart=/usr/bin/offlineimap
User=archie

And an offlineimap.timer file which looks like this:

[Unit]
Description=Run offlineimap 15 minutes after boot and daily

[Timer]
# Time to wait after booting before offlineimap.service is run for the first time
OnBootSec=15min
# Time between running each consecutive time
OnUnitActiveSec=1d
Unit=offlineimap.service

[Install]
WantedBy=timers.target

I want to run the service as the user "archie". So I copied both files to /etc/systemd/system/ and tried to activate the offlineimap.timer file like so:

sudo systemctl --user enable offlineimap.timer

But I get this error message:

Failed to get D-Bus connection: Connection refused

Without the sudo I get this error message:

Failed to execute operation: No such file or directory

What am I doing wrong? (I know it works, because it has worked before on another computer.)

Last edited by mamr (2015-03-31 07:07:50)

Offline

#2 2015-02-07 21:31:01

Spider.007
Member
Registered: 2004-06-20
Posts: 1,175

Re: [SOLVED] How to enable systemd's *.timer files for a user?

Systemctl doesn't work combined with sudo (see https://bbs.archlinux.org/viewtopic.php?id=186568 ). Also; you can use systemd as a user without sudo. However, the service&timer should be put in your homedir. This is all described in https://wiki.archlinux.org/index.php/Systemd/User You also shouldn't forget to daemon-reload after moving services around

Last edited by Spider.007 (2015-02-07 21:31:44)

Offline

#3 2015-02-07 22:02:57

rumpelsepp
Member
From: Bavaria
Registered: 2012-11-13
Posts: 105
Website

Re: [SOLVED] How to enable systemd's *.timer files for a user?

You have to put the file into one of the "user" directories of systemd (table 2): http://www.freedesktop.org/software/sys … oad%20Path
I also have written a blogpost for this. Maybe it helps: https://sevenbyte.org/2014/11/15/cron-j … emd-timer/

Last edited by rumpelsepp (2015-02-07 22:03:16)


Every time I see some piece of medical research saying that caffeine is good for you, I high-five myself. Because I'm going to live forever. -- Torvalds, Linus (2010-08-03).

Offline

#4 2015-02-07 23:15:45

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED] How to enable systemd's *.timer files for a user?

1. Don't use sudo with --user
2. Put user units in '$HOME/.config/systemd/user'
3. If 'systemctl --user enable <user timer or unit name>' doesn't work then:
4. Symlink <path_to_timer> into '$HOME/.config/systemd/user/default.target.wants/<name_of_timer>'
5. Then 'systemctl --user daemon-reload'

Scott

Offline

#5 2015-02-08 14:03:57

mamr
Member
Registered: 2008-08-16
Posts: 63

Re: [SOLVED] How to enable systemd's *.timer files for a user?

Thanks. It does work now. I moved both files into ~/.config/systemd/user/ and activated the timer unit with 'systemctl --user enable offlineimap.timer'. After a daemon restart everything works like a charm.

Offline

#6 2015-02-08 14:14:49

mamr
Member
Registered: 2008-08-16
Posts: 63

Re: [SOLVED] How to enable systemd's *.timer files for a user?

I still got a problem: It looks like the timer gets activated and works but somehow new mails don't get fetched by 'offlineimap'. When I try 'offlineimap' on the terminal myself it fetches new mail. Is there some kind of log which records what the service unit does, when it get's triggered? (I did look into 'journalctl' but didn't see anything related to my problem. How can I test, if everything is working?

Offline

#7 2015-02-08 14:37:18

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED] How to enable systemd's *.timer files for a user?

Try

 journalctl --user-unit offlineimap.service

Offline

#8 2015-03-05 06:10:43

mamr
Member
Registered: 2008-08-16
Posts: 63

Re: [SOLVED] How to enable systemd's *.timer files for a user?

This brings me:

...
Mar 01 09:58:47 mobiletux systemd[391]: Starting Run offlineimap (used in conjunction with a timer file)...
Mar 01 09:58:47 mobiletux systemd[391]: Started Run offlineimap (used in conjunction with a timer file).
Mar 01 09:58:47 mobiletux systemd[1357]: Failed at step GROUP spawning /usr/bin/offlineimap: Operation not permitted
Mar 01 09:58:47 mobiletux systemd[391]: offlineimap.service: main process exited, code=exited, status=216/GROUP
Mar 01 09:58:47 mobiletux systemd[391]: Unit offlineimap.service entered failed state.
Mar 01 09:58:47 mobiletux systemd[391]: offlineimap.service failed.
-- Reboot --
Mar 02 19:29:11 mobiletux systemd[435]: Starting Run offlineimap (used in conjunction with a timer file)...
Mar 02 19:29:11 mobiletux systemd[435]: Started Run offlineimap (used in conjunction with a timer file).
Mar 02 19:29:11 mobiletux systemd[2421]: Failed at step GROUP spawning /usr/bin/offlineimap: Operation not permitted
Mar 02 19:29:11 mobiletux systemd[435]: offlineimap.service: main process exited, code=exited, status=216/GROUP
Mar 02 19:29:11 mobiletux systemd[435]: Unit offlineimap.service entered failed state.
Mar 02 19:29:11 mobiletux systemd[435]: offlineimap.service failed.
-- Reboot --
Mar 03 07:18:19 mobiletux systemd[393]: Starting Run offlineimap (used in conjunction with a timer file)...
Mar 03 07:18:19 mobiletux systemd[393]: Started Run offlineimap (used in conjunction with a timer file).
Mar 03 07:18:19 mobiletux systemd[393]: offlineimap.service: main process exited, code=exited, status=216/GROUP
Mar 03 07:18:19 mobiletux systemd[393]: Unit offlineimap.service entered failed state.
Mar 03 07:18:19 mobiletux systemd[393]: offlineimap.service failed.
-- Reboot --
Mar 03 20:31:45 mobiletux systemd[383]: Starting Run offlineimap (used in conjunction with a timer file)...
Mar 03 20:31:45 mobiletux systemd[383]: Started Run offlineimap (used in conjunction with a timer file).
Mar 03 20:31:45 mobiletux systemd[383]: offlineimap.service: main process exited, code=exited, status=216/GROUP
Mar 03 20:31:45 mobiletux systemd[383]: Unit offlineimap.service entered failed state.
Mar 03 20:31:45 mobiletux systemd[383]: offlineimap.service failed.
-- Reboot --
Mar 04 05:43:14 mobiletux systemd[447]: Starting Run offlineimap (used in conjunction with a timer file)...
Mar 04 05:43:14 mobiletux systemd[447]: Started Run offlineimap (used in conjunction with a timer file).
Mar 04 05:43:14 mobiletux systemd[447]: offlineimap.service: main process exited, code=exited, status=216/GROUP
Mar 04 05:43:14 mobiletux systemd[447]: Unit offlineimap.service entered failed state.
Mar 04 05:43:14 mobiletux systemd[447]: offlineimap.service failed.
-- Reboot --
Mar 04 06:16:10 mobiletux systemd[419]: Starting Run offlineimap (used in conjunction with a timer file)...
Mar 04 06:16:10 mobiletux systemd[419]: Started Run offlineimap (used in conjunction with a timer file).
Mar 04 06:16:10 mobiletux systemd[1013]: Failed at step GROUP spawning /usr/bin/offlineimap: Operation not permitted
Mar 04 06:16:10 mobiletux systemd[419]: offlineimap.service: main process exited, code=exited, status=216/GROUP
Mar 04 06:16:10 mobiletux systemd[419]: Unit offlineimap.service entered failed state.
Mar 04 06:16:10 mobiletux systemd[419]: offlineimap.service failed.

Looks like the user doesn't have the permission to run offlineimap? When I try this command from the terminal (as a user) it does work. What should I do now?

Offline

#9 2015-03-05 06:26:50

nullified
Member
From: Massachusetts, USA
Registered: 2013-12-09
Posts: 468

Re: [SOLVED] How to enable systemd's *.timer files for a user?

what is the output of

groups

when run as user 'archie'? and what is output of

ls -l /usr/bin/offlineimap

Last edited by nullified (2015-03-05 06:32:18)


"We may say most aptly, that the Analytical Engine weaves algebraical patterns just as the Jacquard-loom weaves flowers and leaves." - Ada Lovelace

Offline

#10 2015-03-05 08:35:57

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

Re: [SOLVED] How to enable systemd's *.timer files for a user?

Did you forget to remove User=archie when you went from system to user service?

Offline

#11 2015-03-31 07:07:23

mamr
Member
Registered: 2008-08-16
Posts: 63

Re: [SOLVED] How to enable systemd's *.timer files for a user?

Raynman wrote:

Did you forget to remove User=archie when you went from system to user service?

That was the problem. It does work now. Thanks!

Offline

Board footer

Powered by FluxBB