You are not logged in.
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
What errors are you getting? https://bbs.archlinux.org/viewtopic.php?id=57855
Not a Sysadmin issue, moving to NC...
Offline
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.shdrive_sync.timer
[Unit]
Description=Drive sync
[Service]
Type=simple
ExecStart=drive_script.shthese files are located in ~/.config/systemd/user
Last edited by nopemopes (2015-03-23 20:00:55)
Offline
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?
Offline
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/
griveLast edited by nopemopes (2015-03-23 20:09:36)
Offline
Your timer is the same as your service and your ExecStart is invalid (no full path).
Offline
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.targetsorry, 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
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=1minFor 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.timerThen 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
Thanks, it finally worked ![]()
Offline
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
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 streetThanks 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 ![]()
See my other post:
Offline