Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aafeijoo-suse
Copy link
Member

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

Checklist

  • I have tested it locally
  • I have reviewed and updated any documentation if relevant
  • I am providing new code and test(s) for it

…dule

Introducing the systemd-battery-check module.
@github-actions github-actions bot added the modules Issue tracker for all modules label Jun 30, 2023
@aafeijoo-suse aafeijoo-suse marked this pull request as ready for review July 5, 2023 06:08
@LaszloGombos
Copy link
Collaborator

@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
  • plymouth module
  • HW and kernel module for /sys/class/power_supply/

@aafeijoo-suse
Copy link
Member Author

@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
Copy link
Collaborator

LaszloGombos commented Jul 7, 2023

* 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 #2332 (review)

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.

Copy link
Collaborator

@LaszloGombos LaszloGombos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@LaszloGombos LaszloGombos added this to the dracut-060 milestone Jul 30, 2023
@LaszloGombos LaszloGombos modified the milestones: dracut-060, dracut-061 Oct 30, 2023
@aafeijoo-suse aafeijoo-suse removed this from the dracut-061 milestone Nov 18, 2023
Copy link

stale bot commented Apr 22, 2024

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.

@stale stale bot added the stale communication is stuck label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modules Issue tracker for all modules stale communication is stuck
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants