mirror of
https://github.com/mjl-/mox.git
synced 2024-12-26 08:23:48 +03:00
merge start.go into serve.go
This commit is contained in:
parent
44a3f9b1bc
commit
9e280221b6
2 changed files with 54 additions and 64 deletions
54
serve.go
54
serve.go
|
@ -19,14 +19,21 @@ import (
|
|||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
|
||||
"github.com/mjl-/mox/dmarcdb"
|
||||
"github.com/mjl-/mox/dns"
|
||||
"github.com/mjl-/mox/dnsbl"
|
||||
"github.com/mjl-/mox/http"
|
||||
"github.com/mjl-/mox/imapserver"
|
||||
"github.com/mjl-/mox/message"
|
||||
"github.com/mjl-/mox/metrics"
|
||||
"github.com/mjl-/mox/mlog"
|
||||
"github.com/mjl-/mox/mox-"
|
||||
"github.com/mjl-/mox/moxvar"
|
||||
"github.com/mjl-/mox/mtastsdb"
|
||||
"github.com/mjl-/mox/queue"
|
||||
"github.com/mjl-/mox/smtpserver"
|
||||
"github.com/mjl-/mox/store"
|
||||
"github.com/mjl-/mox/tlsrptdb"
|
||||
"github.com/mjl-/mox/updates"
|
||||
)
|
||||
|
||||
|
@ -545,3 +552,50 @@ func fixperms(log *mlog.Log, workdir, configdir, datadir string, moxuid, moxgid
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// start initializes all packages, starts all listeners and the switchboard
|
||||
// goroutine, then returns.
|
||||
func start(mtastsdbRefresher, skipForkExec bool) error {
|
||||
smtpserver.Listen()
|
||||
imapserver.Listen()
|
||||
http.Listen()
|
||||
|
||||
if !skipForkExec {
|
||||
// If we were just launched as root, fork and exec as unprivileged user, handing
|
||||
// over the bound sockets to the new process. We'll get to this same code path
|
||||
// again, skipping this if block, continuing below with the actual serving.
|
||||
if os.Getuid() == 0 {
|
||||
mox.ForkExecUnprivileged()
|
||||
panic("cannot happen")
|
||||
} else {
|
||||
mox.CleanupPassedSockets()
|
||||
}
|
||||
}
|
||||
|
||||
if err := dmarcdb.Init(); err != nil {
|
||||
return fmt.Errorf("dmarc init: %s", err)
|
||||
}
|
||||
|
||||
if err := mtastsdb.Init(mtastsdbRefresher); err != nil {
|
||||
return fmt.Errorf("mtasts init: %s", err)
|
||||
}
|
||||
|
||||
if err := tlsrptdb.Init(); err != nil {
|
||||
return fmt.Errorf("tlsrpt init: %s", err)
|
||||
}
|
||||
|
||||
done := make(chan struct{}, 1)
|
||||
if err := queue.Start(dns.StrictResolver{Pkg: "queue"}, done); err != nil {
|
||||
return fmt.Errorf("queue start: %s", err)
|
||||
}
|
||||
|
||||
store.StartAuthCache()
|
||||
smtpserver.Serve()
|
||||
imapserver.Serve()
|
||||
http.Serve()
|
||||
|
||||
go func() {
|
||||
<-store.Switchboard()
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
|
64
start.go
64
start.go
|
@ -1,64 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/mjl-/mox/dmarcdb"
|
||||
"github.com/mjl-/mox/dns"
|
||||
"github.com/mjl-/mox/http"
|
||||
"github.com/mjl-/mox/imapserver"
|
||||
"github.com/mjl-/mox/mox-"
|
||||
"github.com/mjl-/mox/mtastsdb"
|
||||
"github.com/mjl-/mox/queue"
|
||||
"github.com/mjl-/mox/smtpserver"
|
||||
"github.com/mjl-/mox/store"
|
||||
"github.com/mjl-/mox/tlsrptdb"
|
||||
)
|
||||
|
||||
// start initializes all packages, starts all listeners and the switchboard
|
||||
// goroutine, then returns.
|
||||
func start(mtastsdbRefresher, skipForkExec bool) error {
|
||||
smtpserver.Listen()
|
||||
imapserver.Listen()
|
||||
http.Listen()
|
||||
|
||||
if !skipForkExec {
|
||||
// If we were just launched as root, fork and exec as unprivileged user, handing
|
||||
// over the bound sockets to the new process. We'll get to this same code path
|
||||
// again, skipping this if block, continuing below with the actual serving.
|
||||
if os.Getuid() == 0 {
|
||||
mox.ForkExecUnprivileged()
|
||||
panic("cannot happen")
|
||||
} else {
|
||||
mox.CleanupPassedSockets()
|
||||
}
|
||||
}
|
||||
|
||||
if err := dmarcdb.Init(); err != nil {
|
||||
return fmt.Errorf("dmarc init: %s", err)
|
||||
}
|
||||
|
||||
if err := mtastsdb.Init(mtastsdbRefresher); err != nil {
|
||||
return fmt.Errorf("mtasts init: %s", err)
|
||||
}
|
||||
|
||||
if err := tlsrptdb.Init(); err != nil {
|
||||
return fmt.Errorf("tlsrpt init: %s", err)
|
||||
}
|
||||
|
||||
done := make(chan struct{}, 1)
|
||||
if err := queue.Start(dns.StrictResolver{Pkg: "queue"}, done); err != nil {
|
||||
return fmt.Errorf("queue start: %s", err)
|
||||
}
|
||||
|
||||
store.StartAuthCache()
|
||||
smtpserver.Serve()
|
||||
imapserver.Serve()
|
||||
http.Serve()
|
||||
|
||||
go func() {
|
||||
<-store.Switchboard()
|
||||
}()
|
||||
return nil
|
||||
}
|
Loading…
Reference in a new issue