clustvirt/daemon/main.go

33 lines
489 B
Go
Raw Normal View History

2024-03-30 02:05:51 +00:00
package daemon
import (
"fmt"
"os"
"git.staur.ca/stobbsm/clustvirt/lib/log"
)
// path to store the PID, configurable
var RunPath string
var PIDFile string
func init() {
// set the RunPath to store the PID
RunPath = `/run/`
PIDFile = RunPath + `clustvirt.pid`
}
func Start() {
pid := pid()
if err := os.WriteFile(PIDFile, []byte(fmt.Sprint(pid)), 0666); err != nil {
log.Error("daemon.Start").
Err(err).
Send()
os.Exit(1)
}
}
func pid() int {
return os.Getpid()
}