2

I use Mageia ver 4 Linux as server, without X started and without any user login-in during normal operation. This PC has a special card for measuring and control of other devices. This card has its own SH4 Linux on-board, and needs to be shutdown first, before PC shutdown.

There is a set of commands supplied by the card vendor and they works properly. To shutdown the card it is necessary to execute /usr/sbin/io_card stop, wait for proper card shutdown and then execute "ordinary" PC shutdown.

I wrote a special shutdown script and it works properly. But the problem is when I press "Power" button on PC, it executes "ordinary" PC shutdown instead of my script.

I try to change /etc/acpi/events/power and systemd scripts to include my own shutdown script, but it does not work. At this moment /etc/acpi/events/power file contains only entry :

action=/home/serwer/Pobrane/shut

where "shut" is my shutdown script, working good when running manually. So how can I change default power-off action associated with depressing "Power" button?

  • Please explain exactly how you tried to change ` /etc/acpi/events/power`. – terdon Mar 17 '14 at 15:36
  • The /etc/acpi/events/power file contains only entry action=/home/serwer/Pobrane/shut where "shut" is my shutdown script, working good when running manually. – mackowiakp Mar 17 '14 at 18:55
  • Did you try my answer? Also, please edit your question to add new info, it is easy to miss and hard to read in the comments. – terdon Mar 17 '14 at 18:57
1

I can't guarantee this will work on Mageia but this is how I got a similar thing to work on my Debian.

There is a script (on my machine, it's /etc/acpi/powerbtn-acpi-support.sh) that is run by default when the power button is pressed. Edit that script, and find this section:

if [ -x /etc/acpi/powerbtn.sh ] ; then
    # Compatibility with old config script from acpid package
    /etc/acpi/powerbtn.sh
elif [ -x /etc/acpi/powerbtn.sh.dpkg-bak ] ; then
        # Compatibility with old config script from acpid package
    # which is still around because it was changed by the admin
        /etc/acpi/powerbtn.sh.dpkg-bak
else
    # Normal handling.
    /sbin/shutdown -h -P now "Power button pressed"

fi

Change /sbin/shutdown -h -P now "Power button pressed" to point to your script instead, save the file and that should now be launched whenever you press the power button.

  • May /etc/acpi subdir contains two dirs: "action" and "events". So it is a little bit different to Yours – mackowiakp Mar 17 '14 at 18:57
  • OK, I edited my post. At this moment I de facto use the same solution as You described in Your post. The only diffrence is that in Your instalation, shutdown script is located in /etc/acpi/powerbtn-acpi-support.sh, in my Linux distro default location is /etc/acpi/events/power file. And this one was edited by me as described. – mackowiakp Mar 18 '14 at 6:24
0

If you have polkit version >= 0.106, you can set a polkit rule file, linked to shutdown action, which calls your script when the user press shutdown button.

The polkit rule will be similar to this:

polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.consolekit.system.stop" ||
    action.id == "org.freedesktop.login1.power-off" ||
    action.id == "org.freedesktop.login1.power-off-multiple-sessions" || 
    action.id == "org.xfce.session.xfsm-shutdown-helper")  
{
        polkit.spawn(["/home/serwer/Pobrane/shut", subject.user]);        
        return polkit.Result.YES;
}
});

To add this rule, you only have to copy this in a file with .rules extension, and copy the file in /usr/share/polkit-1/rules.d/

But I don't know if this runs without a graphical interface

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.