8460: Retrieve recent logs and send old matching events if last_log_id given.
[arvados.git] / services / ws / main.go
1 package main
2
3 import (
4         "flag"
5         "fmt"
6         "log"
7         "net/http"
8         "time"
9
10         "git.curoverse.com/arvados.git/sdk/go/config"
11 )
12
13 func main() {
14         configPath := flag.String("config", "/etc/arvados/ws/ws.yml", "`path` to config file")
15         dumpConfig := flag.Bool("dump-config", false, "show current configuration and exit")
16         cfg := DefaultConfig()
17         flag.Parse()
18
19         err := config.LoadFile(&cfg, *configPath)
20         if err != nil {
21                 log.Fatal(err)
22         }
23         if !cfg.Debug {
24                 debugLogf = func(string, ...interface{}) {}
25         }
26
27         if *dumpConfig {
28                 txt, err := config.Dump(&cfg)
29                 if err != nil {
30                         log.Fatal(err)
31                 }
32                 fmt.Print(string(txt))
33                 return
34         }
35
36         eventSource := &pgEventSource{
37                 DataSource: cfg.Postgres.ConnectionString(),
38                 QueueSize:  cfg.ServerEventQueue,
39         }
40         srv := &http.Server{
41                 Addr:           cfg.Listen,
42                 ReadTimeout:    time.Minute,
43                 WriteTimeout:   time.Minute,
44                 MaxHeaderBytes: 1 << 20,
45                 Handler: &router{
46                         Config:      &cfg,
47                         eventSource: eventSource,
48                 },
49         }
50         eventSource.NewSink().Stop()
51
52         log.Printf("listening at %s", srv.Addr)
53         log.Fatal(srv.ListenAndServe())
54 }