-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
81 lines (64 loc) · 1.95 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"flag"
"fmt"
"os"
"strconv"
"time"
log "github.com/Sirupsen/logrus"
"github.com/docker/go-plugins-helpers/volume"
)
var (
root = flag.String("root", "", "Base directory where volumes are created in the cluster")
debug = flag.Bool("debug", true, "Enable verbose logging")
hostname = flag.String("hostname", "", "The hostname used in locking operations")
lockInterval = 20 * time.Second
lockTimeout = 60 * time.Second
cleanupInterval = 60 * time.Minute
defaultProtected = false
defaultExclusive = false
)
func main() {
parseEnvironment()
flag.Parse()
if *debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
if *hostname == "" {
*hostname, _ = os.Hostname()
}
log.Debugf("Starting with hostname=%s; root=%s", *hostname, *root)
// userID, _ := user.Lookup("root")
// groupID, _ := strconv.Atoi(userID.Gid)
driver := newSharedFSDriver(*root)
handler := volume.NewHandler(driver)
fmt.Println(handler.ServeUnix("sharedfs", 0))
}
func parseEnvironment() {
value := os.Getenv("SFS_DEBUG")
if parsedBool, err := strconv.ParseBool(value); err == nil {
*debug = parsedBool
}
value = os.Getenv("SFS_LOCK_INTERVAL")
if parsedInt, err := strconv.ParseInt(value, 10, 32); err == nil {
lockInterval = time.Duration(parsedInt) * time.Second
}
value = os.Getenv("SFS_LOCK_TIMEOUT")
if parsedInt, err := strconv.ParseInt(value, 10, 32); err == nil {
lockTimeout = time.Duration(parsedInt) * time.Second
}
value = os.Getenv("SFS_CLEANUP_INTERVAL")
if parsedInt, err := strconv.ParseInt(value, 10, 32); err == nil {
cleanupInterval = time.Duration(parsedInt) * time.Minute
}
value = os.Getenv("SFS_DEFAULT_PROTECTED")
if parsedBool, err := strconv.ParseBool(value); err == nil {
defaultProtected = parsedBool
}
value = os.Getenv("SFS_DEFAULT_EXCLUSIVE")
if parsedBool, err := strconv.ParseBool(value); err == nil {
defaultProtected = parsedBool
}
}