-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
106 lines (71 loc) · 2.92 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
package main
import (
"os"
"strconv"
"time"
"github.com/30x/kiln/pkg/kiln"
"github.com/30x/kiln/pkg/server"
)
// This file was generated by the swagger tool.
// Make sure not to overwrite this file after you generated it because all your edits would be lost!
func main() {
kiln.LogInfo.Printf("Starting server configuration and validation...")
portString := os.Getenv("PORT")
if portString == "" {
kiln.LogError.Fatal("You must specifiy the PORT environment variable")
}
port, err := strconv.Atoi(portString)
if err != nil {
kiln.LogError.Fatal("You must specify a valid integer for the PORT value")
}
kiln.LogInfo.Printf("PORT accepted: %d", port)
timeoutString := os.Getenv("SHUTDOWN_TIMEOUT")
if timeoutString == "" {
kiln.LogError.Fatal("You must specifiy the SHUTDOWN_TIMEOUT environment variable")
}
timeout, err := strconv.Atoi(timeoutString)
if err != nil {
kiln.LogError.Fatal("You must specify a valid integer for the SHUTDOWN_TIMEOUT value")
}
kiln.LogInfo.Printf("SHUTDOWN_TIMEOUT accepted: %d", timeout)
imageCreator, err := kiln.NewImageCreatorFromEnv()
//we should die here if we're unable to start
if err != nil {
kiln.LogError.Fatalf("Unable to create image creator %s", err)
}
kiln.LogInfo.Printf("ImageCreator set up.")
clusterConfig, err := kiln.NewClusterConfigFromEnv()
if err != nil {
kiln.LogError.Fatalf("Unable to get cluster config: %s", err)
}
kiln.LogInfo.Printf("ClusterConfig set up.")
//start the reaper process in the background
if os.Getenv("NO_REAP") == "" {
reaperIntervalString := os.Getenv("REAP_INTERVAL")
if reaperIntervalString == "" {
kiln.LogError.Fatal("You must specifiy the REAP_INTERVAL environment variable")
}
reaperInterval, err := strconv.Atoi(reaperIntervalString)
if err != nil {
kiln.LogError.Fatal("You must specify a valid integer for the REAP_INTERVAL value")
}
kiln.LogInfo.Printf("REAP_INTERVAL accepted: %d", reaperInterval)
reaperMinAgeString := os.Getenv("REAP_MIN_AGE")
if reaperMinAgeString == "" {
kiln.LogError.Fatal("You must specifiy the REAP_MIN_AGE environment variable")
}
reaperMinAge, err := strconv.Atoi(reaperMinAgeString)
if err != nil {
kiln.LogError.Fatal("You must specify a valid integer for the REAP_MIN_AGE value")
}
kiln.LogInfo.Printf("REAP_MIN_AGE accepted: %d", reaperMinAge)
minTime := time.Duration(reaperMinAge) * time.Second
reapInterval := time.Duration(reaperInterval) * time.Second
kiln.LogInfo.Printf("Starting background reaper process. Reper will remove images older than %f second, and will run every %f seconds ", minTime.Seconds(), reapInterval.Seconds())
//start the reap interval
go kiln.ReapForever(minTime, imageCreator, reapInterval)
}
kiln.LogInfo.Printf("Successfully configured server and validated configuration. Starting server.")
server := server.NewServer(imageCreator, clusterConfig)
server.Start(port, time.Duration(timeout)*time.Second)
}