dracutdevs / dracut

dracut the event driven initramfs infrastructure
https://github.com/dracutdevs/dracut/wiki
GNU General Public License v2.0
598 stars 397 forks source link

feat(systemd-battery-check): introducing the systemd-battery-check module #2419

Open aafeijoo-suse opened 1 year ago

aafeijoo-suse commented 1 year ago

See https://github.com/systemd/systemd/blob/main/man/systemd-battery-check.service.xml

Checklist

LaszloGombos commented 1 year ago

@aafeijoo-suse how have you tested this dracut module ?

From a quick look it seems this module requires quite a lot of things to work

aafeijoo-suse commented 1 year ago

@aafeijoo-suse how have you tested this dracut module ?

From a quick look it seems this module requires quite a lot of things to work

* recent version of systemd

~30s to compile the main branch.

~/src/systemd/upstream-fork/main> time ( meson setup build &>/dev/null && ninja -C build &>/dev/null )

real    0m33.890s
user    5m27.098s
sys 0m50.014s
~/src/systemd/upstream-fork/main> ./build/systemd-battery-check --version
systemd 254 (254~rc1-9-g9cf2203)
+PAM +AUDIT +SELINUX +APPARMOR +IMA +SMACK -SECCOMP -GCRYPT +GNUTLS +OPENSSL -ACL +BLKID +CURL -ELFUTILS +FIDO2 +IDN2 -IDN -IPTC +KMOD +LIBCRYPTSETUP -LIBFDISK -PCRE2 -PWQUALITY +P11KIT -QRENCODE +TPM2 +BZIP2 -LZ4 +XZ +ZLIB +ZSTD -BPF_FRAMEWORK -XKBCOMMON +UTMP +SYSVINIT default-hierarchy=unified
* plymouth module

I haven't added plymouth as a dependency because it also works without it.

~/src/systemd/upstream-fork/main> SYSTEMD_LOG_LEVEL=debug build/systemd-battery-check
AC: The power supply is currently offline.
BAT0: The power supply is a battery and currently discharging.
port0: The USB type-C port is in power source mode.
port1: The USB type-C port is in power source mode.
port2: The USB type-C port is in power source mode.
ucsi-source-psy-USBC000:001: All USB type-C ports are in power source mode.
ucsi-source-psy-USBC000:001: USB power supply is in source mode, ignoring device.
port0: The USB type-C port is in power source mode.
port1: The USB type-C port is in power source mode.
port2: The USB type-C port is in power source mode.
ucsi-source-psy-USBC000:002: All USB type-C ports are in power source mode.
ucsi-source-psy-USBC000:002: USB power supply is in source mode, ignoring device.
port0: The USB type-C port is in power source mode.
port1: The USB type-C port is in power source mode.
port2: The USB type-C port is in power source mode.
ucsi-source-psy-USBC000:003: All USB type-C ports are in power source mode.
ucsi-source-psy-USBC000:003: USB power supply is in source mode, ignoring device.
Found at least one discharging battery and no online power sources, assuming system is running from battery.
🪫 Battery level critically low. Please connect your charger or the system will power off in 10 seconds.
Failed to connect to plymouth: Connection refused
AC: The power supply is currently offline.
BAT0: The power supply is a battery and currently discharging.
port0: The USB type-C port is in power source mode.
port1: The USB type-C port is in power source mode.
port2: The USB type-C port is in power source mode.
ucsi-source-psy-USBC000:001: All USB type-C ports are in power source mode.
ucsi-source-psy-USBC000:001: USB power supply is in source mode, ignoring device.
port0: The USB type-C port is in power source mode.
port1: The USB type-C port is in power source mode.
port2: The USB type-C port is in power source mode.
ucsi-source-psy-USBC000:002: All USB type-C ports are in power source mode.
ucsi-source-psy-USBC000:002: USB power supply is in source mode, ignoring device.
port0: The USB type-C port is in power source mode.
port1: The USB type-C port is in power source mode.
port2: The USB type-C port is in power source mode.
ucsi-source-psy-USBC000:003: All USB type-C ports are in power source mode.
ucsi-source-psy-USBC000:003: USB power supply is in source mode, ignoring device.
Found at least one discharging battery and no online power sources, assuming system is running from battery.
Battery level critically low, powering off.
~/src/systemd/upstream-fork/main> echo $?
1
* HW and kernel module for /sys/class/power_supply/

My hw from the emergency shell of any standard SUSE distro:

sh-4.4# ls -l /sys/class/power_supply/
total 0
lrwxrwxrwx 1 root root 0 Jul  7 07:19 AC -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:1e/PNP0C09:00/ACPI0003:00/power_supply/AC
lrwxrwxrwx 1 root root 0 Jul  7 07:19 BAT0 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:1e/PNP0C09:00/PNP0C0A:00/power_supply/BAT0
lrwxrwxrwx 1 root root 0 Jul  7 07:19 ucsi-source-psy-USBC000:001 -> ../../devices/platform/USBC000:00/power_supply/ucsi-source-psy-USBC000:001
lrwxrwxrwx 1 root root 0 Jul  7 07:19 ucsi-source-psy-USBC000:002 -> ../../devices/platform/USBC000:00/power_supply/ucsi-source-psy-USBC000:002
lrwxrwxrwx 1 root root 0 Jul  7 07:19 ucsi-source-psy-USBC000:003 -> ../../devices/platform/USBC000:00/power_supply/ucsi-source-psy-USBC000:003

Yes, we may specify here the required kernel drivers, but the systemd-ac-power module does not specify them either, so I followed the same approach.

LaszloGombos commented 1 year ago
* plymouth module

I haven't added plymouth as a dependency because it also works without it.

🪫 Battery level critically low. Please connect your charger or the system will power off in 10 seconds. Failed to connect to plymouth: Connection refused

Thanks for these details. I also think not requiring plymouth is OK, but just wondering how and when would the user see why the system did not boot (so that the user can then take an action), if the system simply just shuts down on low battery.

We had similar related discussion at https://github.com/dracutdevs/dracut/pull/2332#pullrequestreview-1421858018

I think it is ok to shutdown the device even if the user is not properly informed, but we should continue to discuss how can we inform the user.

* HW and kernel module for /sys/class/power_supply/

Yes, we may specify here the required kernel drivers, but the systemd-ac-power module does not specify them either, so I followed the same approach.

We can optimize the module later with follow-up PRs. One idea could be that in hostonly mode it might make sense to check for /sys/class/power_supply/ like it is done in the bluetooth module to optimize initramfs size and boot time.

stale[bot] commented 4 months ago

This issue is being marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. If this is still an issue in the latest release of Dracut and you would like to keep it open please comment on this issue within the next 7 days. Thank you for your contributions.