forked from j-keck/lsleases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlsleases.go
94 lines (82 loc) · 2.37 KB
/
lsleases.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
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime"
)
var VERSION string
var (
//
// Flags
// flag description in flag.Usage
//
// common
printHelpFlag = flag.Bool("h", false, "")
verboseFlag = flag.Bool("v", false, "")
printVersionFlag = flag.Bool("V", false, "")
// server
serverModeFlag = flag.Bool("s", false, "")
expireBasedFlag = flag.Bool("p", false, "")
// flag.Duration not useful because there is not unit for days
leaseExpiredDurationFlag = flag.String("e", "7d", "")
cleanupLeaseTimerFlag = flag.String("t", "15m", "")
missedPingsThresholdFlag = flag.Int("m", 3, "")
keepLeasesOverRestartFlag = flag.Bool("k", false, "")
// client
scriptedModeFlag = flag.Bool("H", false, "")
clearLeasesFlag = flag.Bool("c", false, "")
listNewestLeasesFirstFlag = flag.Bool("n", false, "")
watchLeasesFlag = flag.Bool("w", false, "")
shutdownServerFlag = flag.Bool("x", false, "")
)
var (
verboseLog *log.Logger
)
var appDataPath = osDependAppDataPath()
func main() {
flag.Usage = func() {
fmt.Println("Common:")
fmt.Println(" -h: print help")
fmt.Println(" -v: verbose output")
fmt.Println(" -V: print version")
fmt.Println("Client mode:")
fmt.Println(" -c: clear leases")
fmt.Println(" -H: scripted mode: no headers, dates as unix time")
fmt.Println(" -n: list newest leases first")
fmt.Println(" -w: watch for new leases")
fmt.Println(" -x: shutdown server")
fmt.Println("Server mode:")
fmt.Println(" -s: server mode")
fmt.Println(" -p: passive mode - no active availability host check - clear leases expire based")
fmt.Println(" -e: in passive mode: lease expire duration (valid units: 'd', 'h', 'm', 's') - default:",
*leaseExpiredDurationFlag)
fmt.Println(" -t: interval for checking of leases validity (valid units: 'd', 'h', 'm', 's') - default:", *cleanupLeaseTimerFlag)
fmt.Println(" -m: in active mode: missed arpings threshold - default:", *missedPingsThresholdFlag)
fmt.Println(" -k: keep leases over restart")
}
flag.Parse()
if *printHelpFlag {
flag.Usage()
os.Exit(0)
}
//
// action
//
if *serverModeFlag {
server()
} else {
client()
}
}
func osDependAppDataPath() string {
//
// set os depend application data path
//
if runtime.GOOS == "windows" {
return os.Getenv("USERPROFILE") + "/lsleases"
} else {
return "/var/lib/lsleases"
}
}