-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-socket-proxy.go
58 lines (47 loc) · 1000 Bytes
/
docker-socket-proxy.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
package main
import (
"log"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/stensonb/docker-socket-proxy/lib/proxyHandler"
"github.com/stensonb/docker-socket-proxy/lib/socketListener"
)
var sl socketListener.SocketListener
var ph proxyHandler.ProxyHandler
func main() {
handleSigterm()
var err error
ph, err = proxyHandler.New()
if err != nil {
log.Fatal(err)
}
sl, err := socketListener.New()
if err != nil {
log.Fatal(err)
}
if err := http.Serve(sl, ph.Handler()); err != nil {
log.Fatal(err)
}
}
func shutdownNicely() {
if err := sl.Cleanup(); err != nil {
log.Println(err)
}
if err := ph.Cleanup(); err != nil {
log.Println(err)
}
}
// handleSigterm does stuff
func handleSigterm() {
// make sure we cleanup on exit
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, os.Interrupt, os.Kill, syscall.SIGTERM)
go func(c chan os.Signal) {
sig := <-c
log.Printf("Caught signal %s: shutting down.\n", sig)
shutdownNicely()
os.Exit(0)
}(sigc)
}