git » chasquid » commit b9e222f

chasquid: Remove unnecessary logging on loading aliases and users on startup

author Alberto Bertogli
2023-09-17 09:46:41 UTC
committer Alberto Bertogli
2023-09-17 09:54:49 UTC
parent 2c02f0d1281e9c723303bce72fe2bab246d75257

chasquid: Remove unnecessary logging on loading aliases and users on startup

When starting up, for each domain we parse aliases and users files (if
they exist).

Today we print a line for each, which gets quite verbose and doesn't
offer much useful information.

This patch adjusts that logic so that we only print errors (unless a
file does not exist, which is a normal case).

This also improves the scenario where chasquid does not have permissions
to access the users file: before this patch, that would fail silently,
but with this patch we show the correct error.

While at it, make the "Loading" messages consistent with each other, for
readability.

chasquid.go +11 -13

diff --git a/chasquid.go b/chasquid.go
index 1bd7356..c1ade7d 100644
--- a/chasquid.go
+++ b/chasquid.go
@@ -90,7 +90,7 @@ func main() {
 
 	// Load certificates from "certs/<directory>/{fullchain,privkey}.pem".
 	// The structure matches letsencrypt's, to make it easier for that case.
-	log.Infof("Loading certificates")
+	log.Infof("Loading certificates:")
 	for _, info := range mustReadDir("certs/") {
 		if info.Type().IsRegular() {
 			// Ignore regular files, we only care about directories.
@@ -121,7 +121,7 @@ func main() {
 	}
 
 	// Load domains from "domains/".
-	log.Infof("Domain config paths:")
+	log.Infof("Loading domains:")
 	for _, info := range mustReadDir("domains/") {
 		domain, err := normalize.Domain(info.Name())
 		if err != nil {
@@ -270,20 +270,18 @@ func loadDomain(name, dir string, s *smtpsrv.Server) {
 	log.Infof("  %s", name)
 	s.AddDomain(name)
 
-	if _, err := os.Stat(dir + "/users"); err == nil {
-		log.Infof("    adding users")
-		udb, err := userdb.Load(dir + "/users")
-		if err != nil {
-			log.Errorf("      error: %v", err)
-		} else {
-			s.AddUserDB(name, udb)
-		}
+	udb, err := userdb.Load(dir + "/users")
+	if os.IsNotExist(err) {
+		// No users file present, that's okay.
+	} else if err != nil {
+		log.Errorf("    users file error: %v", err)
+	} else {
+		s.AddUserDB(name, udb)
 	}
 
-	log.Infof("    adding aliases")
-	err := s.AddAliasesFile(name, dir+"/aliases")
+	err = s.AddAliasesFile(name, dir+"/aliases")
 	if err != nil {
-		log.Errorf("      error: %v", err)
+		log.Errorf("    aliases file error: %v", err)
 	}
 }