Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: Perform actions before/after hibernating/suspending with acpid (Read 2513 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Perform actions before/after hibernating/suspending with acpid

Is it possible? I do not use elogind.
Is there something else maybe?

It seems not looking https://wiki.archlinux.org/title/Acpid.

I use "echo disk > /sys/power/state" to hibernate.

Re: Perform actions before/after hibernating/suspending with acpid

Reply #1
It probably can be done using a combination of acpid and pm-utils(AUR).

I first came across this as a fix for 'suspend when closing the lid' on my chromebook.
https://archlinuxarm.org/wiki/Samsung_Chromebook.

pm-utils has not been updated since 2017 but still builds.
And I'm fairly sure it still works. I'd have to update the chromebook to check.

There could be other methods ?

Re: Perform actions before/after hibernating/suspending with acpid

Reply #2
When I press the button or use a lid only acpid should work.
But if send the command to hibernate via a keyboard shortcut how can I do something?
I think that it would be nice to have some dedicated daemon.

Re: Perform actions before/after hibernating/suspending with acpid

Reply #3
I found out that before e/logind people used to use https://github.com/ConsoleKit2/ConsoleKit2, that it's in the AUR.
It is used by FreeBSD.

Re: Perform actions before/after hibernating/suspending with acpid

Reply #4
I was not planning to communicate this yet but as I a see more and more related topics in our forum I'll make a start now:

It's not available for use yet but lately I have been working on a new repo that provides packages like consolekit2, pm-utils and quite a few more to be able to run some custom Xorg and Wayland desktops with neither elogind nor libelogind, but makes use of seatd, turnstile and basu.

These are some currently known limitations:

- This will not be a drop-in replacement for elogind.
- This will not work for all desktops.
- This will not work for all packages.
- It is experimental, so not suited to be used for any daily driver.
- This repo will not be supported in any way by Artix Linux.
- This will result in polkit no longer working for the login1/session actions (reboot/shutdown/suspend/hibernate).

A word of caution related to the original post: don't suspend/hibernate by writing directly to /sys/power/state; this will cause drivers to miss state change interrupts and crash, causing devices to no longer work when the system is resumed unless re-acitvated by a module unload/reload or rescan. Use pm-utils instead.

During the coming weekend I hope to be able to provide more information.

artist

Re: Perform actions before/after hibernating/suspending with acpid

Reply #5
I don't quite get what your problem is.
Anyway check etc/acpi/handler.sh. Especially this part:
Code: [Select]
    button/lid)
        case "$3" in
            close)
                logger 'LID closed'
                ;;
            open)
                logger 'LID opened'
                ;;
            *)
                logger "ACPI action undefined: $3"
                ;;
    esac
It's not properly configured by default.


Re: Perform actions before/after hibernating/suspending with acpid

Reply #6
- This will not be a drop-in replacement for elogind.
- This will not work for all desktops.
- This will not work for all packages.
- It is experimental, so not suited to be used for any daily driver.
- This repo will not be supported in any way by Artix Linux.
- This will result in polkit no longer working for the login1/session actions (reboot/shutdown/suspend/hibernate).
Please, consider naming it [world-clown].

Re: Perform actions before/after hibernating/suspending with acpid

Reply #7
I don't quite get what your problem is.
As I stated:
Quote
When I press the button or use a lid only acpid should work.
But if send the command to hibernate via a keyboard shortcut how can I do something?
Correct me if I am wrong .

Quote
A word of caution related to the original post: don't suspend/hibernate by writing directly to /sys/power/state
...
 Use pm-utils instead.
Good to know.
I did now about pm-utils back when I was using elogind, it did not work (loginctl hibernate) so I was writing directly.

Is there something else besides consolekit that should I use? I still have to learn what's that.
I am running bspwm right now.

Re: Perform actions before/after hibernating/suspending with acpid

Reply #8
According to https://web.archive.org/web/20200928212358if_/https://wiki.gentoo.org/wiki/ConsoleKit:
Quote
ConsoleKit's primary function is to support multi-user setups.
So not it's not really useful for me.

Basu
Quote
Some projects rely on the sd-bus library for DBus support. However not all systems have systemd or elogind installed. This library provides just sd-bus (and the busctl utility).

Will Artix keep to having packages depending on elogind?
Alpine does not installed elogind for networkmanager etc. there are UIs like sxmo that works fine without.

Quote
Please, consider naming it [world-clown].
A clown world.

Re: Perform actions before/after hibernating/suspending with acpid

Reply #9
It's not available for use yet but lately I have been working on a new repo that provides packages like consolekit2, pm-utils and quite a few more to be able to run some custom Xorg and Wayland desktops with neither elogind nor libelogind, but makes use of seatd, turnstile and basu.

Due to set backs this has been put on hold.

artist

Re: Perform actions before/after hibernating/suspending with acpid

Reply #10
I found out that  I have elogind-daemon running and it is needed for Xorg I think, killing it kills the UI.
So I disabled acpid since I just press the power button and that is handled by the elogind-daemon process.

According to htop it is started by dinit so it is not clear.
There is no service:
Code: [Select]
dinitctl list | grep elogind

Re: Perform actions before/after hibernating/suspending with acpid

Reply #11
I have found out about zzz.
From the man page:
Code: [Select]
FILES
       /etc/zzz.d/*
           Hook scripts found in this directory are executed before/after the system is
           suspended/resumed by zzz.

       /etc/zzz.d/suspend/*
           Hook scripts found in this directory are executed before the system is suspended
           by zzz. This directory is supported for compatibility with zzz(8) on Void Linux.

       /etc/zzz.d/suspend/*
           Hook scripts found in this directory are executed after the system is resumed.
           This directory is supported for compatibility with zzz(8) on Void Linux.
[...]

I did not test hooks yet.

 

Re: Perform actions before/after hibernating/suspending with acpid

Reply #12
Artix runit has (a possibly slightly tweaked version of?) Void's zzz (the OG). It's a shell script that doesn't rely on runit being PID 1 and can be used on any init system.

The general solution to the question in the original post is making acpid call a tool that handles hooks, does the kind of extra setup Artist mentioned, then suspends, instead of just suspending through /sys/power/state. Like zzz (either implementation), pm-utils or loginctl suspend.



I found out that  I have elogind-daemon running and it is needed for Xorg I think, killing it kills the UI.
So I disabled acpid since I just press the power button and that is handled by the elogind-daemon process.

According to htop it is started by dinit so it is not clear.
There is no service:
Code: [Select]
dinitctl list | grep elogind

It's indeed needed for Xorg (Artix would need to patch it to use libseat instead of talking to elogind directly).

Elogind is started because of the /usr/share/dbus-1/system-services/org.freedesktop.login1.service file. If Xorg queries for {systemd-,e}logind's functions through the D-Bus (a kind of "message mailman") daemon and the init system hasn't started it yet, D-Bus will "helpfully" start another process that reads the contents of that file, then starts elogind on its own. When that middle process exits, htop and other tools will consider PID 1 (dinit, in your case) as the parent.

I'm oversimplifying a bit here, google about double-forking and reparenting to learn more.

Re: Perform actions before/after hibernating/suspending with acpid

Reply #13
I wanted to used acipd to run hooks.
At the moment since I do not close a lid or use other actions I do not need it.

I teste zzz hook it worked fine.

Code: [Select]
cat /etc/zzz.d/hook.sh
#!/bin/sh

case "$1" in
    pre)
    DISPLAY=:0 su -c 'playerctl pause' user
    # Lock the screen only when suspending since I have disk encryption no need after hibernating
    if [ "$ZZZ_MODE" = "suspend" ]; then
DISPLAY=:0 su -c '~/bin/lock-screen.sh' user &
fi
;;
post)

;;
esac

I am not sure about all the options here:
Quote
       The hook scripts are executed sequentially in alphabetic order with two arguments:

        1. “pre” (before suspend), or “post” (after resume),

        2. the same as ZZZ_MODE (see below).

       And the following environment variables:

       ZZZ_MODE
           The selected suspend mode; one of “hibernate”, “noop”, “standby”, or “suspend”.

       ZZZ_HIBERNATE_MODE
           The selected hibernate mode: “platform”, “reboot”, or “suspend”.

On Alpine I can run xorg without libseat/seatd and elogind, I do not know why.
They are not installed and there is no process.

zzz is in the AUR and it's quick to install:
Code: [Select]
aur/zzz 0.1.1-3 [installed] [2+] [0.00%] [11 Mar 2023]
    A simple program to suspend or hibernate your computer

Re: Perform actions before/after hibernating/suspending with acpid

Reply #14
I use a custom bash script just for my specific situation:

slep.sh