Merge pull request #803 from harshavardhana/minio-server-changes
Refactoring minio server command and flagsmaster
commit
67f9df0926
@ -0,0 +1,74 @@ |
||||
/* |
||||
* Minio Cloud Storage, (C) 2015 Minio, Inc. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/minio/minio/internal/github.com/minio/cli" |
||||
"github.com/minio/minio/pkg/controller" |
||||
) |
||||
|
||||
var controllerCmd = cli.Command{ |
||||
Name: "controller", |
||||
Usage: "Get|Set server configuration", |
||||
Action: controllerMain, |
||||
CustomHelpTemplate: `NAME: |
||||
minio {{.Name}} - {{.Description}} |
||||
|
||||
USAGE: |
||||
minio {{.Name}} [get|set] [INFOTYPE] [SERVERURL] |
||||
|
||||
EXAMPLES: |
||||
1. Get disks from controller |
||||
$ minio {{.Name}} get disks http://localhost:9001/rpc
|
||||
|
||||
2. Get memstats from controller |
||||
$ minio {{.Name}} get mem http://localhost:9001/rpc
|
||||
|
||||
`, |
||||
} |
||||
|
||||
func controllerMain(c *cli.Context) { |
||||
if len(c.Args()) < 2 || c.Args().First() == "help" { |
||||
cli.ShowCommandHelpAndExit(c, "controller", 1) // last argument is exit code
|
||||
} |
||||
if c.Args().First() == "get" { |
||||
newArgs := c.Args().Tail() |
||||
switch newArgs.First() { |
||||
case "mem": |
||||
memstats, err := controller.GetMemStats(newArgs.Tail().First()) |
||||
if err != nil { |
||||
Fatalln(err) |
||||
} |
||||
Println(string(memstats)) |
||||
case "sysinfo": |
||||
sysinfo, err := controller.GetSysInfo(newArgs.Tail().First()) |
||||
if err != nil { |
||||
Fatalln(err) |
||||
} |
||||
Println(string(sysinfo)) |
||||
case "auth": |
||||
keys, err := controller.GetAuthKeys(newArgs.Tail().First()) |
||||
if err != nil { |
||||
Fatalln(err) |
||||
} |
||||
Println(string(keys)) |
||||
} |
||||
} |
||||
if c.Args().First() == "set" { |
||||
Fatalln("Not supported yet") |
||||
} |
||||
} |
@ -0,0 +1,99 @@ |
||||
/* |
||||
* Minio Cloud Storage, (C) 2015 Minio, Inc. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"os" |
||||
"path/filepath" |
||||
|
||||
"github.com/minio/minio/internal/github.com/minio/cli" |
||||
"github.com/minio/minio/pkg/donut" |
||||
) |
||||
|
||||
var ( |
||||
donutSubCommands = []cli.Command{ |
||||
{ |
||||
Name: "make", |
||||
Description: "make a donut", |
||||
Action: makeDonutMain, |
||||
CustomHelpTemplate: `NAME: |
||||
minio donut {{.Name}} - {{.Description}} |
||||
|
||||
USAGE: |
||||
minio donut {{.Name}} DONUTNAME [DISKS...] |
||||
|
||||
EXAMPLES: |
||||
1. Make a donut with 4 exports |
||||
$ minio donut {{.Name}} mongodb-backup /mnt/export1 /mnt/export2 /mnt/export3 /mnt/export4 |
||||
|
||||
2. Make a donut with 16 exports |
||||
$ minio donut {{.Name}} operational-data /mnt/export1 /mnt/export2 /mnt/export3 /mnt/export4 /mnt/export5 \
|
||||
/mnt/export6 /mnt/export7 /mnt/export8 /mnt/export9 /mnt/export10 /mnt/export11 \
|
||||
/mnt/export12 /mnt/export13 /mnt/export14 /mnt/export15 /mnt/export16 |
||||
`, |
||||
}, |
||||
} |
||||
|
||||
donutCmd = cli.Command{ |
||||
Name: "donut", |
||||
Usage: "Create and manage a donut configuration", |
||||
Subcommands: donutSubCommands, |
||||
} |
||||
) |
||||
|
||||
func makeDonutMain(c *cli.Context) { |
||||
if !c.Args().Present() || c.Args().First() == "help" { |
||||
cli.ShowCommandHelpAndExit(c, "make", 1) |
||||
} |
||||
donutName := c.Args().First() |
||||
if c.Args().First() != "" { |
||||
if !donut.IsValidDonut(donutName) { |
||||
Fatalf("Invalid donutname %s\n", donutName) |
||||
} |
||||
} |
||||
var disks []string |
||||
for _, disk := range c.Args().Tail() { |
||||
if _, err := isUsable(disk); err != nil { |
||||
Fatalln(err) |
||||
} |
||||
disks = append(disks, disk) |
||||
} |
||||
for _, disk := range disks { |
||||
if err := os.MkdirAll(filepath.Join(disk, donutName), 0700); err != nil { |
||||
Fatalln(err) |
||||
} |
||||
} |
||||
|
||||
hostname, err := os.Hostname() |
||||
if err != nil { |
||||
Fatalln(err) |
||||
} |
||||
donutConfig := &donut.Config{} |
||||
donutConfig.Version = "0.0.1" |
||||
donutConfig.DonutName = donutName |
||||
donutConfig.NodeDiskMap = make(map[string][]string) |
||||
// keep it in exact order as it was specified, do not try to sort disks
|
||||
donutConfig.NodeDiskMap[hostname] = disks |
||||
// default cache is unlimited
|
||||
donutConfig.MaxSize = 512000000 |
||||
|
||||
if err := donut.SaveConfig(donutConfig); err != nil { |
||||
Fatalln(err) |
||||
} |
||||
|
||||
Infoln("Success!") |
||||
} |
@ -0,0 +1,63 @@ |
||||
/* |
||||
* Minio Cloud Storage, (C) 2015 Minio, Inc. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package main |
||||
|
||||
import "github.com/minio/minio/internal/github.com/minio/cli" |
||||
|
||||
// Collection of minio flags currently supported
|
||||
var flags = []cli.Flag{} |
||||
|
||||
var ( |
||||
addressFlag = cli.StringFlag{ |
||||
Name: "address", |
||||
Value: ":9000", |
||||
Usage: "ADDRESS:PORT for cloud storage access", |
||||
} |
||||
|
||||
addressMgmtFlag = cli.StringFlag{ |
||||
Name: "address-mgmt", |
||||
Hide: true, |
||||
Value: ":9001", |
||||
Usage: "ADDRESS:PORT for management console access", |
||||
} |
||||
|
||||
ratelimitFlag = cli.IntFlag{ |
||||
Name: "ratelimit", |
||||
Value: 16, |
||||
Usage: "Limit for total concurrent requests: [DEFAULT: 16]", |
||||
} |
||||
|
||||
certFlag = cli.StringFlag{ |
||||
Name: "cert", |
||||
Usage: "Provide your domain certificate", |
||||
} |
||||
|
||||
keyFlag = cli.StringFlag{ |
||||
Name: "key", |
||||
Usage: "Provide your domain private key", |
||||
} |
||||
|
||||
debugFlag = cli.BoolFlag{ |
||||
Name: "debug", |
||||
Usage: "print debug information", |
||||
} |
||||
) |
||||
|
||||
// registerFlag registers a cli flag
|
||||
func registerFlag(flag cli.Flag) { |
||||
flags = append(flags, flag) |
||||
} |
@ -0,0 +1,67 @@ |
||||
/* |
||||
* Minio Cloud Storage, (C) 2015 Minio, Inc. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/minio/minio/internal/github.com/minio/cli" |
||||
"github.com/minio/minio/pkg/server" |
||||
"github.com/minio/minio/pkg/server/api" |
||||
) |
||||
|
||||
var serverCmd = cli.Command{ |
||||
Name: "server", |
||||
Usage: "Start minio server", |
||||
Action: serverMain, |
||||
CustomHelpTemplate: `NAME: |
||||
minio {{.Name}} - {{.Description}} |
||||
|
||||
USAGE: |
||||
minio {{.Name}} |
||||
|
||||
EXAMPLES: |
||||
1. Start minio server |
||||
$ minio {{.Name}} |
||||
|
||||
`, |
||||
} |
||||
|
||||
func getServerConfig(c *cli.Context) api.Config { |
||||
certFile := c.GlobalString("cert") |
||||
keyFile := c.GlobalString("key") |
||||
if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") { |
||||
Fatalln("Both certificate and key are required to enable https.") |
||||
} |
||||
tls := (certFile != "" && keyFile != "") |
||||
return api.Config{ |
||||
Address: c.GlobalString("address"), |
||||
TLS: tls, |
||||
CertFile: certFile, |
||||
KeyFile: keyFile, |
||||
RateLimit: c.GlobalInt("ratelimit"), |
||||
} |
||||
} |
||||
|
||||
func serverMain(c *cli.Context) { |
||||
if c.Args().Present() { |
||||
cli.ShowCommandHelpAndExit(c, "server", 1) |
||||
} |
||||
apiServerConfig := getServerConfig(c) |
||||
err := server.StartServices(apiServerConfig) |
||||
if err != nil { |
||||
Fatalln(err) |
||||
} |
||||
} |
@ -0,0 +1,48 @@ |
||||
/* |
||||
* Minio Cloud Storage, (C) 2015 Minio, Inc. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"net/http" |
||||
"time" |
||||
|
||||
"github.com/minio/minio/internal/github.com/minio/cli" |
||||
) |
||||
|
||||
var versionCmd = cli.Command{ |
||||
Name: "version", |
||||
Usage: "Print version", |
||||
Action: mainVersion, |
||||
CustomHelpTemplate: `NAME: |
||||
mc {{.Name}} - {{.Usage}} |
||||
|
||||
USAGE: |
||||
mc {{.Name}} {{if .Description}} |
||||
|
||||
EXAMPLES: |
||||
|
||||
`, |
||||
} |
||||
|
||||
func mainVersion(ctxx *cli.Context) { |
||||
t, _ := time.Parse(time.RFC3339Nano, Version) |
||||
if t.IsZero() { |
||||
Println("") |
||||
return |
||||
} |
||||
Println(t.Format(http.TimeFormat)) |
||||
} |
@ -1,29 +1,7 @@ |
||||
// -------- DO NOT EDIT --------
|
||||
// this is an autogenerated file
|
||||
// This file is autogenerated by genversion.go during the release process.
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"net/http" |
||||
"time" |
||||
) |
||||
|
||||
// Version autogenerated
|
||||
var Version = "2015-06-17T03:17:23.789648634Z" |
||||
|
||||
// Tag is of following format
|
||||
//
|
||||
// [[STRING]-[EPOCH]
|
||||
//
|
||||
// STRING is release string of your choice.
|
||||
// EPOCH is unix seconds since Jan 1, 1970 UTC.
|
||||
var Tag = "release-1434511043" |
||||
|
||||
// getVersion -
|
||||
func getVersion() string { |
||||
t, _ := time.Parse(time.RFC3339Nano, Version) |
||||
if t.IsZero() { |
||||
return "" |
||||
} |
||||
return t.Format(http.TimeFormat) |
||||
} |
||||
const Version = "2015-08-14T03:23:47.250240049Z" |
||||
|
Loading…
Reference in new issue