Resume from hibernate scripts

I’m trying to run a script to restore bluetooth devices after hibernate/suspend.
I created a file /etc/pm/sleep.d/20_bluetooth_restart according to the note at
SDB:Pm-utils - openSUSE
Code:

#!/bin/sh

case $1 in
suspend)
echo “stopping bluez on suspend”
service bluez-coldplug stop
;;
hibernate)
echo “stopping bluez on hibernate”
service bluez-coldplug stop
;;
resume)
echo “caught bluez resume”
service bluez-coldplug start
hciconfig 0 sspmode 0
;;
thaw)
echo “caught bluez thaw”
service bluez-coldplug start
hciconfig 0 sspmode 0
;;
*)
echo “bluez call from something odd”
;;
esac

In theory this should give me a message in my logs somewhere that an action was attempted
during the hibernate and thaw, but nothing occurs in /var/log/messages or the /var/log/pm-suspend.log.

This script is executable and if I run

/etc/pm/sleep.d/20_bluetooth_restart thaw

after hibernate/resume
then I get “caught bluetooth thaw”
but the subsequent commands are not executed successfully.

If I run the two commands separately from the command line after restore is complete then my bluetooth runs fine again.

On 2012-02-08 17:36, colbec wrote:
>
> I’m trying to run a script to restore bluetooth devices after
> hibernate/suspend.

Please remember to use code tags to post scripts here.

> I created a file /etc/pm/sleep.d/20_bluetooth_restart according to the
> note at
> ‘SDB:Pm-utils - openSUSE’ (http://en.opensuse.org/SDB:Pm-utils)

You should have a look at existing scripts (/usr/lib/pm-utils/sleep.d/).
For example, to log things in the messages file you have to use
“/bin/logger”. Another thing, many scripts import PM_FUNCTIONS. And… is
it marked executable?

> This script is executable and if I run
>> /etc/pm/sleep.d/20_bluetooth_restart thaw
> after hibernate/resume
> then I get “caught bluetooth thaw”
> but the subsequent commands are not executed successfully.

Try the service calls as root on a terminal.

> If I run the two commands separately from the command line after
> restore is complete then my bluetooth runs fine again.

Ah, you did? Mmm dunno… ah, change the first line to:


#!/bin/sh -x

from memory - I’m not sure if it is “-x”. If you then run the script
manually, it should print a lot of text about what it is doing.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

Looks like the code tag icon is only available in the advanced mode editor.
I keep forgetting.

-x gives (when run from CLI):


+ case $1 in
+ echo 'caught bluez thaw'
caught bluez thaw
+ service bluez-coldplug start
redirecting to systemctl
+ hciconfig 0 sspmode 0

But calling this script as such produces no effect on BT,
even though it seems to indicate that it is going to systemctl.

I’ll investigate the pm functions thing later. Thanks.

Looks like the code tag icon is only available in the advanced mode editor.
I keep forgetting.

-x gives (when run from CLI):


+ case $1 in
+ echo 'caught bluez thaw'
caught bluez thaw
+ service bluez-coldplug start
redirecting to systemctl
+ hciconfig 0 sspmode 0

But calling this script as such produces no effect on BT,
even though it seems to indicate that it is going to systemctl.

I’ll investigate the pm functions thing later. Thanks.

On 2012-02-09 01:16, colbec wrote:
>
> Looks like the code tag icon is only available in the advanced mode
> editor.
> I keep forgetting.

:slight_smile:

You must get used to it, things get difficult otherwise when reading.

> -x gives (when run from CLI):
>
> Code:
> --------------------
>
> + case $1 in
> + echo ‘caught bluez thaw’
> caught bluez thaw
> + service bluez-coldplug start
> redirecting to systemctl
> + hciconfig 0 sspmode 0
>
> --------------------

My trick worked, I see. The script is running correctly, but if it is
doesn’t do the effect you expect, I don’t know why.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

Looks like “service” and “hciconfig” want full absolute paths on my system.
Those commands now work.
However “echo” does not write to a log that I can find.
I see there is another posting on this forum that notes that using the alternate sysvinit does allow the log to be written.

I missed the earlier comment about replacing echo with logger.
That now works too, with the comments appearing in /var/log/messages, but nothing in /var/log/pm-suspend.log.

On 2012-02-09 13:26, colbec wrote:
>
> I missed the earlier comment about replacing echo with logger.
> That now works too, with the comments appearing in /var/log/messages,
> but nothing in /var/log/pm-suspend.log.

Well, you found a bug. Please, report it in Bugzilla. :slight_smile:


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)