You are not logged in.

#1 2014-09-03 13:39:54

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

Cron-jobs cannot use systemctl --user "Failed to get D-Bus connection"

I use https://wiki.archlinux.org/index.php/Systemd/User which works fine; but I also have a cronjob which should restart a certain (user) service. This doesn't work; the cronjob says:

Failed to get D-Bus connection: Connection refused

I have the same issue when su-ing to the user, which is why I have a suspicion this is related to https://bugzilla.redhat.com/show_bug.cgi?id=753882.

Does anyone here have this working; or possible solution?

Okay I found a workaround:

[[ -z $XDG_RUNTIME_DIR ]] && export XDG_RUNTIME_DIR=/run/user/$UID

Last edited by Spider.007 (2014-09-05 08:51:26)

Offline

#2 2014-09-17 10:49:36

vendion
Member
From: Tennessee, USA
Registered: 2010-03-10
Posts: 204
Website

Re: Cron-jobs cannot use systemctl --user "Failed to get D-Bus connection"

I am having the same problem, but it affects all user services, even running "systemctl --user status" fails because it can not connect to D-Bus.  Your workaround went in you're shells configuration file I assume (bashrc, zshrc, etc)?

Offline

#3 2014-12-19 13:32:15

Karamazov
Member
From: Rennes, France
Registered: 2014-12-19
Posts: 2

Re: Cron-jobs cannot use systemctl --user "Failed to get D-Bus connection"

Spider.007 wrote:

Okay I found a workaround:

[[ -z $XDG_RUNTIME_DIR ]] && export XDG_RUNTIME_DIR=/run/user/$UID

Thanks a lot smile

In my case, I did this :

  1. First, I edit the sudo's configuration file, with the visudo command.

  2. And finally :

    # This is the UID of the user "pikachu" :
    PIKACHU_UID=1008
    
    sudo -u pikachu -H XDG_RUNTIME_DIR=/run/user/$PIKACHU_UID systemctl --user start something.service

Sorry ! My English is not perfect wink

Offline

#4 2014-12-19 16:35:13

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

Re: Cron-jobs cannot use systemctl --user "Failed to get D-Bus connection"

but I also have a cronjob which should restart a certain (user) service

You could use a timer instead: https://wiki.archlinux.org/index.php/Systemd/Timers

[Unit]
Description=Do something daily

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timer.target
[Unit]
Description=Restart service

[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl try-restart my_program.service

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

#5 2014-12-19 17:58:30

intelfx
Member
From: Russia, Moscow
Registered: 2013-08-21
Posts: 13

Re: Cron-jobs cannot use systemctl --user "Failed to get D-Bus connection"

Setting XDG_RUNTIME_DIR and using sudo is hackish... Have you tried using either systemd user instance's timers or per-user cron tables?

Offline

#6 2014-12-20 12:05:17

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

Re: Cron-jobs cannot use systemctl --user "Failed to get D-Bus connection"

rumpelsepp wrote:

but I also have a cronjob which should restart a certain (user) service

You could use a timer instead: https://wiki.archlinux.org/index.php/Systemd/Timers

[...]

Thanks; that's a good suggestion. Unfortunately for me it doesn't work; the restart is part of a bigger script that should be performed after certain updates are completed

intelfx wrote:

Setting XDG_RUNTIME_DIR and using sudo is hackish... Have you tried using either systemd user instance's timers or per-user cron tables?

The whole point is systemd-user instances can only be controlled by logged in users. Not by cron-jobs that run under that users credentials....

Offline

#7 2014-12-20 13:04:46

Karamazov
Member
From: Rennes, France
Registered: 2014-12-19
Posts: 2

Re: Cron-jobs cannot use systemctl --user "Failed to get D-Bus connection"

intelfx wrote:

Have you tried using either systemd user instance's timers or per-user cron tables?

Spider.007 needs timers or cronjobs, not me smile


intelfx wrote:

Setting XDG_RUNTIME_DIR and using sudo is hackish.


My problem is : how does user_B to stop, reload, mask, enable … an unit which is launched by the user_A's systemd instance ?

For example : the wiki talks about a user version of the mpd service, which is launched by the systemd instance of the user "mpd". How does the user "intelfx" to stop, reload, mask, enable … this unit ?

Using sudo and XDG_RUNTIME_DIR seems to work. Does an other solution exist ?


Sorry ! My English is not perfect wink

Offline

#8 2014-12-20 13:19:51

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: Cron-jobs cannot use systemctl --user "Failed to get D-Bus connection"

Karamazov wrote:
intelfx wrote:

Have you tried using either systemd user instance's timers or per-user cron tables?

Spider.007 needs timers or cronjobs, not me smile


intelfx wrote:

Setting XDG_RUNTIME_DIR and using sudo is hackish.


My problem is : how does user_B to stop, reload, mask, enable … an unit which is launched by the user_A's systemd instance ?

For example : the wiki talks about a user version of the mpd service, which is launched by the systemd instance of the user "mpd". How does the user "intelfx" to stop, reload, mask, enable … this unit ?

Using sudo and XDG_RUNTIME_DIR seems to work. Does an other solution exist ?

Please start your own thread. Forum Etiquette: Thread Hijacking. Thanks.


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

Board footer

Powered by FluxBB