//go:build unix
package main
import (
"os"
"syscall"
)
// deployRunning reports whether scripts/deploy.sh holds its lock: the
// script keeps an exclusive flock on the file for the whole deploy and
// the kernel drops it with the process, so a shared non-blocking lock
// failing means a deploy is running. A file that cannot be opened is
// no deploy.
func deployRunning(path string) bool {
f, err := os.Open(path)
if err != nil {
return false
}
defer f.Close()
if err := syscall.Flock(int(f.Fd()), syscall.LOCK_SH|syscall.LOCK_NB); err != nil {
return err == syscall.EWOULDBLOCK
}
syscall.Flock(int(f.Fd()), syscall.LOCK_UN)
return false
}