9 "github.com/coreos/go-systemd/daemon"
13 httpServer *http.Server
16 eventSource *pgEventSource
20 func (srv *server) Close() {
22 srv.eventSource.Close()
26 func (srv *server) WaitReady() {
27 srv.setupOnce.Do(srv.setup)
28 srv.eventSource.WaitReady()
31 func (srv *server) Run() error {
32 srv.setupOnce.Do(srv.setup)
33 return srv.httpServer.Serve(srv.listener)
36 func (srv *server) setup() {
39 ln, err := net.Listen("tcp", srv.wsConfig.Listen)
41 log.WithField("Listen", srv.wsConfig.Listen).Fatal(err)
43 log.WithField("Listen", ln.Addr().String()).Info("listening")
46 srv.eventSource = &pgEventSource{
47 DataSource: srv.wsConfig.Postgres.ConnectionString(),
48 QueueSize: srv.wsConfig.ServerEventQueue,
50 srv.httpServer = &http.Server{
51 Addr: srv.wsConfig.Listen,
52 ReadTimeout: time.Minute,
53 WriteTimeout: time.Minute,
54 MaxHeaderBytes: 1 << 20,
57 eventSource: srv.eventSource,
58 newPermChecker: func() permChecker { return newPermChecker(srv.wsConfig.Client) },
64 log.Info("event source stopped")
68 if _, err := daemon.SdNotify(false, "READY=1"); err != nil {
69 log.WithError(err).Warn("error notifying init daemon")