Debug worker
This commit is contained in:
@@ -21,13 +21,12 @@ type LDAPSearch struct {
|
|||||||
LDAPSearch *ldap.SearchResult
|
LDAPSearch *ldap.SearchResult
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectToLDAPServer(URL string, starttls bool, ignore_cert bool) (*LDAPServer, error) {
|
func connectToLDAPServer(URL string, starttls bool, ignore_cert bool) *LDAPServer {
|
||||||
logging.Debugf("Connecting to LDAP server %s", URL)
|
logging.Debugf("Connecting to LDAP server %s", URL)
|
||||||
l, err := ldap.DialURL(URL)
|
l, err := ldap.DialURL(URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Fatal("Failed to connect to LDAP server")
|
logging.Fatal("Failed to connect to LDAP server")
|
||||||
logging.Fatal(err.Error())
|
logging.Fatal(err.Error())
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
logging.Infof("Connected to LDAP server")
|
logging.Infof("Connected to LDAP server")
|
||||||
|
|
||||||
@@ -44,7 +43,7 @@ func connectToLDAPServer(URL string, starttls bool, ignore_cert bool) (*LDAPServ
|
|||||||
URL: URL,
|
URL: URL,
|
||||||
StartTLS: starttls,
|
StartTLS: starttls,
|
||||||
IgnoreInsecureCert: ignore_cert,
|
IgnoreInsecureCert: ignore_cert,
|
||||||
}, nil
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func reconnectToLDAPServer(server *LDAPServer) {
|
func reconnectToLDAPServer(server *LDAPServer) {
|
||||||
@@ -119,7 +118,11 @@ func modifyLDAPAttribute(server *LDAPServer, userDN string, attribute string, da
|
|||||||
|
|
||||||
func closeLDAPServer(server *LDAPServer) {
|
func closeLDAPServer(server *LDAPServer) {
|
||||||
if server != nil && server.Connection != nil {
|
if server != nil && server.Connection != nil {
|
||||||
server.Connection.Close()
|
logging.Debug("Closing connection to LDAP server")
|
||||||
|
err := server.Connection.Close()
|
||||||
|
if err != nil {
|
||||||
|
logging.Errorf("Failed to close LDAP server %s", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -321,13 +321,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ldapServerMutex.Lock()
|
ldapServerMutex.Lock()
|
||||||
server, err := connectToLDAPServer(serverConfig.LDAPConfig.LDAPURL, serverConfig.LDAPConfig.Security == "tls", serverConfig.LDAPConfig.IgnoreInvalidCert)
|
server := connectToLDAPServer(serverConfig.LDAPConfig.LDAPURL, serverConfig.LDAPConfig.Security == "tls", serverConfig.LDAPConfig.IgnoreInvalidCert)
|
||||||
ldapServer = server
|
ldapServer = server
|
||||||
ldapServerMutex.Unlock()
|
ldapServerMutex.Unlock()
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer closeLDAPServer(ldapServer)
|
defer closeLDAPServer(ldapServer)
|
||||||
|
|
||||||
createWorker(time.Minute*5, cleanupSessions)
|
createWorker(time.Minute*5, cleanupSessions)
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"astraltech.xyz/accountmanager/src/logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
func createWorker(interval time.Duration, task func()) {
|
func createWorker(interval time.Duration, task func()) {
|
||||||
|
logging.Debugf("Creating worker that runs on a %s interval", interval.String())
|
||||||
go func() {
|
go func() {
|
||||||
ticker := time.NewTicker(interval)
|
ticker := time.NewTicker(interval)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|||||||
Reference in New Issue
Block a user