1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "github.com/coreos/go-systemd/daemon"
17 httpServer *http.Server
20 eventSource *pgEventSource
24 func (srv *server) Close() {
26 srv.eventSource.Close()
30 func (srv *server) WaitReady() {
31 srv.setupOnce.Do(srv.setup)
32 srv.eventSource.WaitReady()
35 func (srv *server) Run() error {
36 srv.setupOnce.Do(srv.setup)
37 return srv.httpServer.Serve(srv.listener)
40 func (srv *server) setup() {
43 ln, err := net.Listen("tcp", srv.wsConfig.Listen)
45 log.WithField("Listen", srv.wsConfig.Listen).Fatal(err)
47 log.WithField("Listen", ln.Addr().String()).Info("listening")
50 srv.eventSource = &pgEventSource{
51 DataSource: srv.wsConfig.Postgres.String(),
52 MaxOpenConns: srv.wsConfig.PostgresPool,
53 QueueSize: srv.wsConfig.ServerEventQueue,
55 srv.httpServer = &http.Server{
56 Addr: srv.wsConfig.Listen,
57 ReadTimeout: time.Minute,
58 WriteTimeout: time.Minute,
59 MaxHeaderBytes: 1 << 20,
62 eventSource: srv.eventSource,
63 newPermChecker: func() permChecker { return newPermChecker(srv.wsConfig.Client) },
69 log.Info("event source stopped")
73 if _, err := daemon.SdNotify(false, "READY=1"); err != nil {
74 log.WithError(err).Warn("error notifying init daemon")