blob: bb0086cfe1149262d42fd9dee60ec84b13017de8 (
plain)
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
|
package main
import (
"log"
"net"
"net/http"
"os"
"github.com/kelseyhightower/envconfig"
"github.com/prometheus/client_golang/prometheus/promhttp"
"gitlab.com/gitlab-org/gitaly/internal/router"
)
type Config struct {
SocketPath string `split_words:"true"`
PrometheusListenAddr string `split_words:"true"`
}
func main() {
config := Config{}
err := envconfig.Process("gitaly", &config)
if err != nil {
log.Fatal(err)
}
if config.SocketPath == "" {
log.Fatal("GITALY_SOCKET_PATH environment variable is not set")
}
if err := os.Remove(config.SocketPath); err != nil && !os.IsNotExist(err) {
log.Fatal(err)
}
listener, err := net.Listen("unix", config.SocketPath)
if err != nil {
log.Fatal(err)
}
log.Println("Listening on socket", config.SocketPath)
serverError := make(chan error, 2)
go func() {
serverError <- http.Serve(listener, router.NewRouter())
}()
if config.PrometheusListenAddr != "" {
promMux := http.NewServeMux()
promMux.Handle("/metrics", promhttp.Handler())
go func() {
http.ListenAndServe(config.PrometheusListenAddr, promMux)
}()
}
log.Fatal(<-serverError)
}
|