wake up scripting

Kernels & Hardware, configuring network, installing services

wake up scripting

Postby kmchen » 2017-11-29 17:22

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
Développeur WEB
http://www.webologix.com
kmchen
 
Posts: 21
Joined: 2013-04-24 06:29

Re: wake up scripting

Postby rolf3945 » 2017-11-29 17:31

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.
rolf3945
 
Posts: 6
Joined: 2009-06-11 19:29

Re: wake up scripting

Postby debiman » 2017-11-29 19:43

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.
User avatar
debiman
 
Posts: 1626
Joined: 2013-03-12 07:18

Re: wake up scripting

Postby kmchen » 2017-11-30 07:37

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
Développeur WEB
http://www.webologix.com
kmchen
 
Posts: 21
Joined: 2013-04-24 06:29

Re: wake up scripting

Postby rolf3945 » 2017-11-30 14:45

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
rolf3945
 
Posts: 6
Joined: 2009-06-11 19:29

Re: wake up scripting

Postby debiman » 2017-11-30 17:02

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/.
User avatar
debiman
 
Posts: 1626
Joined: 2013-03-12 07:18

Re: wake up scripting

Postby kmchen » 2017-12-04 17:04

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
Développeur WEB
http://www.webologix.com
kmchen
 
Posts: 21
Joined: 2013-04-24 06:29

Re: wake up scripting

Postby debiman » 2017-12-05 05:48

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?
User avatar
debiman
 
Posts: 1626
Joined: 2013-03-12 07:18

Re: wake up scripting

Postby kmchen » 2017-12-12 11:03

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 ?
Développeur WEB
http://www.webologix.com
kmchen
 
Posts: 21
Joined: 2013-04-24 06:29

Re: wake up scripting

Postby Dai_trying » 2017-12-12 11:41

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.
Dai_trying
 
Posts: 339
Joined: 2016-01-07 12:25

Re: wake up scripting

Postby kmchen » 2017-12-13 12:39

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
Développeur WEB
http://www.webologix.com
kmchen
 
Posts: 21
Joined: 2013-04-24 06:29

Re: wake up scripting

Postby Dai_trying » 2017-12-13 19:53

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.
Dai_trying
 
Posts: 339
Joined: 2016-01-07 12:25

Re: wake up scripting

Postby debiman » 2017-12-15 06:02

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.
User avatar
debiman
 
Posts: 1626
Joined: 2013-03-12 07:18

Re: wake up scripting

Postby kmchen » 2017-12-15 17:03

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.
Développeur WEB
http://www.webologix.com
kmchen
 
Posts: 21
Joined: 2013-04-24 06:29

Re: wake up scripting

Postby kmchen » 2017-12-15 17:27

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
Développeur WEB
http://www.webologix.com
kmchen
 
Posts: 21
Joined: 2013-04-24 06:29


Return to System configuration

Who is online

Users browsing this forum: carlos11 and 8 guests

fashionable