33 lines
489 B
Go
33 lines
489 B
Go
|
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()
|
||
|
}
|