probe/main.go

86 lines
1.9 KiB
Go
Raw Normal View History

2018-04-12 11:54:56 +00:00
package main
import (
"context"
"flag"
"os"
"os/signal"
"syscall"
"time"
"git.loafle.net/commons/configuration-go"
2018-04-14 08:57:01 +00:00
cdr "git.loafle.net/commons/di-go/registry"
2018-04-12 11:54:56 +00:00
"git.loafle.net/commons/logging-go"
occi "git.loafle.net/overflow/commons-go/core/interfaces"
ocpc "git.loafle.net/overflow/commons-go/probe/config"
"git.loafle.net/overflow/probe/auth"
"git.loafle.net/overflow/probe/config"
)
var (
configDir *string
)
func init() {
configDir = flag.String("config-dir", "./", "Config directory")
logConfigPath := flag.String("log-config", "", "logging config path")
flag.Parse()
logging.InitializeLogger(*logConfigPath)
}
func main() {
_config := &config.Config{}
configuration.SetConfigPath(*configDir)
if err := configuration.Load(_config, ocpc.ConfigFileName); nil != err {
logging.Logger().Panic(err)
}
2018-04-14 08:57:01 +00:00
cdr.RegisterResource("Config", _config)
cdr.RegisterResource("ConfigDir", *configDir)
2018-04-12 11:54:56 +00:00
var instance interface{}
go func() {
if ocpc.ProbeStateTypeNotAuthorized == _config.Probe.State() {
instance = &auth.Authenticator{
ConfigDir: *configDir,
Config: _config,
}
doneChan, err := instance.(occi.EndableStarter).EndableStart()
if nil != err {
logging.Logger().Panic(err)
2018-04-14 08:57:01 +00:00
return
2018-04-12 11:54:56 +00:00
}
err = <-doneChan
if nil != err {
logging.Logger().Panic(err)
}
2018-04-14 08:57:01 +00:00
if err := instance.(occi.Stopper).Stop(context.Background()); err != nil {
logging.Logger().Errorf("error: %v", err)
}
2018-04-13 11:59:46 +00:00
2018-04-12 11:54:56 +00:00
}
// err := s.ListenAndServe()
// if nil != err {
// log.Printf("err: %v", err)
// }
}()
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 := instance.(occi.Stopper).Stop(ctx); err != nil {
logging.Logger().Errorf("error: %v", err)
}
}