Dont create pidfile if not defined

This commit is contained in:
yo 2022-05-17 11:43:36 +02:00
parent a84e22ce61
commit 28dd17ccee

View File

@ -26,7 +26,7 @@ import (
)
const (
version = "1.0.0-rc2"
version = "1.0.0-rc3"
)
var (
@ -301,7 +301,7 @@ func connectLdap() (*ldap.Conn, error) {
}
err = conLdap.Bind(*ldapUser, *ldapPass)
if err != nil {
logstream.Errorf("Error binding LDAP: ", err)
logstream.Errorf("Error binding LDAP: %s", err)
return conLdap, err
}
return conLdap, err
@ -349,7 +349,7 @@ func main() {
ldapBaseDN = fs.String("ldapDN", "", "LDAP base DN (also via LDAPDN env var)")
ldapUser = fs.String("ldapUser", "", "LDAP user DN (also via LDAPUSER env var)")
ldapPass = fs.String("ldapPass", "", "LDAP user password (also via LDAPPASS env var)")
pidFilePath = fs.String("pidfile", "/var/run/mynettcptable/mynettcptable.pid", "PID File (also via PIDFILE env var)")
pidFilePath = fs.String("pidfile", "", "PID File (also via PIDFILE env var). Creates pidfile only if defined")
refreshInterval = fs.Int("refresh", 300, "Net cache update interval in seconds")
timeout = fs.Int("timeout", 5, "timeout in seconds")
_ = fs.String("config", "", "config file (optional)")
@ -403,10 +403,12 @@ func main() {
logstream.Hooks.Add(hook)
}
if pid, err := pidfile.Create(*pidFilePath); err != nil {
logstream.Fatal(err)
} else {
defer pid.Clear()
if len(pidfile) > 0 {
if pid, err := pidfile.Create(*pidFilePath); err != nil {
logstream.Fatal(err)
} else {
defer pid.Clear()
}
}
logstream.Infof("Start listening for incoming connections on %s\n", *listen)