Prevent temporally suspend/hibernate from script?
To prvent hibernation, create /var/run/do-not-hibernate
:
sudo touch /var/run/do-not-hibernate
The file /usr/lib/pm-utils/sleep.d/000kernel-change
makes this work. If you need to disable suspend, create a new file for that, say /etc/pm/sleep.d/000_prevent_suspend_hibernate
:
#!/bin/sh
# Prevents the machine from suspending or hibernating when
# the file /var/run/do-not-hibernate-or-suspend exist
case "$1" in
suspend|hibernate)
[ -f /var/run/do-not-hibernate-or-suspend ] && exit 1
;;
esac
Make it executable:
sudo chmod +x /etc/pm/sleep.d/000_prevent_suspend_hibernate
In case you need to prevent the machine from suspending or hibernating, create a file:
sudo touch /var/run/do-not-hibernate-or-suspend
After rebooting or removing this file, suspending and hibernating works again.