-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
64 lines (54 loc) · 1.53 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
package main
import (
"fmt"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/opts"
flag "github.com/docker/docker/pkg/mflag"
"github.com/hustcat/docker-graph-driver/api"
"github.com/hustcat/docker-graph-driver/driver"
"os"
)
const (
socketAddress = "/run/docker/plugins/rbd.sock"
)
var (
root string
graphDriver string
graphOptions []string
flDebug bool
flLogLevel string
)
func init() {
installFlags()
}
func installFlags() {
flag.BoolVar(&flDebug, []string{"D", "-debug"}, false, "Enable debug mode")
flag.StringVar(&flLogLevel, []string{"l", "-log-level"}, "info", "Set the logging level")
flag.StringVar(&root, []string{"g", "-graph"}, "/var/lib/docker", "Path to use as the root of the graph driver")
opts.ListVar(&graphOptions, []string{"-storage-opt"}, "Set storage driver options")
flag.StringVar(&graphDriver, []string{"s", "-storage-driver"}, "", "Force the runtime to use a specific storage driver")
}
func main() {
flag.Parse()
if flLogLevel != "" {
lvl, err := logrus.ParseLevel(flLogLevel)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to parse logging level: %s\n", flLogLevel)
os.Exit(1)
}
logrus.SetLevel(lvl)
} else {
logrus.SetLevel(logrus.InfoLevel)
}
if flDebug {
logrus.SetLevel(logrus.DebugLevel)
}
driver, err := graphdriver.New(root, graphOptions)
if err != nil {
logrus.Errorf("Create rbd driver failed: %v", err)
os.Exit(1)
}
h := api.NewHandler(driver)
logrus.Infof("listening on %s\n", socketAddress)
fmt.Println(h.ServeUnix("root", socketAddress))
}