X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/104b2b5a46844e94a37c332b4ddd5a861dd8d63d..066f9bcf5a74c255cb64cf89e554cf64ec719f5a:/services/ws/main.go diff --git a/services/ws/main.go b/services/ws/main.go index 28662440d0..7c3625bdad 100644 --- a/services/ws/main.go +++ b/services/ws/main.go @@ -3,28 +3,31 @@ package main import ( "flag" "fmt" - "log" "net/http" "time" "git.curoverse.com/arvados.git/sdk/go/config" + "git.curoverse.com/arvados.git/sdk/go/ctxlog" + "github.com/coreos/go-systemd/daemon" ) -var debugLogf = func(string, ...interface{}) {} +var logger = ctxlog.FromContext func main() { + log := logger(nil) + configPath := flag.String("config", "/etc/arvados/ws/ws.yml", "`path` to config file") dumpConfig := flag.Bool("dump-config", false, "show current configuration and exit") - cfg := DefaultConfig() + cfg := defaultConfig() flag.Parse() err := config.LoadFile(&cfg, *configPath) if err != nil { log.Fatal(err) } - if cfg.Debug { - debugLogf = log.Printf - } + + ctxlog.SetLevel(cfg.LogLevel) + ctxlog.SetFormat(cfg.LogFormat) if *dumpConfig { txt, err := config.Dump(&cfg) @@ -35,9 +38,10 @@ func main() { return } + log.Info("started") eventSource := &pgEventSource{ - PgConfig: cfg.Postgres, - QueueSize: cfg.ServerEventQueue, + DataSource: cfg.Postgres.ConnectionString(), + QueueSize: cfg.ServerEventQueue, } srv := &http.Server{ Addr: cfg.Listen, @@ -45,10 +49,19 @@ func main() { WriteTimeout: time.Minute, MaxHeaderBytes: 1 << 20, Handler: &router{ - Config: &cfg, - eventSource: eventSource, + Config: &cfg, + eventSource: eventSource, + newPermChecker: func() permChecker { return newPermChecker(cfg.Client) }, }, } + // Bootstrap the eventSource by attaching a dummy subscriber + // and hanging up. eventSource.NewSink().Stop() + + if _, err := daemon.SdNotify(false, "READY=1"); err != nil { + log.WithError(err).Warn("error notifying init daemon") + } + + log.WithField("Listen", srv.Addr).Info("listening") log.Fatal(srv.ListenAndServe()) }