mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
Reopen logs on SIGHUP
This makes it possible to manage chasquid logs using logrotate. Amended-by: Alberto Bertogli <albertito@blitiri.com.ar> Added tests, minor style and comment changes.
This commit is contained in:
committed by
Alberto Bertogli
parent
ade107f62e
commit
db810084a0
30
chasquid.go
30
chasquid.go
@@ -14,8 +14,10 @@ import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"blitiri.com.ar/go/chasquid/internal/config"
|
||||
@@ -90,6 +92,8 @@ func main() {
|
||||
|
||||
initMailLog(conf.MailLogPath)
|
||||
|
||||
go signalHandler()
|
||||
|
||||
if conf.MonitoringAddress != "" {
|
||||
launchMonitoringServer(conf.MonitoringAddress)
|
||||
}
|
||||
@@ -224,6 +228,32 @@ func initMailLog(path string) {
|
||||
}
|
||||
}
|
||||
|
||||
func signalHandler() {
|
||||
var err error
|
||||
|
||||
signals := make(chan os.Signal, 1)
|
||||
signal.Notify(signals, syscall.SIGHUP)
|
||||
|
||||
for {
|
||||
switch sig := <-signals; sig {
|
||||
case syscall.SIGHUP:
|
||||
// SIGHUP triggers a reopen of the log files. This is used for log
|
||||
// rotation.
|
||||
err = log.Default.Reopen()
|
||||
if err != nil {
|
||||
log.Fatalf("Error reopening log: %v", err)
|
||||
}
|
||||
|
||||
err = maillog.Default.Reopen()
|
||||
if err != nil {
|
||||
log.Fatalf("Error reopening maillog: %v", err)
|
||||
}
|
||||
default:
|
||||
log.Errorf("Unexpected signal %v", sig)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to load a single domain configuration into the server.
|
||||
func loadDomain(name, dir string, s *smtpsrv.Server) {
|
||||
log.Infof(" %s", name)
|
||||
|
||||
Reference in New Issue
Block a user