2015-06-05 21:29:24 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/user"
|
|
|
|
|
|
|
|
"github.com/minio/cli"
|
2015-06-30 23:15:48 -04:00
|
|
|
"github.com/minio/minio/pkg/server"
|
|
|
|
"github.com/minio/minio/pkg/server/api"
|
2015-06-05 21:29:24 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var commands = []cli.Command{
|
2015-06-30 15:18:31 -04:00
|
|
|
serverCmd,
|
|
|
|
controlCmd,
|
2015-06-05 21:29:24 -04:00
|
|
|
}
|
|
|
|
|
2015-06-30 15:18:31 -04:00
|
|
|
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
|
2015-06-05 21:29:24 -04:00
|
|
|
|
2015-06-30 15:18:31 -04:00
|
|
|
`,
|
2015-06-05 21:29:24 -04:00
|
|
|
}
|
|
|
|
|
2015-06-30 15:18:31 -04:00
|
|
|
var controlCmd = cli.Command{
|
|
|
|
Name: "control",
|
|
|
|
Description: "Control mode",
|
|
|
|
Action: runController,
|
2015-06-05 21:29:24 -04:00
|
|
|
CustomHelpTemplate: `NAME:
|
2015-06-30 15:18:31 -04:00
|
|
|
minio {{.Name}} - {{.Description}}
|
2015-06-05 21:29:24 -04:00
|
|
|
|
|
|
|
USAGE:
|
2015-06-30 15:18:31 -04:00
|
|
|
minio {{.Name}}
|
2015-06-05 21:29:24 -04:00
|
|
|
|
|
|
|
EXAMPLES:
|
2015-06-30 15:18:31 -04:00
|
|
|
1. Start in controller mode
|
|
|
|
$ minio control
|
2015-06-05 21:29:24 -04:00
|
|
|
|
|
|
|
`,
|
|
|
|
}
|
|
|
|
|
2015-06-30 23:15:48 -04:00
|
|
|
func getAPIServerConfig(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"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-30 15:18:31 -04:00
|
|
|
func runServer(c *cli.Context) {
|
|
|
|
_, err := user.Current()
|
2015-06-05 21:29:24 -04:00
|
|
|
if err != nil {
|
|
|
|
Fatalf("Unable to determine current user. Reason: %s\n", err)
|
|
|
|
}
|
2015-06-30 15:18:31 -04:00
|
|
|
apiServerConfig := getAPIServerConfig(c)
|
2015-06-30 23:15:48 -04:00
|
|
|
if err := server.StartServices(apiServerConfig); err != nil {
|
2015-06-30 19:30:02 -04:00
|
|
|
Fatalln(err)
|
2015-06-27 18:02:49 -04:00
|
|
|
}
|
2015-06-30 15:18:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func runController(c *cli.Context) {
|
|
|
|
_, err := user.Current()
|
|
|
|
if err != nil {
|
|
|
|
Fatalf("Unable to determine current user. Reason: %s\n", err)
|
2015-06-27 18:02:49 -04:00
|
|
|
}
|
2015-06-30 15:18:31 -04:00
|
|
|
if len(c.Args()) < 1 {
|
|
|
|
cli.ShowCommandHelpAndExit(c, "control", 1) // last argument is exit code
|
2015-06-05 21:29:24 -04:00
|
|
|
}
|
|
|
|
}
|