You are not logged in.

#1 2015-03-23 18:46:50

nopemopes
Member
Registered: 2015-03-23
Posts: 12

[Solved] Systemd user service and timer dbus error

I have installed arch recently and added a few of my own services, for example the acpi_call commands and such. Now I want to create a systemd service that runs every 5 minutes and execute a script.

I searched a lot and I found that I must use timers. I got the thing with the timers working, but because my script has to do with a specific user, I want it to run only every 5 minutes when i am logged in as that user.

I tried to put the files in /etc/systemd/users, .config/local/users and all the possibilities but everytime i want to enable it, it says dbus connection refused.

Can somebody please provide me a way to execute a systemd service every 5 minutes while I am logged in as a specific user?

I did follow the wiki and created a dbus service and all. Everything works on that side but i can't enable my user service.

thanks!

Last edited by nopemopes (2015-03-25 11:10:06)

Offline

#2 2015-03-23 19:46:36

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [Solved] Systemd user service and timer dbus error

What errors are you getting? https://bbs.archlinux.org/viewtopic.php?id=57855


Not a Sysadmin issue, moving to NC...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2015-03-23 19:55:14

nopemopes
Member
Registered: 2015-03-23
Posts: 12

Re: [Solved] Systemd user service and timer dbus error

jasonwryan wrote:

What errors are you getting? https://bbs.archlinux.org/viewtopic.php?id=57855


Not a Sysadmin issue, moving to NC...


sorry, didn't mean to be incomplete.

The error says "Failed to get D-Bus connection: Connection refused".

I did what the wiki said: Create the dbus files, enable them and such.

No i put my service files + timer in the places mentioned by the wiki but everytime i try to enable them, that error shows up.

systemctl status dbus gives me all good

dbus.service - D-Bus System Message Bus
   Loaded: loaded (/usr/lib/systemd/system/dbus.service; static; vendor preset: disabled)
   Active: active (running) since ma 2015-03-23 19:39:24 CET; 1h 18min ago
     Docs: man:dbus-daemon(1)
 Main PID: 246 (dbus-daemon)
   CGroup: /system.slice/dbus.service
           └─246 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation

mrt 23 19:39:34 Jordy-Laptop dbus[246]: [system] Activating via systemd: service name='org.freedesktop.ModemManager1' unit='...ervice'
mrt 23 19:39:34 Jordy-Laptop dbus[246]: [system] Activation via systemd failed for unit 'dbus-org.freedesktop.ModemManager1....ectory.
mrt 23 19:39:34 Jordy-Laptop dbus[246]: [system] Activating via systemd: service name='org.freedesktop.ModemManager1' unit='...ervice'
mrt 23 19:39:34 Jordy-Laptop dbus[246]: [system] Activation via systemd failed for unit 'dbus-org.freedesktop.ModemManager1....ectory.
mrt 23 19:39:39 Jordy-Laptop dbus[246]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='...ervice'
mrt 23 19:39:39 Jordy-Laptop dbus[246]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
mrt 23 19:47:01 Jordy-Laptop dbus[246]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='...ervice'
mrt 23 19:47:01 Jordy-Laptop dbus[246]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
mrt 23 20:51:38 Jordy-Laptop dbus[246]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='...ervice'
mrt 23 20:51:38 Jordy-Laptop dbus[246]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'

that's the log for dbus and these are my files:

drive_sync.service

[Unit]
Description=Drive sync

[Service]
Type=simple
ExecStart=drive_script.sh

drive_sync.timer

[Unit]
Description=Drive sync

[Service]
Type=simple
ExecStart=drive_script.sh

these files are located in ~/.config/systemd/user

Last edited by nopemopes (2015-03-23 20:00:55)

Offline

#4 2015-03-23 20:04:35

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [Solved] Systemd user service and timer dbus error

Have you followed these steps to the letter? https://wiki.archlinux.org/index.php/Systemd/User#D-Bus

Because it doesn't look like it to me... Is the environment variable set? And the socket activated?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2015-03-23 20:06:26

nopemopes
Member
Registered: 2015-03-23
Posts: 12

Re: [Solved] Systemd user service and timer dbus error

jasonwryan wrote:

Have you followed these steps to the letter? https://wiki.archlinux.org/index.php/Systemd/User#D-Bus

Because it doesn't look like it to me... Is the environment variable set? And the socket activated?

Yes, did follow them to the letter. after that I tried some things like putting them in other directories to see if anything changed.

I also copied them into /etc/systemd/system, but i know they are run as root because my service that turns of my discrete vga also resides there.

The script i run:

#!/bin/bash

cd /home/jordy/Google\ Drive/
grive

Last edited by nopemopes (2015-03-23 20:09:36)

Offline

#6 2015-03-23 20:09:10

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

Re: [Solved] Systemd user service and timer dbus error

Your timer is the same as your service and your ExecStart is invalid (no full path).

Offline

#7 2015-03-23 20:12:19

nopemopes
Member
Registered: 2015-03-23
Posts: 12

Re: [Solved] Systemd user service and timer dbus error

Raynman wrote:

Your timer is the same as your service and your ExecStart is invalid (no full path).

[Unit]
Description=Drive sync

[Service]
onBootSec=3min
OnUnitActiveSec=5min
Unit=drive_sync.service

[Install]
WantedBy=timers.target

sorry, something gone wrong with copying the right file.

I copied the script to other places to see if it worked. In other service files I use the full path, for example /proc/acpi/call So i didn't forget that, i just tried it this way also.

Last edited by nopemopes (2015-03-23 20:16:51)

Offline

#8 2015-03-24 15:58:50

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

Re: [Solved] Systemd user service and timer dbus error

Hi Nopemopes
I've made a timer for a service named A.service which starts every minutes, when and only when the user is logged in.
I will show you how I did this, maybe you could find it useful for your case.
I use the 'systemd --user' process which is started when a user logs in.
First I wrote an A.service and an A.timer in ~/.config/systemd/user :

$ cat ~/.config/systemd/user/A.service 
[Unit]
Description=Test A running every minutes

[Service]
Type=oneshot
ExecStart=/usr/bin/echo 'A starts' ; /usr/bin/sleep 10 ; /usr/bin/echo 'A ends'
$ cat ~/.config/systemd/user/A.timer
[Unit]
Description=Timer for A running every minutes

[Timer]
AccuracySec=1us
OnActiveSec=10
OnUnitActiveSec=1min

For this timer to start when the user logs in, I created a default.target file in the same directory:

$ cat ~/.config/systemd/user/default.target 
[Unit]
Description=Default target for user
Wants=A.timer

Then I had to reboot the machine, for restarting the 'systemd --user' process.
It works as can be seen in the journal:

$ journalctl --user --follow
...
mars 24 15:46:58 arch64 systemd[512]: Reached target Paths.
mars 24 15:46:58 arch64 systemd[512]: Starting Sockets.
mars 24 15:46:58 arch64 systemd[512]: Reached target Sockets.
mars 24 15:46:58 arch64 systemd[512]: Starting Basic System.
mars 24 15:46:58 arch64 systemd[512]: Reached target Basic System.
mars 24 15:46:58 arch64 systemd[512]: Starting Test A running every minutes...
mars 24 15:46:58 arch64 echo[598]: A starts
mars 24 15:47:08 arch64 echo[624]: A ends
mars 24 15:47:08 arch64 systemd[512]: Started Test A running every minutes.
...
mars 24 15:47:58 arch64 systemd[512]: Starting Test A running every minutes...
mars 24 15:47:58 arch64 echo[649]: A starts
mars 24 15:48:08 arch64 echo[653]: A ends
mars 24 15:48:08 arch64 systemd[512]: Started Test A running every minutes.
mars 24 15:48:58 arch64 systemd[512]: Starting Test A running every minutes...
mars 24 15:48:58 arch64 echo[662]: A starts
mars 24 15:49:08 arch64 echo[666]: A ends
mars 24 15:49:08 arch64 systemd[512]: Started Test A running every minutes.
...

A starts every minutes as wanted.

BTW the timer you pasted in your last post will run your service ~3min (+ ~1min) after boot time, then every ~5min (+ ~1min) but as root and independently of your user login time.
You need to use the 'systemd --user' process instead, as shown above;
the 'AccuracySec=1us' line will elliminate the (+ ~1min) approximation.

Of course you need to adapt this simple example to your case.

Last edited by berbae (2015-03-24 16:07:51)

Offline

#9 2015-03-25 10:55:18

nopemopes
Member
Registered: 2015-03-23
Posts: 12

Re: [Solved] Systemd user service and timer dbus error

Thanks, it finally worked smile

Offline

#10 2015-03-25 15:25:29

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

Re: [Solved] Systemd user service and timer dbus error

It's nice, but please can you give more details about what you've done exactly, for those who might see this thread from a search in the future:
Life is a two-way street

Thanks for them.

Offline

#11 2015-03-26 06:39:09

nopemopes
Member
Registered: 2015-03-23
Posts: 12

Re: [Solved] Systemd user service and timer dbus error

berbae wrote:

It's nice, but please can you give more details about what you've done exactly, for those who might see this thread from a search in the future:
Life is a two-way street

Thanks for them.

Yes, I just installed arrch again and did not follow the wiki about the dbus and such. I only copied my service files to the location mentioned et voila smile

See my other post:

https://bbs.archlinux.org/viewtopic.php … 0#p1514050

Offline

Board footer

Powered by FluxBB