|
|
|
@ -2,146 +2,93 @@ package main |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"os/user" |
|
|
|
|
"path/filepath" |
|
|
|
|
"strings" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/dustin/go-humanize" |
|
|
|
|
"github.com/minio/cli" |
|
|
|
|
"github.com/minio/minio/pkg/iodine" |
|
|
|
|
"github.com/minio/minio/pkg/server" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func appendUniq(slice []string, i string) []string { |
|
|
|
|
for _, ele := range slice { |
|
|
|
|
if ele == i { |
|
|
|
|
return slice |
|
|
|
|
func removeDuplicates(slice []string) []string { |
|
|
|
|
newSlice := []string{} |
|
|
|
|
seen := make(map[string]struct{}) |
|
|
|
|
for _, val := range slice { |
|
|
|
|
if _, ok := seen[val]; !ok { |
|
|
|
|
newSlice = append(newSlice, val) |
|
|
|
|
seen[val] = struct{}{} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return append(slice, i) |
|
|
|
|
return newSlice |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var commands = []cli.Command{ |
|
|
|
|
modeCmd, |
|
|
|
|
serverCmd, |
|
|
|
|
controlCmd, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var modeCommands = []cli.Command{ |
|
|
|
|
donutCmd, |
|
|
|
|
} |
|
|
|
|
var serverCmd = cli.Command{ |
|
|
|
|
Name: "server", |
|
|
|
|
Description: "Server mode", |
|
|
|
|
Action: runServer, |
|
|
|
|
CustomHelpTemplate: `NAME: |
|
|
|
|
minio {{.Name}} - {{.Description}} |
|
|
|
|
|
|
|
|
|
USAGE: |
|
|
|
|
minio {{.Name}} |
|
|
|
|
|
|
|
|
|
EXAMPLES: |
|
|
|
|
1. Start in server mode |
|
|
|
|
$ minio server |
|
|
|
|
|
|
|
|
|
var modeCmd = cli.Command{ |
|
|
|
|
Name: "mode", |
|
|
|
|
Subcommands: modeCommands, |
|
|
|
|
Description: "Mode of execution", |
|
|
|
|
`, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var donutCmd = cli.Command{ |
|
|
|
|
Name: "donut", |
|
|
|
|
Description: "[status: EXPERIMENTAL]. Path to donut volume.", |
|
|
|
|
Action: runDonut, |
|
|
|
|
var controlCmd = cli.Command{ |
|
|
|
|
Name: "control", |
|
|
|
|
Description: "Control mode", |
|
|
|
|
Action: runController, |
|
|
|
|
CustomHelpTemplate: `NAME: |
|
|
|
|
minio mode {{.Name}} - {{.Description}} |
|
|
|
|
minio {{.Name}} - {{.Description}} |
|
|
|
|
|
|
|
|
|
USAGE: |
|
|
|
|
minio mode {{.Name}} PATH |
|
|
|
|
minio {{.Name}} |
|
|
|
|
|
|
|
|
|
EXAMPLES: |
|
|
|
|
1. Create a donut volume under "/mnt/backup", with a cache limit of 64MB with 1hr expiration |
|
|
|
|
$ minio mode {{.Name}} limit 64MB expire 1h paths /mnt/backup |
|
|
|
|
|
|
|
|
|
2. Create a donut volume under collection of paths, put a cache limit of 512MB |
|
|
|
|
$ minio mode {{.Name}} limit 512MB paths "" |
|
|
|
|
1. Start in controller mode |
|
|
|
|
$ minio control |
|
|
|
|
|
|
|
|
|
`, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func runDonut(c *cli.Context) { |
|
|
|
|
var err error |
|
|
|
|
|
|
|
|
|
u, err := user.Current() |
|
|
|
|
func runServer(c *cli.Context) { |
|
|
|
|
_, err := user.Current() |
|
|
|
|
if err != nil { |
|
|
|
|
Fatalf("Unable to determine current user. Reason: %s\n", err) |
|
|
|
|
} |
|
|
|
|
if len(c.Args()) < 1 { |
|
|
|
|
cli.ShowCommandHelpAndExit(c, "donut", 1) // last argument is exit code
|
|
|
|
|
cli.ShowCommandHelpAndExit(c, "server", 1) // last argument is exit code
|
|
|
|
|
} |
|
|
|
|
var maxMemory uint64 |
|
|
|
|
maxMemorySet := false |
|
|
|
|
|
|
|
|
|
var expiration time.Duration |
|
|
|
|
expirationSet := false |
|
|
|
|
|
|
|
|
|
var paths []string |
|
|
|
|
pathSet := false |
|
|
|
|
|
|
|
|
|
args := c.Args() |
|
|
|
|
for len(args) > 0 { |
|
|
|
|
switch args.First() { |
|
|
|
|
case "limit": |
|
|
|
|
{ |
|
|
|
|
if maxMemorySet { |
|
|
|
|
Fatalln("Limit should be set only once") |
|
|
|
|
} |
|
|
|
|
args = args.Tail() |
|
|
|
|
maxMemory, err = humanize.ParseBytes(args.First()) |
|
|
|
|
if err != nil { |
|
|
|
|
Fatalf("Invalid memory size [%s] passed. Reason: %s\n", args.First(), iodine.New(err, nil)) |
|
|
|
|
} |
|
|
|
|
if maxMemory < 1024*1024*10 { |
|
|
|
|
Fatalf("Invalid memory size [%s] passed. Should be greater than 10M\n", args.First()) |
|
|
|
|
} |
|
|
|
|
args = args.Tail() |
|
|
|
|
maxMemorySet = true |
|
|
|
|
} |
|
|
|
|
case "expire": |
|
|
|
|
{ |
|
|
|
|
if expirationSet { |
|
|
|
|
Fatalln("Expiration should be set only once") |
|
|
|
|
} |
|
|
|
|
args = args.Tail() |
|
|
|
|
expiration, err = time.ParseDuration(args.First()) |
|
|
|
|
if err != nil { |
|
|
|
|
Fatalf("Invalid expiration time [%s] passed. Reason: %s\n", args.First(), iodine.New(err, nil)) |
|
|
|
|
} |
|
|
|
|
args = args.Tail() |
|
|
|
|
expirationSet = true |
|
|
|
|
} |
|
|
|
|
case "paths": |
|
|
|
|
if pathSet { |
|
|
|
|
Fatalln("Path should be set only once") |
|
|
|
|
} |
|
|
|
|
// supporting multiple paths
|
|
|
|
|
args = args.Tail() |
|
|
|
|
if strings.TrimSpace(args.First()) == "" { |
|
|
|
|
p := filepath.Join(u.HomeDir, "minio-storage", "donut") |
|
|
|
|
paths = appendUniq(paths, p) |
|
|
|
|
} else { |
|
|
|
|
for _, arg := range args { |
|
|
|
|
paths = appendUniq(paths, strings.TrimSpace(arg)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
args = args.Tail() |
|
|
|
|
pathSet = true |
|
|
|
|
default: |
|
|
|
|
{ |
|
|
|
|
cli.ShowCommandHelpAndExit(c, "donut", 1) // last argument is exit code
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
apiServerConfig := getAPIServerConfig(c) |
|
|
|
|
s := server.Factory{ |
|
|
|
|
Config: apiServerConfig, |
|
|
|
|
} |
|
|
|
|
if maxMemorySet == false { |
|
|
|
|
Fatalln("Memory limit must be set") |
|
|
|
|
apiServer := s.GetStartServerFunc() |
|
|
|
|
// webServer := getWebServerConfigFunc(c)
|
|
|
|
|
servers := []server.StartServerFunc{apiServer} //, webServer}
|
|
|
|
|
server.StartMinio(servers) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func runController(c *cli.Context) { |
|
|
|
|
_, err := user.Current() |
|
|
|
|
if err != nil { |
|
|
|
|
Fatalf("Unable to determine current user. Reason: %s\n", err) |
|
|
|
|
} |
|
|
|
|
if pathSet == false { |
|
|
|
|
Fatalln("Path must be set") |
|
|
|
|
if len(c.Args()) < 1 { |
|
|
|
|
cli.ShowCommandHelpAndExit(c, "control", 1) // last argument is exit code
|
|
|
|
|
} |
|
|
|
|
apiServerConfig := getAPIServerConfig(c) |
|
|
|
|
donutDriver := server.Factory{ |
|
|
|
|
Config: apiServerConfig, |
|
|
|
|
Paths: paths, |
|
|
|
|
MaxMemory: maxMemory, |
|
|
|
|
Expiration: expiration, |
|
|
|
|
s := server.Factory{ |
|
|
|
|
Config: apiServerConfig, |
|
|
|
|
} |
|
|
|
|
apiServer := donutDriver.GetStartServerFunc() |
|
|
|
|
apiServer := s.GetStartServerFunc() |
|
|
|
|
// webServer := getWebServerConfigFunc(c)
|
|
|
|
|
servers := []server.StartServerFunc{apiServer} //, webServer}
|
|
|
|
|
server.StartMinio(servers) |
|
|
|
|