Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app.go
diff options
context:
space:
mode:
authorJacob Vosmaer (GitLab) <jacob@gitlab.com>2018-04-23 18:00:24 +0300
committerNick Thomas <nick@gitlab.com>2018-04-23 18:00:24 +0300
commitfd06fc02844a15bfaa78502f6b7c36588f66cd42 (patch)
tree65bf11c76d4ab6b09f7cbf9dee088e980bcec7c9 /app.go
parentc2fb2a8f8aa79e390b920f7b7c061e2951e69566 (diff)
Add gRPC admin health check
Diffstat (limited to 'app.go')
-rw-r--r--app.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/app.go b/app.go
index 0403d028..a785a383 100644
--- a/app.go
+++ b/app.go
@@ -2,8 +2,10 @@ package main
import (
"crypto/tls"
+ "fmt"
"net"
"net/http"
+ "os"
"strconv"
"strings"
"sync"
@@ -15,6 +17,7 @@ import (
"github.com/rs/cors"
log "github.com/sirupsen/logrus"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/admin"
"gitlab.com/gitlab-org/gitlab-pages/internal/artifact"
"gitlab.com/gitlab-org/gitlab-pages/internal/domain"
"gitlab.com/gitlab-org/gitlab-pages/internal/httperrors"
@@ -217,11 +220,63 @@ func (a *theApp) Run() {
}(a.ListenMetrics)
}
+ a.listenAdminUnix(&wg)
+ a.listenAdminHTTPS(&wg)
+
go domain.Watch(a.Domain, a.UpdateDomains, time.Second)
wg.Wait()
}
+func (a *theApp) listenAdminUnix(wg *sync.WaitGroup) {
+ fd := a.ListenAdminUnix
+ if fd == 0 {
+ return
+ }
+
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+
+ l, err := net.FileListener(os.NewFile(fd, "[admin-socket-unix]"))
+ if err != nil {
+ fatal(fmt.Errorf("failed to listen on FD %d: %v", fd, err))
+ }
+ defer l.Close()
+
+ if err := admin.NewServer(string(a.AdminToken)).Serve(l); err != nil {
+ fatal(err)
+ }
+ }()
+}
+
+func (a *theApp) listenAdminHTTPS(wg *sync.WaitGroup) {
+ fd := a.ListenAdminHTTPS
+ if fd == 0 {
+ return
+ }
+
+ cert, err := tls.X509KeyPair(a.AdminCertificate, a.AdminKey)
+ if err != nil {
+ fatal(err)
+ }
+
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+
+ l, err := net.FileListener(os.NewFile(fd, "[admin-socket-https]"))
+ if err != nil {
+ fatal(fmt.Errorf("failed to listen on FD %d: %v", fd, err))
+ }
+ defer l.Close()
+
+ if err := admin.NewTLSServer(string(a.AdminToken), &cert).Serve(l); err != nil {
+ fatal(err)
+ }
+ }()
+}
+
func runApp(config appConfig) {
a := theApp{appConfig: config}