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

mendersoftware / deviceconfig / 938999487

pending completion
938999487

push

gitlab-ci

web-flow
Merge pull request #151 from lluiscampos/chore-update-dind

ci: Update Docker-inDocker service images to latest

1257 of 1378 relevant lines covered (91.22%)

10.71 hits per line

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

84.62
/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
        "github.com/mendersoftware/go-lib-micro/config"
25
        "github.com/mendersoftware/go-lib-micro/log"
26
        "golang.org/x/sys/unix"
27

28
        api "github.com/mendersoftware/deviceconfig/api/http"
29
        "github.com/mendersoftware/deviceconfig/app"
30
        "github.com/mendersoftware/deviceconfig/client/workflows"
31
        . "github.com/mendersoftware/deviceconfig/config"
32
        "github.com/mendersoftware/deviceconfig/store"
33
)
34

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

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

1✔
49
        router := api.NewRouter(appl)
1✔
50

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

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

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

1✔
68
        l.Info("Server shutting down")
1✔
69

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

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