Merge branch '10846-nodemanager-errors' closes #10846
[arvados.git] / services / ws / main.go
index c83f8d956a814e77c3255b13ba26ce4078df2f89..9eee8130af9d9b4b8fe831aa48865f5abd64808f 100644 (file)
@@ -7,13 +7,18 @@ import (
        "time"
 
        "git.curoverse.com/arvados.git/sdk/go/config"
-       log "github.com/Sirupsen/logrus"
+       "git.curoverse.com/arvados.git/sdk/go/ctxlog"
+       "github.com/coreos/go-systemd/daemon"
 )
 
+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)
@@ -21,24 +26,8 @@ func main() {
                log.Fatal(err)
        }
 
-       lvl, err := log.ParseLevel(cfg.LogLevel)
-       if err != nil {
-               log.Fatal(err)
-       }
-       log.SetLevel(lvl)
-       switch cfg.LogFormat {
-       case "text":
-               log.SetFormatter(&log.TextFormatter{
-                       FullTimestamp:   true,
-                       TimestampFormat: time.RFC3339Nano,
-               })
-       case "json":
-               log.SetFormatter(&log.JSONFormatter{
-                       TimestampFormat: time.RFC3339Nano,
-               })
-       default:
-               log.WithField("LogFormat", cfg.LogFormat).Fatal("unknown log format")
-       }
+       ctxlog.SetLevel(cfg.LogLevel)
+       ctxlog.SetFormat(cfg.LogFormat)
 
        if *dumpConfig {
                txt, err := config.Dump(&cfg)
@@ -49,6 +38,7 @@ func main() {
                return
        }
 
+       log.Info("started")
        eventSource := &pgEventSource{
                DataSource: cfg.Postgres.ConnectionString(),
                QueueSize:  cfg.ServerEventQueue,
@@ -59,11 +49,20 @@ 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) },
                },
        }
-       eventSource.NewSink().Stop()
+
+       go func() {
+               eventSource.Run()
+               log.Fatal("event source stopped")
+       }()
+
+       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())