-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (57 loc) · 1.67 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
package main
import (
"flag"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/influxtsdb/influxdb-admin/admin"
)
var (
config admin.Config
version = "unknown"
commit = "unknown"
build = "unknown"
)
func init() {
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
log.SetOutput(os.Stdout)
flag.StringVar(&config.BindAddress, "bind-address", ":8083", "The default bind address used by the admin service")
flag.BoolVar(&config.HTTPSEnabled, "https-enabled", false, "Whether the admin service should use HTTPS")
flag.StringVar(&config.HTTPSCertificate, "https-certificate", "", "The SSL certificate used when HTTPS is enabled")
flag.Parse()
}
func main() {
log.Printf("InfluxDB admin version: %s, commit: %s, build: %s", version, commit, build)
config.Version = version
srv := admin.NewService(config)
if err := srv.Open(); err != nil {
log.Printf("Open admin service error: %s\n", err)
return
}
closed := make(chan struct{})
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
log.Print("Listening for signals")
// Block until one of the signals above is received
<-signalCh
log.Print("Signal received, initializing clean shutdown...")
go func() {
defer close(closed)
if srv != nil {
srv.Close()
}
}()
// Block again until another signal is received, a shutdown timeout elapses,
// or the Command is gracefully closed
log.Print("Waiting for clean shutdown...")
select {
case <-signalCh:
log.Print("Second signal received, initializing hard shutdown")
case <-time.After(time.Second * 30):
log.Print("Time limit reached, initializing hard shutdown")
case <-closed:
log.Print("Server shutdown completed")
}
}