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

mendersoftware / mender-server / 1600238645

23 Dec 2024 10:30AM UTC coverage: 76.615% (+3.8%) from 72.818%
1600238645

Pull #274

gitlab-ci

bahaa-ghazal
fix: implement signal handler for `server` commands

Changelog: Title
Ticket: QA-782
Signed-off-by: Bahaa Aldeen Ghazal <bahaa.ghazal@northern.tech>
Pull Request #274: fix: implement signal handler for `server` commands

4254 of 6166 branches covered (68.99%)

Branch coverage included in aggregate %.

63 of 91 new or added lines in 8 files covered. (69.23%)

46 existing lines in 5 files now uncovered.

45257 of 58457 relevant lines covered (77.42%)

21.82 hits per line

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

89.74
/backend/services/deviceconfig/server/server.go
1
// Copyright 2021 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/deviceconfig/api/http"
30
        "github.com/mendersoftware/mender-server/services/deviceconfig/app"
31
        "github.com/mendersoftware/mender-server/services/deviceconfig/client/workflows"
32
        . "github.com/mendersoftware/mender-server/services/deviceconfig/config"
33
        "github.com/mendersoftware/mender-server/services/deviceconfig/store"
34
)
35

36
// InitAndRun initializes the server and runs it
37
func InitAndRun(dataStore store.DataStore) error {
2✔
38
        ctx := context.Background()
2✔
39

2✔
40
        l := log.FromContext(ctx)
2✔
41
        wflows := workflows.NewClient(
2✔
42
                config.Config.GetString(SettingWorkflowsURL),
2✔
43
        )
2✔
44
        appl := app.New(
2✔
45
                dataStore, wflows, app.Config{
2✔
46
                        HaveAuditLogs: config.Config.GetBool(SettingEnableAudit),
2✔
47
                },
2✔
48
        )
2✔
49

2✔
50
        router := api.NewRouter(appl)
2✔
51

2✔
52
        var listen = config.Config.GetString(SettingListen)
2✔
53
        srv := &http.Server{
2✔
54
                Addr:    listen,
2✔
55
                Handler: router,
2✔
56
        }
2✔
57

2✔
58
        go func() {
4✔
59
                l.Infof("Server listening for connections on \"%s\"", listen)
2✔
60
                if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
2✔
61
                        l.Fatalf("listen: %s\n", err)
×
62
                }
×
63
        }()
64

65
        quit := make(chan os.Signal, 1)
2✔
66
        signal.Notify(quit, unix.SIGINT, unix.SIGTERM)
2✔
67
        <-quit
2✔
68

2✔
69
        l.Info("Server shutting down")
2✔
70

2✔
71
        ctxWithTimeout, cancel := context.WithTimeout(ctx, 10*time.Second)
2✔
72
        defer cancel()
2✔
73
        if err := srv.Shutdown(ctxWithTimeout); err != nil {
2✔
NEW
74
                l.Fatal("error when shutting down the server ", err)
×
NEW
75
        }
×
76

77
        l.Info("Server exited")
2✔
78
        return nil
2✔
79
}
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