Skip to content

Commit be199d6

Browse files
committed
updated
1 parent a520788 commit be199d6

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

sleep.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package bash
2+
3+
import "os/exec"
4+
5+
type SystemSleepLock struct {
6+
cmd *exec.Cmd
7+
}
8+
9+
// SleepLock prevents the system from sleeping by using systemd-inhibit
10+
func SleepLock() *SystemSleepLock {
11+
cmd := exec.Command(`/usr/bin/systemd-inhibit`, `--who=Special Modifications Installer`, `--why=Installing Packages`, `--what=sleep:idle`, `bash`, `-c`, `while true; do sleep 1000; done`)
12+
cmd.Start()
13+
return &SystemSleepLock{cmd: cmd}
14+
}
15+
16+
// Release releases the sleep lock
17+
func (lock *SystemSleepLock) Release() {
18+
lock.cmd.Process.Kill()
19+
}

0 commit comments

Comments
 (0)