mirror of
https://github.com/minio/minio.git
synced 2025-03-01 14:29:13 -05:00
Add server and control command
This commit is contained in:
parent
101784bc44
commit
c2031ca066
167
commands.go
167
commands.go
@ -2,146 +2,93 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
|
||||||
"github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/minio/pkg/iodine"
|
|
||||||
"github.com/minio/minio/pkg/server"
|
"github.com/minio/minio/pkg/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
func appendUniq(slice []string, i string) []string {
|
func removeDuplicates(slice []string) []string {
|
||||||
for _, ele := range slice {
|
newSlice := []string{}
|
||||||
if ele == i {
|
seen := make(map[string]struct{})
|
||||||
return slice
|
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{
|
var commands = []cli.Command{
|
||||||
modeCmd,
|
serverCmd,
|
||||||
|
controlCmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
var modeCommands = []cli.Command{
|
var serverCmd = cli.Command{
|
||||||
donutCmd,
|
Name: "server",
|
||||||
}
|
Description: "Server mode",
|
||||||
|
Action: runServer,
|
||||||
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,
|
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
minio mode {{.Name}} - {{.Description}}
|
minio {{.Name}} - {{.Description}}
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
minio mode {{.Name}} PATH
|
minio {{.Name}}
|
||||||
|
|
||||||
EXAMPLES:
|
EXAMPLES:
|
||||||
1. Create a donut volume under "/mnt/backup", with a cache limit of 64MB with 1hr expiration
|
1. Start in server mode
|
||||||
$ minio mode {{.Name}} limit 64MB expire 1h paths /mnt/backup
|
$ minio server
|
||||||
|
|
||||||
2. Create a donut volume under collection of paths, put a cache limit of 512MB
|
|
||||||
$ minio mode {{.Name}} limit 512MB paths ""
|
|
||||||
|
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
func runDonut(c *cli.Context) {
|
var controlCmd = cli.Command{
|
||||||
var err error
|
Name: "control",
|
||||||
|
Description: "Control mode",
|
||||||
|
Action: runController,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
minio {{.Name}} - {{.Description}}
|
||||||
|
|
||||||
u, err := user.Current()
|
USAGE:
|
||||||
|
minio {{.Name}}
|
||||||
|
|
||||||
|
EXAMPLES:
|
||||||
|
1. Start in controller mode
|
||||||
|
$ minio control
|
||||||
|
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
func runServer(c *cli.Context) {
|
||||||
|
_, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatalf("Unable to determine current user. Reason: %s\n", err)
|
Fatalf("Unable to determine current user. Reason: %s\n", err)
|
||||||
}
|
}
|
||||||
if len(c.Args()) < 1 {
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if maxMemorySet == false {
|
|
||||||
Fatalln("Memory limit must be set")
|
|
||||||
}
|
|
||||||
if pathSet == false {
|
|
||||||
Fatalln("Path must be set")
|
|
||||||
}
|
}
|
||||||
apiServerConfig := getAPIServerConfig(c)
|
apiServerConfig := getAPIServerConfig(c)
|
||||||
donutDriver := server.Factory{
|
s := server.Factory{
|
||||||
Config: apiServerConfig,
|
Config: apiServerConfig,
|
||||||
Paths: paths,
|
|
||||||
MaxMemory: maxMemory,
|
|
||||||
Expiration: expiration,
|
|
||||||
}
|
}
|
||||||
apiServer := donutDriver.GetStartServerFunc()
|
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 len(c.Args()) < 1 {
|
||||||
|
cli.ShowCommandHelpAndExit(c, "control", 1) // last argument is exit code
|
||||||
|
}
|
||||||
|
apiServerConfig := getAPIServerConfig(c)
|
||||||
|
s := server.Factory{
|
||||||
|
Config: apiServerConfig,
|
||||||
|
}
|
||||||
|
apiServer := s.GetStartServerFunc()
|
||||||
// webServer := getWebServerConfigFunc(c)
|
// webServer := getWebServerConfigFunc(c)
|
||||||
servers := []server.StartServerFunc{apiServer} //, webServer}
|
servers := []server.StartServerFunc{apiServer} //, webServer}
|
||||||
server.StartMinio(servers)
|
server.StartMinio(servers)
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
package featureflags
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
var features = make(map[string]bool)
|
|
||||||
var lock = &sync.RWMutex{}
|
|
||||||
|
|
||||||
// Get feature will return true if the feature is enabled, otherwise false
|
|
||||||
func Get(feature string) bool {
|
|
||||||
lock.RLock()
|
|
||||||
defer lock.RUnlock()
|
|
||||||
res := features[feature]
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable a feature
|
|
||||||
func Enable(feature string) {
|
|
||||||
lock.Lock()
|
|
||||||
defer lock.Unlock()
|
|
||||||
features[feature] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable a feature
|
|
||||||
func Disable(feature string) {
|
|
||||||
lock.Lock()
|
|
||||||
defer lock.Unlock()
|
|
||||||
features[feature] = false
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package featureflags
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestFeatureFlag(t *testing.T) {
|
|
||||||
foo := Get("foo")
|
|
||||||
if foo {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
Enable("foo")
|
|
||||||
foo = Get("foo")
|
|
||||||
if !foo {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
Disable("foo")
|
|
||||||
foo = Get("foo")
|
|
||||||
if foo {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package featureflags
|
|
||||||
|
|
||||||
const (
|
|
||||||
// MultipartPutObject ...
|
|
||||||
MultipartPutObject = "minio.multipart_put_object"
|
|
||||||
)
|
|
Loading…
x
Reference in New Issue
Block a user