mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
Exit if there's an error reading users/aliases files on startup
Today, when starting up, if there's an error reading the users or aliases files, we only log but do not exit. And then those files will not be attempted to be read on the periodic reload. We also treat "file does not exist" as an error for users file, but not aliases file, resulting in inconsistent behaviour between the two. All of this makes some classes of problems (like permission errors) more difficult to spot and troubleshoot. For example, https://github.com/albertito/chasquid/issues/55. So this patch makes errors reading users/aliases files on startup a fatal error, and also unifies the "file does not exist" behaviour to make it not an error in both cases. Note that the behaviour on the periodic reload is unchanged: treat these errors as fatal too. This may be changed in future patches.
This commit is contained in:
17
chasquid.go
17
chasquid.go
@@ -27,7 +27,6 @@ import (
|
||||
"blitiri.com.ar/go/chasquid/internal/normalize"
|
||||
"blitiri.com.ar/go/chasquid/internal/smtpsrv"
|
||||
"blitiri.com.ar/go/chasquid/internal/sts"
|
||||
"blitiri.com.ar/go/chasquid/internal/userdb"
|
||||
"blitiri.com.ar/go/log"
|
||||
"blitiri.com.ar/go/systemd"
|
||||
)
|
||||
@@ -286,18 +285,18 @@ func loadDomain(name, dir string, s *smtpsrv.Server) {
|
||||
log.Infof(" %s", name)
|
||||
s.AddDomain(name)
|
||||
|
||||
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)
|
||||
err := s.AddUserDB(name, dir+"/users")
|
||||
if err != nil {
|
||||
// If there is an error loading users, fail hard to make sure this is
|
||||
// noticed and fixed as soon as it happens.
|
||||
log.Fatalf(" users file error: %v", err)
|
||||
}
|
||||
|
||||
err = s.AddAliasesFile(name, dir+"/aliases")
|
||||
if err != nil {
|
||||
log.Errorf(" aliases file error: %v", err)
|
||||
// If there's an error loading aliases, fail hard to make sure this is
|
||||
// noticed and fixed as soon as it happens.
|
||||
log.Fatalf(" aliases file error: %v", err)
|
||||
}
|
||||
|
||||
err = loadDKIM(name, dir, s)
|
||||
|
||||
Reference in New Issue
Block a user