Skip to content

add Suspend (suspend to ram) to ShutdownModal and power button#23113

Open
macpaul wants to merge 6 commits intocockpit-project:mainfrom
macpaul:macpaul/suspend-to-ram
Open

add Suspend (suspend to ram) to ShutdownModal and power button#23113
macpaul wants to merge 6 commits intocockpit-project:mainfrom
macpaul:macpaul/suspend-to-ram

Conversation

@macpaul
Copy link
Copy Markdown

@macpaul macpaul commented Apr 9, 2026

Add a suspend function to shutdown and power button.
This is useful for some home sever you just want it to suspend a while for saving power.
My next plan is to add a wake-up suspend to this if the commits have been accepted.
Thanks

Macpaul Lin added 6 commits April 9, 2026 22:09
Add a new 'suspend' prop to the ShutdownModal component to support
suspending the system in addition to reboot and poweroff.

When suspend mode is active:
- Modal title changes to 'Suspend to RAM'
- Submit button text changes to 'Suspend'
- Immediate suspend uses 'systemctl suspend'
- Delayed suspend uses 'systemd-run --unit=cockpit-suspend
  --on-active=Nm systemctl suspend' to create a transient timer
  that survives cockpit restarts
- The message field is kept with a note that it has no effect
  for suspend operations, since wall(1) is not called during suspend

The existing reboot/poweroff code paths are unchanged.

Signed-off-by: Macpaul Lin <macpaul.lin@gmail.com>
Add a 'Suspend' option to the system overview shutdown dropdown and a
corresponding status card for scheduled suspends.

overview.jsx:
- Check logind CanSuspend() via D-Bus on mount; only show 'Suspend'
  dropdown item when the hardware/kernel supports it (returns 'yes'
  or 'challenge')
- Wire the 'Suspend' item to ShutdownModal with the new suspend prop

shutdownStatus.tsx:
- Add SuspendStatus component that detects an active cockpit-suspend
  transient timer via 'systemctl is-active cockpit-suspend.timer'
- Display 'Scheduled suspend at <time>' with a MoonIcon in the
  Health card
- Provide a 'Cancel suspend' button that stops the timer unit
- Poll every 5 seconds since transient timers have no reliable
  file-watch equivalent unlike /run/systemd/shutdown/scheduled

shutdownStatus.scss:
- Add .suspend-status-icon colour rule alongside the existing
  shutdown/reboot icon styles

healthCard.tsx:
- Import and render the new SuspendStatus component after ShutDownStatus

Signed-off-by: Macpaul Lin <macpaul.lin@gmail.com>
Verify that the suspend status banner in the Health card works
end-to-end:
- Schedule a suspend via systemd-run --unit=cockpit-suspend
  --on-active=10m to mimic what the cockpit UI does
- Wait for the SuspendStatus component to detect the timer
  (polls every 5 seconds) and show 'Scheduled suspend' text
- Reload the page and confirm the banner persists
- Cancel via the UI cancel button and confirm the banner disappears
- Assert that the cockpit-suspend.timer unit is no longer active

Signed-off-by: Macpaul Lin <macpaul.lin@gmail.com>
Add two new test methods to a new TestSuspendDialog class:

testSuspendDialogBasic:
- Open the shutdown dropdown and click 'Suspend'
- Verify the dialog title is 'Suspend to RAM'
- Verify the submit button text is 'Suspend'
- Verify the helper note about the message field is shown
- Test delay option selection

testSuspendDelayed:
- Select a 5-minute delay and submit the suspend dialog
- Verify that systemd-run created the cockpit-suspend.timer unit

Both tests mock /usr/local/bin/systemctl to intercept the 'suspend'
subcommand so the test VM is not actually suspended.

Signed-off-by: Macpaul Lin <macpaul.lin@gmail.com>
Two bugs found during integration testing:

1. shutdownStatus.tsx: Fix fallback text from 'Suspend scheduled'
   to 'Scheduled suspend' for consistency with 'Scheduled reboot'
   and 'Scheduled poweroff' patterns. Also move the element id
   'system-health-suspend-status-text' to a <span> wrapping only
   the text, so the cancel button text is not included in the
   selector's text content.

2. check-system-shutdown-restart: Replace locale-sensitive
   text selectors ('button:contains(5 minutes)') with
   position-based nth-child selectors that work correctly
   regardless of the UI language (test VM uses Traditional
   Chinese locale for translated strings).

Signed-off-by: Macpaul Lin <macpaul.lin@gmail.com>
On Ubuntu hosts, the autotools Makefile generated by the tasks
container uses Fedora paths (e.g. /usr/sbin/mkdir) which are not
present on Ubuntu. This causes `make dist` to fail when running
test/image-prepare directly on the host.

Add tools/make-dist-cached, a thin wrapper that returns the paths of
already-built source tarballs (previously created inside the toolbox
via tools/make-dist). Update test/image-prepare to use this wrapper
so that image-prepare can be run on the Ubuntu host, which is needed
to get KVM access via the host libvirt (the toolbox qemu does not
expose the KVM virt type to its session libvirt driver).

Signed-off-by: Macpaul Lin <macpaul.lin@gmail.com>
@Venefilyn Venefilyn self-requested a review April 14, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant