systemd-inhibit

Prohibit the system from entering certain power states. Inhibitor locks may be used to block or delay system sleep and shutdown requests as well as automatic idle handling. More information: https://www.freedesktop.org/software/systemd/man/systemd-inhibit.html.

systemd-inhibit --list

systemd-inhibit --what shutdown sleep 5

systemd-inhibit --what sleep:idle wget https://example.com/file

systemd-inhibit --what sleep:handle-lid-switch path/to/script

systemd-inhibit --what handle-power-key command

systemd-inhibit --who $USER --why reason --what operation command