From fe39e4fdfd171c43747c907af92b8813553e8678 Mon Sep 17 00:00:00 2001 From: yo Date: Tue, 26 Jan 2021 14:19:33 +0100 Subject: [PATCH] v.0.9.6 : Add PID file --- mxrouter.go | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/mxrouter.go b/mxrouter.go index 571c858..9e0d210 100644 --- a/mxrouter.go +++ b/mxrouter.go @@ -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,24 +26,26 @@ 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 ( - logstream *syslog.Writer - conLdap *ldap.Conn - mutex sync.Mutex - debug *bool - listen *string - ldapURL *string - ldapBaseDN *string - ldapUser *string - ldapPass *string - ldapAttr *string - defDomain *string + logstream *syslog.Writer + conLdap *ldap.Conn + mutex sync.Mutex + debug *bool + listen *string + ldapURL *string + ldapBaseDN *string + ldapUser *string + 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) }