Temporarily prevent linux from shutting down

前端 未结 6 2087
暖寄归人
暖寄归人 2021-01-11 14:06

I have a backup script that runs in the background daily on my linux (Fedora 9) computer. If the computer is shut down while the backup is in progress the backup may be dama

6条回答
  •  萌比男神i
    2021-01-11 14:26

    But a script that would remind me (or another user) that the backup is still running when I choose shut down from the Gnome/GDM menus

    One may use polkit to completely block shutdown/restart - but I failed to find method that would provide a clear response why it is blocked.

    Adding the following lines as /etc/polkit-1/localauthority/50-local.d/restrict-login-powermgmt.pkla works:

    [Disable lightdm PowerMgmt]
    Identity=unix-user:*
    Action=org.freedesktop.login1.reboot;org.freedesktop.login1.reboot-multiple-sessions;org.freedesktop.login1.power-off;org.freedesktop.login1.power-off-multiple-sessions;org.freedesktop.login1.suspend;org.freedesktop.login1.suspend-multiple-sessions;org.freedesktop.login1.hibernate;org.freedesktop.login1.hibernate-multiple-sessions
    ResultAny=no
    ResultInactive=no
    ResultActive=no
    

    You still see a confirmation dialog but there are not buttons to confirm. Looks ugly, but works ;)

    Unfortunately this applies to all users, not only the lightdm session, so you have to add a second rule to white-list them if desired.

    Note that this method block solely reboot/etc commands issued from GUI. To block reboot/etc commands from command line one may use molly-guard - as explained in https://askubuntu.com/questions/17187/disabling-shutdown-command-for-all-users-even-root-consequences/17255#17255

提交回复
热议问题