overflow_probes/main.go
crusader 1b8ee93026 ing
2017-09-29 21:30:27 +09:00

142 lines
3.9 KiB
Go

package main
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"path"
"syscall"
"time"
lfcc "git.loafle.net/commons_go/config"
"git.loafle.net/commons_go/logging"
"git.loafle.net/overflow/overflow_probes/auth"
"git.loafle.net/overflow/overflow_probes/commons"
"git.loafle.net/overflow/overflow_probes/config"
"git.loafle.net/overflow/overflow_probes/probe"
)
/*
/bin/
probe.exe
/config/
/sensor/
noauthprobe.json
central.json
probe.json
logging.json
*/
// const (
// // name of the service
// serviceName = "Probe"
// serviceDescription = "Probe Service of overFlow"
// )
var (
daemonCommand *string
configDir *string
)
func init() {
// flag.Usage = func() {
// fmt.Printf("Usage of %s\n", os.Args[0])
// fmt.Printf(" [install | remove | start | stop | status]\n")
// flag.PrintDefaults()
// }
configDir = flag.String("config-dir", ".", "The directory of config")
flag.Parse()
}
func main() {
var err error
var handler commons.Handler
defer logging.Logger.Sync()
printBanner()
if dir, err := lfcc.ABSPathify(*configDir); nil != err {
logging.Logger.Panic(fmt.Sprintf("Probe: config path[%s] is not valid", *configDir))
} else {
logging.Logger.Debug(fmt.Sprintf("Probe: config path[%s]", dir))
config.ConfigDir = &dir
}
cfp := path.Join(*config.ConfigDir, config.ConfigFileName)
config.ConfigFilePath = &cfp
conf := lfcc.New()
config.CFG = &config.Config{}
if err := conf.Load(config.CFG, *config.ConfigFilePath); nil != err {
logging.Logger.Panic(fmt.Sprintf("Probe: config is not valid error[%v]", err))
}
go func() {
if handler, err = auth.New(); nil != err {
logging.Logger.Error(fmt.Sprintf("Auth: error: %v", err))
return
}
if err := handler.Serve(); err != nil {
logging.Logger.Error(fmt.Sprintf("Auth: Stopped[%v]", err))
return
}
if handler, err = probe.New(); nil != err {
logging.Logger.Error(fmt.Sprintf("Probe: error: %v", err))
return
}
if err := handler.Serve(); err != nil {
logging.Logger.Error(fmt.Sprintf("Probe: error: %v", err))
return
}
}()
// // Set up channel on which to send signal notifications.
// // We must use a buffered channel or risk missing the signal
// // if we're not ready to receive when the signal is sent.
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt,
syscall.SIGKILL,
syscall.SIGSTOP,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
<-interrupt
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := handler.Shutdown(ctx); err != nil {
logging.Logger.Error(fmt.Sprintf("Probe error: %v", err))
}
}
const (
version = "1.0.0"
website = "https://www.overflow.cloud"
banner = `
██████╗ ██╗ ██╗███████╗██████╗ ███████╗██╗ ██████╗ ██╗ ██╗
██╔═══██╗██║ ██║██╔════╝██╔══██╗██╔════╝██║ ██╔═══██╗██║ ██║
██║ ██║██║ ██║█████╗ ██████╔╝█████╗ ██║ ██║ ██║██║ █╗ ██║
██║ ██║╚██╗ ██╔╝██╔══╝ ██╔══██╗██╔══╝ ██║ ██║ ██║██║███╗██║
╚██████╔╝ ╚████╔╝ ███████╗██║ ██║██║ ███████╗╚██████╔╝╚███╔███╔╝
╚═════╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚══════╝ ╚═════╝ ╚══╝╚══╝
`
)
func printBanner() {
fmt.Println(banner)
fmt.Printf("Version: %s\n", version)
fmt.Printf("URL: %s\n", website)
fmt.Println()
}