make certdb maintain go routine a own func

This commit is contained in:
6543 2021-12-05 17:44:10 +01:00
parent de439f9bec
commit a0e0d2d335
No known key found for this signature in database
GPG key ID: C99B82E40B027BAE
2 changed files with 64 additions and 71 deletions

View file

@ -109,6 +109,9 @@ func Serve(ctx *cli.Context) error {
certificates.SetupCertificates(mainDomainSuffix, dnsProvider, acmeConfig, acmeUseRateLimits, enableHTTPServer, challengeCache, keyDatabase)
// TODO: make it graceful
go certificates.MaintainCertDB(mainDomainSuffix, dnsProvider, acmeUseRateLimits, keyDatabase)
if enableHTTPServer {
go func() {
err := httpServer.ListenAndServe("[::]:80")

View file

@ -444,18 +444,9 @@ func SetupCertificates(mainDomainSuffix []byte, dnsProvider string, acmeConfig *
log.Printf("[ERROR] Couldn't renew main domain certificate, continuing with mock certs only: %s", err)
}
}
}
go (func() {
for {
err := keyDatabase.Sync()
if err != nil {
log.Printf("[ERROR] Syncing key database failed: %s", err)
}
time.Sleep(5 * time.Minute)
// TODO: graceful exit
}
})()
go (func() {
func MaintainCertDB(mainDomainSuffix []byte, dnsProvider string, acmeUseRateLimits bool, keyDatabase database.CertDB) {
for {
// clean up expired certs
now := time.Now()
@ -514,5 +505,4 @@ func SetupCertificates(mainDomainSuffix []byte, dnsProvider string, acmeConfig *
time.Sleep(12 * time.Hour)
}
})()
}