Skip to content

Commit 81d19ad

Browse files
authored
Merge pull request moby#3545 from gabriel-samfira/add-windows-service-support
[Windows] Add Windows service support
2 parents 2c2b779 + d826beb commit 81d19ad

File tree

10 files changed

+1435
-0
lines changed

10 files changed

+1435
-0
lines changed

cmd/buildkitd/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ func main() {
198198
},
199199
)
200200
app.Flags = append(app.Flags, appFlags...)
201+
app.Flags = append(app.Flags, serviceFlags()...)
201202

202203
app.Action = func(c *cli.Context) error {
203204
// TODO: On Windows this always returns -1. The actual "are you admin" check is very Windows-specific.
@@ -253,6 +254,15 @@ func main() {
253254
return errors.Wrapf(err, "failed to create %s", root)
254255
}
255256

257+
// Stop if we are registering or unregistering against Windows SCM.
258+
stop, err := registerUnregisterService(cfg.Root)
259+
if err != nil {
260+
logrus.Fatal(err)
261+
}
262+
if stop {
263+
return nil
264+
}
265+
256266
lockPath := filepath.Join(root, "buildkitd.lock")
257267
lock := flock.New(lockPath)
258268
locked, err := lock.TryLock()
@@ -290,6 +300,12 @@ func main() {
290300
}
291301
}
292302
}
303+
304+
// Launch as a Windows Service if necessary
305+
if err := launchService(server); err != nil {
306+
logrus.Fatal(err)
307+
}
308+
293309
errCh := make(chan error, 1)
294310
if err := serveGRPC(cfg.GRPC, server, errCh); err != nil {
295311
return err
@@ -485,6 +501,8 @@ func applyMainFlags(c *cli.Context, cfg *config.Config) error {
485501
if tlsca := c.String("tlscacert"); tlsca != "" {
486502
cfg.GRPC.TLS.CA = tlsca
487503
}
504+
applyPlatformFlags(c)
505+
488506
return nil
489507
}
490508

cmd/buildkitd/service_unix.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package main
5+
6+
import (
7+
"github.com/urfave/cli"
8+
"google.golang.org/grpc"
9+
)
10+
11+
// serviceFlags returns an array of flags for configuring buildkitd to run
12+
// as a service. Only relevant on Windows.
13+
func serviceFlags() []cli.Flag {
14+
return []cli.Flag{}
15+
}
16+
17+
// applyPlatformFlags applies platform-specific flags.
18+
func applyPlatformFlags(context *cli.Context) {
19+
}
20+
21+
// registerUnregisterService is only relevant on Windows.
22+
func registerUnregisterService(root string) (bool, error) {
23+
return false, nil
24+
}
25+
26+
// launchService is only relevant on Windows.
27+
func launchService(s *grpc.Server) error {
28+
return nil
29+
}

0 commit comments

Comments
 (0)