Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

wake up scripting

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
kmchen
Posts: 74
Joined: 2013-04-24 06:29

wake up scripting

#1 Post by kmchen »

Hi everybody, I have a script that musts be executed as a normal user in group audio at wake-up from sleep on Debian Jessie.

The following command test as root works fine:

Code: Select all

root@kmcs:# sudo -H -u kmc bash -c "cadence-session-start -s"
Initiated PulseAudio successfully!
JACK Started Successfully
root@kmcs:#
But when I put exactly the same command in a script in /lib/systemd/system-sleep/ I called kmc_reload_sound, this script fails with error code 1:

Code: Select all

Nov 29 18:53:34 kmcs systemd-sleep[23651]: /lib/systemd/system-sleep/kmc_reload_sound failed with error code 1.
Thanks for your advices

rolf3945
Posts: 7
Joined: 2009-06-11 19:29

Re: wake up scripting

#2 Post by rolf3945 »

First guess: you need to add the full path to your commands ands scripts, ie instead of just bash use /bin/bash.

Good luck, Rolf

Edith: clearer phrasing
Last edited by rolf3945 on 2017-11-30 14:30, edited 1 time in total.

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: wake up scripting

#3 Post by debiman »

kmchen wrote:But when I put exactly the same command in a script in /lib/systemd/system-sleep/ I called kmc_reload_sound, this script fails with error code 1:

Code: Select all

Nov 29 18:53:34 kmcs systemd-sleep[23651]: /lib/systemd/system-sleep/kmc_reload_sound failed with error code 1.
... and systemd probably also told you to use 'journalctl' or 'systemctl status ...' to investigate.

kmchen
Posts: 74
Joined: 2013-04-24 06:29

Re: wake up scripting

#4 Post by kmchen »

Hi thanks for answering. I don't know where systemctl or whatever new f... journalctl would have put any message but I have this on syslog:
Nov 30 09:07:18 kmcs kmc_reload_sound V3: after wakeup: $0=/lib/systemd/system-sleep/kmc_reload_sound, ...
Nov 30 09:07:19 kmcs org.jackaudio.service[1499]: no message buffer overruns
Nov 30 09:07:19 kmcs systemd-sleep[31722]: tryCloseJackDBus() failed
Nov 30 09:07:19 kmcs systemd-sleep[31722]: Traceback (most recent call last):
Nov 30 09:07:19 kmcs systemd-sleep[31722]: File "/usr/share/cadence/src/cadence_session_start.py", line 236, in <module>
Nov 30 09:07:19 kmcs systemd-sleep[31722]: sys.exit(startSession(False, False))
Nov 30 09:07:19 kmcs systemd-sleep[31722]: File "/usr/share/cadence/src/cadence_session_start.py", line 67, in startSession
Nov 30 09:07:19 kmcs systemd-sleep[31722]: DBus.bus = dbus.SessionBus()
Nov 30 09:07:19 kmcs systemd-sleep[31722]: File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 211, in __new__
Nov 30 09:07:19 kmcs systemd-sleep[31722]: mainloop=mainloop)
Nov 30 09:07:19 kmcs systemd-sleep[31722]: File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 100, in __new__
Nov 30 09:07:19 kmcs systemd-sleep[31722]: bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
Nov 30 09:07:19 kmcs systemd-sleep[31722]: File "/usr/lib/python3/dist-packages/dbus/bus.py", line 122, in __new__
Nov 30 09:07:19 kmcs systemd-sleep[31722]: bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
Nov 30 09:07:19 kmcs systemd-sleep[31722]: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Nov 30 09:07:19 kmcs org.jackaudio.service[1499]: no message buffer overruns
...
Nov 30 09:07:20 kmcs pulseaudio[32012]: Unable to contact D-Bus session bus: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Nov 30 09:07:20 kmcs pulseaudio[32012]: Failed to load module "module-jackdbus-detect" (argument: "channels=2"): initialization failed.
Nov 30 09:07:20 kmcs pulseaudio[32012]: JACK error >Cannot connect to server socket err = Connexion refusée<
...
Later I've read a doc about the new f... journalctl and found that:

Code: Select all

kmc@kmcs:~$ sudo journalctl --since 09:07:18  _UID=1000
-- Logs begin at mer. 2017-11-29 21:26:18 CET, end at jeu. 2017-11-30 09:47:35 CET. --
nov. 30 09:07:19 kmcs org.jackaudio.service[1499]: no message buffer overruns
nov. 30 09:07:19 kmcs org.jackaudio.service[1499]: no message buffer overruns
nov. 30 09:07:19 kmcs org.jackaudio.service[1499]: no message buffer overruns
nov. 30 09:07:20 kmcs pulseaudio[32012]: Unable to contact D-Bus session bus: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-d
nov. 30 09:07:20 kmcs pulseaudio[32012]: Failed to load module "module-jackdbus-detect" (argument: "channels=2"): initialization failed.
nov. 30 09:07:20 kmcs pulseaudio[32012]: JACK error >Cannot connect to server socket err = Connexion refusée<
nov. 30 09:07:20 kmcs pulseaudio[32012]: JACK error >Cannot connect to server request channel<
nov. 30 09:07:21 kmcs pulseaudio[32012]: JACK error >Cannot connect to server socket err = Connexion refusée<
nov. 30 09:07:21 kmcs pulseaudio[32012]: JACK error >Cannot connect to server request channel<
nov. 30 09:07:22 kmcs pulseaudio[32012]: JACK error >Cannot connect to server socket err = Connexion refusée<
nov. 30 09:07:22 kmcs pulseaudio[32012]: JACK error >Cannot connect to server request channel<
nov. 30 09:07:23 kmcs pulseaudio[32012]: JACK error >Cannot connect to server socket err = Connexion refusée<
nov. 30 09:07:23 kmcs pulseaudio[32012]: JACK error >Cannot connect to server request channel<
nov. 30 09:07:24 kmcs pulseaudio[32012]: JACK error >Cannot connect to server socket err = Connexion refusée<
nov. 30 09:07:24 kmcs pulseaudio[32012]: JACK error >Cannot connect to server request channel<
nov. 30 09:07:25 kmcs pulseaudio[32012]: JACK error >Cannot connect to server socket err = Connexion refusée<
nov. 30 09:07:25 kmcs pulseaudio[32012]: JACK error >Cannot connect to server request channel<
nov. 30 09:07:26 kmcs pulseaudio[32012]: JACK error >jack server is not running or cannot be started<
nov. 30 09:07:26 kmcs pulseaudio[32012]: jack_client_open() failed.
nov. 30 09:07:26 kmcs pulseaudio[32012]: Failed to load module "module-jack-sink" (argument: ""): initialization failed.
nov. 30 09:07:26 kmcs pulseaudio[32012]: Module load failed.
nov. 30 09:07:26 kmcs pulseaudio[32012]: Module load failed.
nov. 30 09:07:26 kmcs pulseaudio[32012]: Échec lors de l'initialisation du démon
nov. 30 09:36:16 kmcs org.kde.knotify[1499]: QDBusConnection: session D-Bus connection created before QCoreApplication. Application may misbehave.
nov. 30 09:36:16 kmcs org.kde.knotify[1499]: QDBusConnection: session D-Bus connection created before QCoreApplication. Application may misbehave.
nov. 30 09:36:16 kmcs org.kde.knotify[1499]: Object::connect: No such signal org::freedesktop::UPower::DeviceAdded(QString)
nov. 30 09:36:16 kmcs org.kde.knotify[1499]: Object::connect: No such signal org::freedesktop::UPower::DeviceRemoved(QString)
nov. 30 09:44:42 kmcs systemd[1143]: Time has been changed
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: [0000000000ca6ec8] pulse audio output error: PulseAudio server connection failure: Connexion refusée
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: X Error: BadWindow (invalid Window parameter) 3
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: Major opcode: 20 (X_GetProperty)
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: Resource id:  0x8e0008e
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: X Error: BadWindow (invalid Window parameter) 3
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: Major opcode: 20 (X_GetProperty)
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: Resource id:  0x8e0008e
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: X Error: BadWindow (invalid Window parameter) 3
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: Major opcode: 18 (X_ChangeProperty)
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: Resource id:  0x8e0008e
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connexion refusée
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: [0000000000ca6ec8] alsa audio output error: cannot open ALSA device "default": Connexion refusée
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: [0000000000ca6ec8] core audio output error: La sortie audio a échoué
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: [0000000000ca6ec8] core audio output error: Le périphérique audio « default » ne peut pas être utilisé 
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: Connexion refusée.
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: [0000000000ca6ec8] core audio output error: module not functional
nov. 30 09:44:51 kmcs org.kde.knotify[1499]: [00007fe414025918] core decoder error: failed to create audio output
Here is the script:

Code: Select all

kmc@kmcs:~$ sudo cat /lib/systemd/system-sleep/kmc_reload_sound 
#!/bin/bash
## This file (or a link to it) must be in /lib/systemd/system-sleep/

if [[ "$1" = "post" ]]; then
logger -t "kmc_reload_sound V3" after wakeup: "\$0=$0, \$1=$1, \$2=$2"
sudo -H -u kmc bin/bash -c "pulseaudio --kill"
sudo -H -u kmc bin/bash -c "cadence-session-start -s"
sudo -H -u kmc bin/bash -c "pulseaudio --start"
alsactl restore
fi

rolf3945
Posts: 7
Joined: 2009-06-11 19:29

Re: wake up scripting

#5 Post by rolf3945 »

General note: scripts have there own environment and do not know about the path(s) specified on the console. You have two choices:
1.) Use the full path on every single call of an executable you use in the script.
2.) Specify a path within the script. I always use

Code: Select all

PATH=/sbin:/bin:/usr/bin:/usr/sbin:
Your script shows no path with the executables logger, sudo, pulseaudio, cadence-session-start and alsactl.

Best regards, Rolf

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: wake up scripting

#6 Post by debiman »

kmchen, i have seen that cadence's python script chokes on a dbus error.
like the previous poster said, it's an environment variable issue that you will run into a lot when you try to start gui apps via system services. have a look at this.
also, you shouldn't touch /usr/lib/systemd at all! custom services go to /etc/systemd/.

kmchen
Posts: 74
Joined: 2013-04-24 06:29

Re: wake up scripting

#7 Post by kmchen »

Reading your answers I changed my script like that:

Code: Select all

#!/bin/bash

PATH=/sbin:/bin:/usr/bin:/usr/sbin:

if [[ "$1" = "post" ]]; then
logger -t "kmc_reload_sound V3" after wakeup: "\$0=$0, \$1=$1, \$2=$2"
#export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
#pid=$(pgrep -xn pulseaudio)\
#  && export DBUS_SESSION_BUS_ADDRESS="$(grep -ao -m1 -P '(?<=DBUS_SESSION_BUS_ADDRESS=).*?\0' /proc/"$pid"/environ)"
#sudo -H -u kmc bash -c "pulseaudio --kill"
sudo -iH -u kmc bash -c "cadence-session-start -s"
#sudo -H -u kmc bash -c "pulseaudio --start"
#alsactl restore
fi
And now I get that:
déc. 04 18:42:09 kmcs pulseaudio[11991]: JACK error >Cannot connect to server socket err = Connexion refusée<
déc. 04 18:42:09 kmcs pulseaudio[11991]: JACK error >Cannot connect to server request channel<
déc. 04 18:42:10 kmcs pulseaudio[11991]: JACK error >jack server is not running or cannot be started<
déc. 04 18:42:10 kmcs pulseaudio[11991]: jack_client_open() failed.
déc. 04 18:42:10 kmcs pulseaudio[11991]: Failed to load module "module-jack-source" (argument: ""): initialization failed.
déc. 04 18:42:10 kmcs pulseaudio[11991]: Module load failed.
déc. 04 18:42:10 kmcs pulseaudio[11991]: Échec lors de l'initialisation du démon
déc. 04 18:42:11 kmcs org.jackaudio.service[1499]: no message buffer overruns
déc. 04 18:42:11 kmcs org.jackaudio.service[1499]: no message buffer overruns
déc. 04 18:42:11 kmcs org.jackaudio.service[1499]: no message buffer overruns
déc. 04 18:42:11 kmcs systemd-sleep[11808]: tryCloseJackDBus() failed
déc. 04 18:42:11 kmcs systemd-sleep[11808]: Traceback (most recent call last):
déc. 04 18:42:11 kmcs systemd-sleep[11808]: File "/usr/share/cadence/src/cadence_session_start.py", line 236, in <module>
déc. 04 18:42:11 kmcs systemd-sleep[11808]: sys.exit(startSession(False, False))
déc. 04 18:42:11 kmcs systemd-sleep[11808]: File "/usr/share/cadence/src/cadence_session_start.py", line 67, in startSession
déc. 04 18:42:11 kmcs systemd-sleep[11808]: DBus.bus = dbus.SessionBus()
déc. 04 18:42:11 kmcs systemd-sleep[11808]: File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 211, in __new__
déc. 04 18:42:11 kmcs systemd-sleep[11808]: mainloop=mainloop)
déc. 04 18:42:11 kmcs systemd-sleep[11808]: File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 100, in __new__
déc. 04 18:42:11 kmcs systemd-sleep[11808]: bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
déc. 04 18:42:11 kmcs systemd-sleep[11808]: File "/usr/lib/python3/dist-packages/dbus/bus.py", line 122, in __new__
déc. 04 18:42:11 kmcs systemd-sleep[11808]: bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
déc. 04 18:42:11 kmcs systemd-sleep[11808]: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
déc. 04 18:42:11 kmcs sudo[11914]: pam_unix(sudo:session): session closed for user kmc
déc. 04 18:42:11 kmcs systemd-sleep[11909]: /lib/systemd/system-sleep/kmc_reload_sound failed with error code 1.
Not shure I understood all you said. Systemd is a little abstrude to me

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: wake up scripting

#8 Post by debiman »

this is not about systemd.
it's about dbus and now also jackaudio, all sorts of problems when starting normal user gui apps from a system service.

thoughts:
does cadence itself offer a solution for command line only?

you will have to work your way throught it.

the only obvious thing i see in your script:
i think this:

Code: Select all

[[ "$1" = "post" ]]
should be:

Code: Select all

[[ "$1" == "post" ]]
don't bother exporting PATH like that; 'sudo -i' should take care of it.

also it looks like some important parts are commented out?

PS:
show us the systemd .service file and the full script and their respective paths!
PPS:
are you even sure the service triggers the way you want to, i.e. after suspend?

kmchen
Posts: 74
Joined: 2013-04-24 06:29

Re: wake up scripting

#9 Post by kmchen »

Thanks a lot for your support.

Reading your comments I changed my scripts to show what happens clearly as follow:

The simplest "heart script" is :

Code: Select all

kmc@kmcs:~$ cat /usr/local/sbin/sound_reload
#!/bin/bash

sudo logger "kmc_ $1"
cadence-session-start -s
I have 2 ways to launch it, automatically at resume or manually after resume:

automatically at resume as a systemd script:

Code: Select all

root@kmcs:/home/kmc# cat /lib/systemd/system-sleep/kmc_reload_sound
#!/bin/bash

logger "kmc_rs Resume from sleep script started"
sudo -iH -u kmc bash -c "/usr/local/sbin/sound_reload resume_launched"
Or manually in a terminal after resume from sleep been done:

Code: Select all

kmc@kmcs:~$ /usr/local/sbin/sound_reload manually_lauched
Initiated PulseAudio successfully!
JACK Started Successfully
So I sleep the PC, resume and then lauch the "heart script" manually.
And now the syslog interesting parts:
Dec 12 12:19:26 kmcs logger: kmc_rs Resume from sleep script started
Dec 12 12:19:26 kmcs logger: kmc_rs resume_launched
Dec 12 12:19:27 kmcs org.jackaudio.service[920]: no message buffer overruns
Dec 12 12:19:27 kmcs systemd-sleep[8537]: tryCloseJackDBus() failed
Dec 12 12:19:27 kmcs systemd-sleep[8537]: Traceback (most recent call last):
Dec 12 12:19:27 kmcs systemd-sleep[8537]: File "/usr/share/cadence/src/cadence_session_start.py", line 236, in <module>
Dec 12 12:19:27 kmcs systemd-sleep[8537]: sys.exit(startSession(False, False))
Dec 12 12:19:27 kmcs systemd-sleep[8537]: File "/usr/share/cadence/src/cadence_session_start.py", line 67, in startSession
Dec 12 12:19:27 kmcs systemd-sleep[8537]: DBus.bus = dbus.SessionBus()
Dec 12 12:19:27 kmcs systemd-sleep[8537]: File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 211, in __new__
Dec 12 12:19:27 kmcs systemd-sleep[8537]: mainloop=mainloop)
Dec 12 12:19:27 kmcs systemd-sleep[8537]: File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 100, in __new__
Dec 12 12:19:27 kmcs systemd-sleep[8537]: bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
Dec 12 12:19:27 kmcs systemd-sleep[8537]: File "/usr/lib/python3/dist-packages/dbus/bus.py", line 122, in __new__
Dec 12 12:19:27 kmcs systemd-sleep[8537]: bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
Dec 12 12:19:27 kmcs systemd-sleep[8537]: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Dec 12 12:19:27 kmcs systemd-sleep[8538]: /lib/systemd/system-sleep/kmc_reload_sound failed with error code 1.

...
Dec 12 12:19:51 kmcs kmc: kmc_rs manually_lauched
Dec 12 12:19:51 kmcs org.jackaudio.service[920]: no message buffer overruns
Dec 12 12:19:51 kmcs rtkit-daemon[1868]: Successfully made thread 9270 of process 9270 (/usr/bin/pulseaudio) owned by '1000' high priority at nice level -11.
Dec 12 12:19:51 kmcs rtkit-daemon[1868]: Supervising 1 threads of 1 processes of 1 users.
Dec 12 12:19:51 kmcs pulseaudio[9270]: Stale PID file, overwriting.
Dec 12 12:19:51 kmcs pulseaudio[9270]: JACK error >Cannot connect to server socket err = Connexion refusée<
Dec 12 12:19:51 kmcs pulseaudio[9270]: JACK error >Cannot connect to server request channel<
Dec 12 12:19:52 kmcs pulseaudio[9270]: Default and alternate sample rates are the same.
Dec 12 12:19:52 kmcs pulseaudio[9270]: JACK error >Cannot use real-time scheduling (RR/5)(1: Opération non permise)<
Dec 12 12:19:52 kmcs pulseaudio[9270]: JACK error >JackClient::AcquireSelfRealTime error<
Dec 12 12:19:52 kmcs pulseaudio[9270]: Default and alternate sample rates are the same.
Dec 12 12:19:52 kmcs pulseaudio[9270]: JACK error >Cannot use real-time scheduling (RR/5)(1: Opération non permise)<
Dec 12 12:19:52 kmcs pulseaudio[9270]: JACK error >JackClient::AcquireSelfRealTime error<
Dec 12 12:19:52 kmcs pulseaudio[9270]: JACK error >Server is not running<
Dec 12 12:19:52 kmcs pulseaudio[9270]: protocol error, kicking client
Dec 12 12:19:54 kmcs org.jackaudio.service[920]: no message buffer overruns
Dec 12 12:19:54 kmcs org.jackaudio.service[920]: ALSA lib pcm_hw.c:1667:(_snd_pcm_hw_open) Invalid value for card
Dec 12 12:19:54 kmcs rtkit-daemon[1868]: Successfully made thread 9348 of process 9348 (/usr/bin/pulseaudio) owned by '1000' high priority at nice level -11.
Dec 12 12:19:54 kmcs rtkit-daemon[1868]: Supervising 1 threads of 1 processes of 1 users.
Dec 12 12:19:54 kmcs pulseaudio[9348]: Stale PID file, overwriting.
Dec 12 12:19:54 kmcs pulseaudio[9348]: Default and alternate sample rates are the same.
Dec 12 12:19:54 kmcs pulseaudio[9348]: JACK error >Cannot use real-time scheduling (RR/5)(1: Opération non permise)<
Dec 12 12:19:54 kmcs pulseaudio[9348]: JACK error >JackClient::AcquireSelfRealTime error<
Dec 12 12:19:54 kmcs pulseaudio[9348]: Not enough physical output ports, leaving unconnected.
You'll notice that the resume script is launched at 12:19:26 calling the "heart script" as kmc user but fails with a lack of "$DISPLAY for X11".

Then I launch the "heart script" manually from a console at 12:19:51 and it shows many errors in syslog but works at last (I have sound :D )

So the problem seems to be that I can't launch the "heart script" as myself, kmc, at resume. Or what I missed ?

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: wake up scripting

#10 Post by Dai_trying »

kmchen wrote:You'll notice that the resume script is launched at 12:19:26 calling the "heart script" as kmc user but fails with a lack of "$DISPLAY for X11".
This would suggest to me that X is not yet up when you run your script, it might be that you could use a delay with your script timing to allow the session to resume first, although it could also be that the $DISPLAY variable is not available directly in the systemd workspace , maybe you could import it but I'm not very experienced with systemd so far so might be better for some others advice there.

kmchen
Posts: 74
Joined: 2013-04-24 06:29

Re: wake up scripting

#11 Post by kmchen »

Yes, the DISPLAY variable seems to have to be set. But I don't know how to set it in context too.

Tried also a sleep 10 but no success. The $DISPLAY error remains unchanged

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: wake up scripting

#12 Post by Dai_trying »

I just noticed you are using sudo in your script, so would the system require a password in order for this to run? like i said earlier not a systemd expert so not sure how it would handle scripts requiring elevated privileges.

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: wake up scripting

#13 Post by debiman »

kmchen wrote:Yes, the DISPLAY variable seems to have to be set. But I don't know how to set it in context too.

Tried also a sleep 10 but no success. The $DISPLAY error remains unchanged
a sleep won't help.
i already linked this article of mine, i'll do it again: http://dt.iki.fi/udev/
please also click on the links inside the article.

kmchen
Posts: 74
Joined: 2013-04-24 06:29

Re: wake up scripting

#14 Post by kmchen »

Sorry I'm not a udev specialist and don't have any idea of what DBUS is. :?

So, reading your article, links included, I did not understand a 50% and found only the DBUS thing related to my problem. I tried this:

Code: Select all

#!/bin/bash
logger "kmc_rs Resume from sleep script started "
#sudo -iH -u kmc bash -c "/usr/local/sbin/sound_reload resume_launched"
sudo -i -u kmc DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus" cadence-session-start -s
and got that:
Dec 15 18:17:11 kmcs systemd-sleep[23319]: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.FileNotFound: Failed to connect to socket /run/user/1000/bus: Aucun fichier ou dossier de ce type
Dec 15 18:17:11 kmcs systemd-sleep[23496]: /lib/systemd/system-sleep/kmc_reload_sound failed with error code 1.

kmchen
Posts: 74
Joined: 2013-04-24 06:29

Re: wake up scripting

#15 Post by kmchen »

Now tried that:

Code: Select all

pid=$(pgrep -xn pulseaudio)\
  && export DBUS_SESSION_BUS_ADDRESS="$(grep -ao -m1 -P '(?<=DBUS_SESSION_BUS_ADDRESS=).*?\0' /proc/"$pid"/environ)"

sudo -i -u kmc pulseaudio --kill
sudo -i -u kmc cadence-session-start -s
sudo -i -u kmc pulseaudio --start
sudo -i -u kmc /usr/sbin/alsactl restore
and it works ! :D
Thanks to all and special to Debiman

kmchen
Posts: 74
Joined: 2013-04-24 06:29

Re: wake up scripting

#16 Post by kmchen »

Sorry to come back with that thread but it worked a few days and failed after a while. Reboot or system upgrade ? I don't know.

I recall my simplified script:

Code: Select all

cat /lib/systemd/system-sleep/kmc_reload_sound
#!/bin/bash
#

pid=$(pgrep -xn pulseaudio)\
  && export DBUS_SESSION_BUS_ADDRESS="$(grep -ao -m1 -P '(?<=DBUS_SESSION_BUS_ADDRESS=).*?\0' /proc/"$pid"/environ)"

#sudo -i -u kmc pulseaudio --kill
logger kmc_v2
sudo -i -u kmc cadence-session-start -s
logger kmc_v2_end
#sudo -i -u kmc pulseaudio --start
#sudo -i -u kmc /usr/sbin/alsactl restore

sudo -i -u kmc /usr/bin/play /usr/share/sounds/Kopete_Event.ogg
And I get that in syslog after a wake up from sleep:
Dec 29 18:40:44 kmcs logger: kmc_v2
Dec 29 18:40:49 kmcs pulseaudio[1893]: JACK error >Cannot connect to server request channel<
Dec 29 18:40:50 kmcs pulseaudio[1893]: JACK error >Cannot connect to server socket err = Connexion refusée<
Dec 29 18:40:51 kmcs pulseaudio[1893]: JACK error >jack server is not running or cannot be started<
Dec 29 18:40:51 kmcs pulseaudio[1893]: jack_client_open() failed.
Dec 29 18:40:51 kmcs pulseaudio[1893]: Failed to load module "module-jack-source" (argument: ""): initialization failed.
Dec 29 18:40:51 kmcs pulseaudio[1893]: Module load failed.
Dec 29 18:40:51 kmcs pulseaudio[1893]: Échec lors de l'initialisation du démon
Dec 29 18:40:52 kmcs org.jackaudio.service[1542]: no message buffer overruns
Dec 29 18:40:52 kmcs systemd-sleep[1860]: tryCloseJackDBus() failed
Dec 29 18:40:52 kmcs systemd-sleep[1860]: Traceback (most recent call last):
Dec 29 18:40:52 kmcs systemd-sleep[1860]: File "/usr/share/cadence/src/cadence_session_start.py", line 236, in <module>
Dec 29 18:40:52 kmcs systemd-sleep[1860]: sys.exit(startSession(False, False))
Dec 29 18:40:52 kmcs systemd-sleep[1860]: File "/usr/share/cadence/src/cadence_session_start.py", line 67, in startSession
Dec 29 18:40:52 kmcs systemd-sleep[1860]: DBus.bus = dbus.SessionBus()
Dec 29 18:40:52 kmcs systemd-sleep[1860]: File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 211, in __new__
Dec 29 18:40:52 kmcs systemd-sleep[1860]: mainloop=mainloop)
Dec 29 18:40:52 kmcs systemd-sleep[1860]: File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 100, in __new__
Dec 29 18:40:52 kmcs systemd-sleep[1860]: bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
Dec 29 18:40:52 kmcs systemd-sleep[1860]: File "/usr/lib/python3/dist-packages/dbus/bus.py", line 122, in __new__
Dec 29 18:40:52 kmcs systemd-sleep[1860]: bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
Dec 29 18:40:52 kmcs systemd-sleep[1860]: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Dec 29 18:40:52 kmcs logger: kmc_v2_end
DBUS exception again. :oops:

Thanks for your help to have a linux sound system 100% working one day !

I just want to launch the simple command

Code: Select all

cadence-session-start -s
that works perfectly when I have X11 workin after resume from sleep.

kmchen
Posts: 74
Joined: 2013-04-24 06:29

Re: wake up scripting

#17 Post by kmchen »

Any body there ?

Post Reply