mirror of
https://github.com/minio/minio.git
synced 2024-12-26 23:25:54 -05:00
86 lines
1.7 KiB
Go
86 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"os/user"
|
|
|
|
"github.com/minio/cli"
|
|
"github.com/minio/minio/pkg/server"
|
|
"github.com/minio/minio/pkg/server/api"
|
|
)
|
|
|
|
var commands = []cli.Command{
|
|
serverCmd,
|
|
controlCmd,
|
|
}
|
|
|
|
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 controlCmd = cli.Command{
|
|
Name: "control",
|
|
Description: "Control mode",
|
|
Action: runController,
|
|
CustomHelpTemplate: `NAME:
|
|
minio {{.Name}} - {{.Description}}
|
|
|
|
USAGE:
|
|
minio {{.Name}}
|
|
|
|
EXAMPLES:
|
|
1. Start in controller mode
|
|
$ minio control
|
|
|
|
`,
|
|
}
|
|
|
|
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"),
|
|
}
|
|
}
|
|
|
|
func runServer(c *cli.Context) {
|
|
_, err := user.Current()
|
|
if err != nil {
|
|
Fatalf("Unable to determine current user. Reason: %s\n", err)
|
|
}
|
|
apiServerConfig := getAPIServerConfig(c)
|
|
if err := server.StartServices(apiServerConfig); err != nil {
|
|
Fatalln(err)
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|