This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
107 lines (92 loc) · 2.39 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"flag"
"net/url"
"os"
"os/signal"
"syscall"
"code.cloudfoundry.org/garden-windows/backend"
"code.cloudfoundry.org/garden-windows/dotnet"
"code.cloudfoundry.org/garden/server"
"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/lager/lagerflags"
"github.com/cloudfoundry/dropsonde"
)
var containerGraceTime = flag.Duration(
"containerGraceTime",
0,
"time after which to destroy idle containers",
)
var containerizerURL = flag.String(
"containerizerURL",
"http://127.0.0.1",
"URL for the Containerizer container server",
)
var dropsondeOrigin = flag.String(
"dropsondeOrigin",
"garden-windows",
"Origin identifier for dropsonde-emitted metrics.",
)
var dropsondeDestination = flag.String(
"dropsondeDestination",
"localhost:3457",
"Destination for dropsonde-emitted metrics.",
)
func initializeDropsonde(logger lager.Logger) {
err := dropsonde.Initialize(*dropsondeDestination, *dropsondeOrigin)
if err != nil {
logger.Error("failed to initialize dropsonde: %v", err)
}
}
func main() {
defaultListNetwork := "unix"
defaultListAddr := "/tmp/garden.sock"
if os.Getenv("PORT") != "" {
defaultListNetwork = "tcp"
defaultListAddr = "0.0.0.0:" + os.Getenv("PORT")
}
var listenNetwork = flag.String(
"listenNetwork",
defaultListNetwork,
"how to listen on the address (unix, tcp, etc.)",
)
var listenAddr = flag.String(
"listenAddr",
defaultListAddr,
"address to listen on",
)
lagerflags.AddFlags(flag.CommandLine)
flag.Parse()
logger, _ := lagerflags.New("garden-windows")
initializeDropsonde(logger)
url, err := url.Parse(*containerizerURL)
if err != nil {
logger.Fatal("Could not parse containerizer url", err, lager.Data{
"containerizerURL": containerizerURL,
})
}
client := dotnet.NewClient(logger, url)
netBackend, err := backend.NewDotNetBackend(client, logger, *containerGraceTime)
if err != nil {
logger.Fatal("Server Failed to Start", err)
os.Exit(1)
}
gardenServer := server.New(*listenNetwork, *listenAddr, *containerGraceTime, netBackend, logger)
err = gardenServer.Start()
if err != nil {
logger.Fatal("Server Failed to Start", err)
os.Exit(1)
}
logger.Info("started", lager.Data{
"network": *listenNetwork,
"addr": *listenAddr,
})
signals := make(chan os.Signal, 1)
go func() {
<-signals
gardenServer.Stop()
os.Exit(0)
}()
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
select {}
}