v.0.9.6 : Add PID file

This commit is contained in:
yo
2021-01-26 14:19:33 +01:00
parent 700c7be116
commit fe39e4fdfd
+13 -1
View File
@@ -8,6 +8,9 @@
// returns : 200 google.com
//
// Use a single LDAP connection protected by a mutex
//
// v0.9.6 : add PID file
//
package main
@@ -23,10 +26,11 @@ import (
"github.com/go-ldap/ldap/v3"
"github.com/peterbourgon/ff"
"github.com/tabalt/pidfile"
)
const (
version = "0.9.5"
version = "0.9.6"
)
var (
@@ -41,6 +45,7 @@ var (
ldapPass *string
ldapAttr *string
defDomain *string
pidFilePath *string
)
func ldapSearch(searchReq *ldap.SearchRequest, attempt int) (*ldap.SearchResult, error) {
@@ -212,6 +217,7 @@ func main() {
ldapPass = fs.String("ldapPass", "", "LDAP user password (also via LDAPPASS env var)")
ldapAttr = fs.String("ldapAttr", "relayName", "LDAP attribute containing the relay name to return")
defDomain = fs.String("domain", "", "Domain to add to relay name if not a FQDN (also via DOMAIN env var)")
pidFilePath= fs.String("pidfile", "/var/run/mxrouter/mxrouter.pid", "PID File (also via PIDFILE env var)")
_ = fs.String("config", "", "config file (optional)")
// Surcharge de la fonction Usage()
@@ -227,6 +233,12 @@ func main() {
return
}
if pid, err := pidfile.Create(*pidFilePath); err != nil {
log.Fatal(err)
} else {
defer pid.Clear()
}
if logstream, e = syslog.New(syslog.LOG_MAIL, "mxrouter"); e != nil {
log.Fatal(e)
}