The officially official Devuan Forum!

You are not logged in.

#1 2019-03-18 18:27:26

hothr
Member
Registered: 2019-03-18
Posts: 2  

run script after suspend

Hi there,

I try to run a command before/after suspending the computer, but I am not able to do so, and I was wondering it someone can help me with that. In short, one of the things that I would like to be able to do, is to control the headphone sound after suspending the computer.  In the past, with gentoo based distribution using openRC, I would create a file called sound in /usr/lib/pm-utils/sleep.d, make it executable (chmod   +x) , and write :

#!/bin/sh

case "$1" in
    resume)
        amixer --card 1 sset Headphone 100%
esac

However, with Devuan, using SysV (and xfce), it won’t work. I have tried the amixer --card 1 sset Headphone 100% command, and everything is working just fine, so I am pretty sure that, either my script is incorrect, or it is not at the right place.

Any help would be appreciated.

Offline

#2 2019-03-18 22:45:06

ralph.ronnquist
Administrator
From: Battery Point, Tasmania, AUS
Registered: 2016-11-30
Posts: 1,251  

Re: run script after suspend

A quick review of the code suggests that "local" specializations should rather reside in /etc/pm/sleep.d than /usr/lib/pm-utils/sleep.d, but that's not the problem here (since the latter is the "program" place for such scripts). However, the order is important. Scripts run in the order of their filenames, sorted as per sort (with LC_COLLATE=C).

Thus, the first check is where in the list of sleep scripts your script ends up, and then you need to determine whether that's the wrong place, and if so, rename it so as to have it run earlier or later. Note, if I understand it right, the scripts are run in the sort order before suspending, and reverse to that when resuming.

btw, it's good to append a true to your script, to make it always return success instead of returning whatever the amixer command returns.

Offline

#3 2019-03-19 06:13:39

hothr
Member
Registered: 2019-03-18
Posts: 2  

Re: run script after suspend

Thank you very much for your insight.

I tried to change the name of the file, but it didn’t help. However, I think that I found the confusion. If I suspend the computer using the log out option in the xfce menu, or if I directly use the command line using xfce tools (xfce4-session-logout –suspend), then the script won’t be effective. However, if I run the pm-suspend command, then the script will work.

I looked a discussion in the xfce forum, and it seems to be normal behaviour https://forum.xfce.org/viewtopic.php?id=9760. It seems that there is a way around that when using systemd, but I am unsure if it is possible to do something similar without it.

Offline

Board footer