You are not logged in.
I'm trying to create a user service file to stop JACK audio service on suspend so that it gracefully cuts off connection with devices. I created /etc/systemd/system/suspend@user.service:
[Unit]
Description=User suspend actions
Before=sleep.target
[Service]
User=%I
Type=simple
ExecStart=/usr/bin/jack_control stop
ExecStartPost=/usr/bin/sleep 1
[Install]
WantedBy=sleep.target
I enable it but if I check the status, I get this:
suspend@brightchip.service - User suspend actions
Loaded: loaded (/etc/systemd/system/suspend@brightchip.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2021-05-07 11:51:23 BST; 1h 34min ago
Main PID: 76304 (code=exited, status=1/FAILURE)
CPU: 39ms
May 07 11:51:22 taichi-z270 jack_control[76304]: sys.exit(main())
May 07 11:51:22 taichi-z270 jack_control[76304]: File "/usr/bin/jack_control", line 159, in main
May 07 11:51:22 taichi-z270 jack_control[76304]: bus = dbus.SessionBus()
May 07 11:51:22 taichi-z270 jack_control[76304]: File "/usr/lib/python3.9/site-packages/dbus/_dbus.py", line 212, in __new__
May 07 11:51:22 taichi-z270 jack_control[76304]: return Bus.__new__(cls, Bus.TYPE_SESSION, private=private,
May 07 11:51:22 taichi-z270 jack_control[76304]: File "/usr/lib/python3.9/site-packages/dbus/_dbus.py", line 102, in __new__
May 07 11:51:22 taichi-z270 jack_control[76304]: bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
May 07 11:51:22 taichi-z270 jack_control[76304]: File "/usr/lib/python3.9/site-packages/dbus/bus.py", line 124, in __new__
May 07 11:51:22 taichi-z270 jack_control[76304]: bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
May 07 11:51:22 taichi-z270 jack_control[76304]: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Using X11 for dbus-daemon autolaunch was disabled at compile time, set your DBUS_SESSION_BUS_ADDRESS instead
I tried the dbus version:
[Service]
Type=dbus
BusName=org.jackaudio.service
ExecStop=/usr/sbin/example-service
but I get the same result. I can confirm that jackaudio is running.
I also tried to do it as --user with --user in ~/.config/systemd/user but no luck.
I'm not entirely sure what my DBUS_SESSION_BUS_ADDRESS is and how to set it.
Any help please?
Last edited by d_fajardo (2021-05-07 15:55:14)
Offline
The solution was to append
export $(dbus-launch)
to my .bashrc and the service file works.
Sorry for the noise.
Offline
I've reopened this thread. The above fix worked once and I thought the problem was solved but I still get the same error.
I also tried creating creating a script in /usr/lib/systemd/system-sleep and journalctl flags me the same error as systemd above.
The issue is clearly with DBus. Anyone can help?
Offline
The problem here is that systemd's system daemon is not linked to your own user's dbus session (... you should also remove dbus-launch from your bashrc, that will launch a new dbus session every time you open a terminal, not something you want), your "personal" DBUS_SESSION_BUS_ADDRESS will be created on login by systemd and used for the session of your user.
The simple way is simply hardcode it, it's normally unix:path=/run/user/1000/bus where the 1000 is the UID of your user. What you probably rather want to do is look for a process that is surely part of your user environment (... or since this is a stop job, just look for the jack process) use something like https://gist.github.com/AladW/de1c5676d93d05a5a0e1 and change the first lookup for an xinit process for the process you want to check, and then import the DBUS_SESSION_BUS_ADDRESS before executing the stop command.
Offline
Thanks V1del.
I made another attempt. I created a script in /usr/lib/systemd/system-sleep:
#!/bin/sh
pid=$(pgrep -x jackdbus -n)
import_environment() {
(( pid )) && for var; do
IFS='=' read key val < <(egrep -z "$var" /proc/$pid/environ)
printf -v "$key" %s "$val"
[[ ${!key} ]] && export "$key"
done
}
import_environment DBUS_SESSION_BUS_ADDRESS
case $1/$2 in
pre/*)
/usr/bin/jack_control stop
;;
esac
My bash scripting knowledge is very minimal so this might be a poor attempt. Journalctl still gives the same error:
May 08 09:00:28 taichi-z270 systemd-sleep[501589]: File "/usr/bin/jack_control", line 403, in <module>
May 08 09:00:28 taichi-z270 systemd-sleep[501589]: sys.exit(main())
May 08 09:00:28 taichi-z270 systemd-sleep[501589]: File "/usr/bin/jack_control", line 159, in main
May 08 09:00:28 taichi-z270 systemd-sleep[501589]: bus = dbus.SessionBus()
May 08 09:00:28 taichi-z270 systemd-sleep[501589]: File "/usr/lib/python3.9/site-packages/dbus/_dbus.py", line 212, in __new__
May 08 09:00:28 taichi-z270 systemd-sleep[501589]: return Bus.__new__(cls, Bus.TYPE_SESSION, private=private,
May 08 09:00:28 taichi-z270 systemd-sleep[501589]: File "/usr/lib/python3.9/site-packages/dbus/_dbus.py", line 102, in __new__
May 08 09:00:28 taichi-z270 systemd-sleep[501589]: bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
May 08 09:00:28 taichi-z270 systemd-sleep[501589]: File "/usr/lib/python3.9/site-packages/dbus/bus.py", line 124, in __new__
May 08 09:00:28 taichi-z270 systemd-sleep[501589]: bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
May 08 09:00:28 taichi-z270 systemd-sleep[501589]: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoReply: Did not receive a re>
May 08 09:00:28 taichi-z270 [501583]: /usr/lib/systemd/system-sleep/jackaudio failed with exit status 1.
May 08 09:00:28 taichi-z270 systemd-sleep[501582]: Suspending system...
May 08 09:00:42 taichi-z270 systemd-sleep[501582]: System resumed.
May 08 09:00:42 taichi-z270 systemd[1]: systemd-suspend.service: Deactivated successfully.
So I'm not doing the right thing. I do can see the variable if I just do cat /proc/$pid/environ with pid==jackdbus:
XDG_RUNTIME_DIR=/run/user/1000QT_AUTO_SCREEN_SCALE_FACTOR=0SESSION_MANAGER=local/taichi-z270:@/tmp/.ICE-unix/1337,unix/taichi-z270:/tmp/.ICE-unix/1337MOTD_SHOWN=pamSYSTEMD_EXEC_PID=1100XDG_SESSION_TYPE=x11DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus,guid=e26d0af001308ec833f437f86096260aUSER=brightchipXAUTHORITY=/home/brightchip/.XauthorityDBUS_STARTER_BUS_TYPE=sessionSHLVL=0XDG_SESSION_DESKTOP=KDESHELL=/bin/bashKDE_APPLICATIONS_AS_SCOPE=1MKLROOT=/opt/intel/mklXCURSOR_THEME=breeze_cursorsKDE_FULL_SESSION=trueLV2_PATH=/home/brightchip/.lv2:/usr/lib/lv2:/usr/local/lib/lv2PWD=/home/brightchipHOME=/home/brightchipCADENCE_AUTO_STARTED=trueDBUS_STARTER_ADDRESS=unix:path=/run/user/1000/bus,guid=e26d0af001308ec833f437f86096260aDISPLAY=:0PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/cuda/bin:/opt/cuda/nsight_compute:/opt/cuda/nsight_systems/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perlGTK_MODULES=canberra-gtk-moduleXDG_VTNR=1JOURNAL_STREAM=8:16091XDG_SESSION_ID=2XDG_SEAT=seat0GTK_RC_FILES=/etc/gtk/gtkrc:/home/brightchip/.gtkrc:/home/brightchip/.config/gtkrcINVOCATION_ID=d5d769faf53b41498da4cece905cb566XDG_SESSION_CLASS=userVST_PATH=/home/brightchip/.vst:/usr/lib/vst:/usr/local/lib/vstLANG=en_GB.UTF-8LOGNAME=brightchipLADSPA_PATH=/home/brightchip/.ladspa:/usr/lib/ladspa:/usr/local/lib/ladspaXCURSOR_SIZE=24XDG_CURRENT_DESKTOP=KDEXDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session1DESKTOP_SESSION=plasmaGTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/brightchip/.gtkrc-2.0:/home/brightchip/.config/gtkrc-2.0KDE_SESSION_UID=1000CUDA_PATH=/opt/cudaMAIL=/var/spool/mail/brightchipGDK_DPI_SCALE=0.5GDK_SCALE=2QT_XCB_TABLET_LEGACY_COORDINATES=XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0KDE_SESSION_VERSION=5MANAGERPID=991DSSI_PATH=/home/brightchip/.dssi:/usr/lib/dssi:/usr/local/lib/dssiHG=/usr/bin/hg
I'm not sure how to properly import the variable.
Offline