/
main.go
68 lines (57 loc) · 1.78 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
package main
import (
"flag"
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"runtime"
log "github.com/Sirupsen/logrus"
"k8s.io/kubernetes/pkg/util/logs"
"github.com/openshift/origin/pkg/cmd/dockerregistry"
cmdutil "github.com/openshift/origin/pkg/cmd/util"
"github.com/openshift/origin/pkg/cmd/util/serviceability"
// install all APIs
_ "github.com/openshift/origin/pkg/api/install"
_ "k8s.io/kubernetes/pkg/api/install"
_ "k8s.io/kubernetes/pkg/apis/extensions/install"
)
func main() {
logs.InitLogs()
defer logs.FlushLogs()
defer serviceability.BehaviorOnPanic(os.Getenv("OPENSHIFT_ON_PANIC"))()
defer serviceability.Profile(os.Getenv("OPENSHIFT_PROFILE")).Stop()
startProfiler()
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
// TODO convert to flags instead of a config file?
configurationPath := ""
if flag.NArg() > 0 {
configurationPath = flag.Arg(0)
}
if configurationPath == "" {
configurationPath = os.Getenv("REGISTRY_CONFIGURATION_PATH")
}
if configurationPath == "" {
fmt.Println("configuration path unspecified")
os.Exit(1)
}
// Prevent a warning about unrecognized environment variable
os.Unsetenv("REGISTRY_CONFIGURATION_PATH")
configFile, err := os.Open(configurationPath)
if err != nil {
log.Fatalf("Unable to open configuration file: %s", err)
}
dockerregistry.Execute(configFile)
}
func startProfiler() {
if cmdutil.Env("OPENSHIFT_PROFILE", "") == "web" {
go func() {
runtime.SetBlockProfileRate(1)
profilePort := cmdutil.Env("OPENSHIFT_PROFILE_PORT", "6060")
profileHost := cmdutil.Env("OPENSHIFT_PROFILE_HOST", "127.0.0.1")
log.Infof(fmt.Sprintf("Starting profiling endpoint at http://%s:%s/debug/pprof/", profileHost, profilePort))
log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%s", profileHost, profilePort), nil))
}()
}
}