• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-server / 1495380963

14 Oct 2024 03:35PM UTC coverage: 70.373% (-2.5%) from 72.904%
1495380963

Pull #101

gitlab-ci

mineralsfree
feat: tenant list added

Ticket: MEN-7568
Changelog: None

Signed-off-by: Mikita Pilinka <mikita.pilinka@northern.tech>
Pull Request #101: feat: tenant list added

4406 of 6391 branches covered (68.94%)

Branch coverage included in aggregate %.

88 of 183 new or added lines in 10 files covered. (48.09%)

2623 existing lines in 65 files now uncovered.

36673 of 51982 relevant lines covered (70.55%)

31.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/backend/services/deviceconnect/server/server.go
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
package server
16

17
import (
18
        "context"
19
        "net/http"
20
        "os"
21
        "os/signal"
22
        "time"
23

24
        "golang.org/x/sys/unix"
25

26
        "github.com/mendersoftware/mender-server/pkg/config"
27
        "github.com/mendersoftware/mender-server/pkg/log"
28

29
        api "github.com/mendersoftware/mender-server/services/deviceconnect/api/http"
30
        "github.com/mendersoftware/mender-server/services/deviceconnect/app"
31
        "github.com/mendersoftware/mender-server/services/deviceconnect/client/nats"
32
        "github.com/mendersoftware/mender-server/services/deviceconnect/client/workflows"
33
        dconfig "github.com/mendersoftware/mender-server/services/deviceconnect/config"
34
        "github.com/mendersoftware/mender-server/services/deviceconnect/store"
35
)
36

37
// InitAndRun initializes the server and runs it
UNCOV
38
func InitAndRun(conf config.Reader, dataStore store.DataStore) error {
×
UNCOV
39
        ctx := context.Background()
×
UNCOV
40

×
UNCOV
41
        log.Setup(conf.GetBool(dconfig.SettingDebugLog))
×
UNCOV
42
        l := log.FromContext(ctx)
×
UNCOV
43

×
UNCOV
44
        allowedOrigin := conf.GetStringSlice(dconfig.SettingWSAllowedOrigins)
×
UNCOV
45
        if allowedOrigin != nil {
×
UNCOV
46
                api.SetAcceptedOrigins(allowedOrigin)
×
UNCOV
47
        }
×
48

UNCOV
49
        natsClient, err := nats.NewClientWithDefaults(
×
UNCOV
50
                config.Config.GetString(dconfig.SettingNatsURI),
×
UNCOV
51
        )
×
UNCOV
52
        if err != nil {
×
53
                return err
×
54
        }
×
UNCOV
55
        wflows := workflows.NewClient(
×
UNCOV
56
                config.Config.GetString(dconfig.SettingWorkflowsURL),
×
UNCOV
57
        )
×
UNCOV
58
        deviceConnectApp := app.New(
×
UNCOV
59
                dataStore, wflows, app.Config{
×
UNCOV
60
                        HaveAuditLogs: conf.GetBool(dconfig.SettingEnableAuditLogs),
×
UNCOV
61
                },
×
UNCOV
62
        )
×
UNCOV
63

×
UNCOV
64
        gracefulShutdownTimeout := conf.GetDuration(dconfig.SettingGracefulShutdownTimeout)
×
UNCOV
65
        router, err := api.NewRouter(deviceConnectApp, natsClient, &api.RouterConfig{
×
UNCOV
66
                GracefulShutdownTimeout: gracefulShutdownTimeout,
×
UNCOV
67
        })
×
UNCOV
68
        if err != nil {
×
69
                l.Fatal(err)
×
70
        }
×
71

UNCOV
72
        var listen = conf.GetString(dconfig.SettingListen)
×
UNCOV
73
        srv := &http.Server{
×
UNCOV
74
                Addr:    listen,
×
UNCOV
75
                Handler: router,
×
UNCOV
76
        }
×
UNCOV
77

×
UNCOV
78
        go func() {
×
UNCOV
79
                if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
×
80
                        l.Fatalf("listen: %s\n", err)
×
81
                }
×
82
        }()
83

UNCOV
84
        quit := make(chan os.Signal, 1)
×
UNCOV
85
        signal.Notify(quit, unix.SIGINT, unix.SIGTERM, unix.SIGUSR1)
×
UNCOV
86
        recvSignal := <-quit
×
UNCOV
87

×
UNCOV
88
        l.Info("server shutdown")
×
UNCOV
89

×
UNCOV
90
        if recvSignal == unix.SIGUSR1 {
×
91
                l.Info("received SIGUSR1, graceful shutdown")
×
92
                srv.RegisterOnShutdown(func() {
×
93
                        deviceConnectApp.Shutdown(gracefulShutdownTimeout)
×
94
                })
×
95
        }
96

UNCOV
97
        ctxWithTimeout, cancel := context.WithTimeout(ctx, 5*time.Second)
×
UNCOV
98
        defer cancel()
×
UNCOV
99
        if err := srv.Shutdown(ctxWithTimeout); err != nil {
×
100
                l.Fatal("error when shutting down the server ", err)
×
101
        }
×
UNCOV
102
        l.Info("server exited")
×
UNCOV
103

×
UNCOV
104
        if recvSignal == unix.SIGUSR1 {
×
105
                deviceConnectApp.ShutdownDone()
×
106
                l.Info("graceful shutdown completed")
×
107
        }
×
108

UNCOV
109
        return nil
×
110
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc