mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
Counters include: - Uptime - SMTP connections - SMTP connections (current) - SMTP messages delivered
63 lines
1.0 KiB
Go
63 lines
1.0 KiB
Go
/*
|
|
This is the inbucket daemon launcher
|
|
*/
|
|
package main
|
|
|
|
import (
|
|
"expvar"
|
|
"flag"
|
|
"fmt"
|
|
"github.com/jhillyerd/inbucket/config"
|
|
"github.com/jhillyerd/inbucket/log"
|
|
"github.com/jhillyerd/inbucket/smtpd"
|
|
"github.com/jhillyerd/inbucket/web"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
var help = flag.Bool("help", false, "Displays this help")
|
|
|
|
var startTime = time.Now()
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
if *help {
|
|
flag.Usage()
|
|
return
|
|
}
|
|
|
|
// Load & Parse config
|
|
if flag.NArg() != 1 {
|
|
flag.Usage()
|
|
os.Exit(1)
|
|
}
|
|
err := config.LoadConfig(flag.Arg(0))
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Failed to parse config: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Configure logging
|
|
level, _ := config.Config.String("logging", "level")
|
|
log.SetLogLevel(level)
|
|
|
|
// Startup SMTP server
|
|
server := smtpd.New()
|
|
go server.Start()
|
|
|
|
web.Start()
|
|
}
|
|
|
|
func init() {
|
|
flag.Usage = func() {
|
|
fmt.Fprintln(os.Stderr, "Usage of inbucket [options] <conf file>:")
|
|
flag.PrintDefaults()
|
|
}
|
|
|
|
expvar.Publish("uptime", expvar.Func(uptime))
|
|
}
|
|
|
|
func uptime() interface{} {
|
|
return time.Since(startTime) / time.Second
|
|
}
|