1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.arvados.org/arvados.git/sdk/go/arvados"
14 "github.com/coreos/go-systemd/daemon"
18 httpServer *http.Server
20 cluster *arvados.Cluster
21 eventSource *pgEventSource
25 func (srv *server) Close() {
27 srv.eventSource.Close()
31 func (srv *server) WaitReady() {
32 srv.setupOnce.Do(srv.setup)
33 srv.eventSource.WaitReady()
36 func (srv *server) Run() error {
37 srv.setupOnce.Do(srv.setup)
38 return srv.httpServer.Serve(srv.listener)
41 func (srv *server) setup() {
44 var listen arvados.URL
45 for listen, _ = range srv.cluster.Services.Websocket.InternalURLs {
48 ln, err := net.Listen("tcp", listen.Host)
50 log.WithField("Listen", listen).Fatal(err)
52 log.WithField("Listen", ln.Addr().String()).Info("listening")
54 client := arvados.Client{}
55 client.APIHost = srv.cluster.Services.Controller.ExternalURL.Host
56 client.AuthToken = srv.cluster.SystemRootToken
57 client.Insecure = srv.cluster.TLS.Insecure
60 srv.eventSource = &pgEventSource{
61 DataSource: srv.cluster.PostgreSQL.Connection.String(),
62 MaxOpenConns: srv.cluster.PostgreSQL.ConnectionPool,
63 QueueSize: srv.cluster.API.WebsocketServerEventQueue,
66 srv.httpServer = &http.Server{
68 ReadTimeout: time.Minute,
69 WriteTimeout: time.Minute,
70 MaxHeaderBytes: 1 << 20,
74 eventSource: srv.eventSource,
75 newPermChecker: func() permChecker { return newPermChecker(client) },
81 log.Info("event source stopped")
85 if _, err := daemon.SdNotify(false, "READY=1"); err != nil {
86 log.WithError(err).Warn("error notifying init daemon")