-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.go
51 lines (43 loc) · 1.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2022 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Polyform License
// that can be found in the LICENSE file.
package main
import (
"runtime"
_ "github.com/harness/godotenv/v3/autoload"
"github.com/harness/harness-docker-runner/cli"
"github.com/kardianos/service"
)
func main() {
if runtime.GOOS == "windows" {
svcConfig := &service.Config{
Name: "harness-docker-runner-svc",
DisplayName: "harness-docker-runner-svc",
Description: "This is a service runing for harness-docker-runner",
}
runAsService(svcConfig, func() {
cli.Command()
})
} else {
cli.Command()
}
}
func runAsService(svcConfig *service.Config, run func()) error {
s, err := service.New(&program{exec: run}, svcConfig)
if err != nil {
return err
}
return s.Run()
}
type program struct {
exec func()
}
func (p *program) Start(s service.Service) error {
// Start should not block. Do the actual work async.
go p.exec()
return nil
}
func (p *program) Stop(s service.Service) error {
// Stop should not block. Return with a few seconds.
return nil
}