2015-08-20 16:05:47 -04:00
|
|
|
|
/*
|
|
|
|
|
* 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
|
|
|
|
|
|
2015-09-19 05:36:50 -04:00
|
|
|
|
import (
|
|
|
|
|
"crypto/tls"
|
2015-10-16 14:26:01 -04:00
|
|
|
|
"encoding/json"
|
2016-03-10 05:48:36 -05:00
|
|
|
|
"errors"
|
2015-10-16 14:26:01 -04:00
|
|
|
|
"fmt"
|
2015-09-19 05:36:50 -04:00
|
|
|
|
"net"
|
|
|
|
|
"net/http"
|
|
|
|
|
"os"
|
2015-10-16 14:26:01 -04:00
|
|
|
|
"runtime"
|
2015-10-17 22:17:33 -04:00
|
|
|
|
"strconv"
|
2015-09-19 05:36:50 -04:00
|
|
|
|
"strings"
|
2016-03-16 11:09:24 -04:00
|
|
|
|
"syscall"
|
2015-09-19 05:36:50 -04:00
|
|
|
|
|
2015-10-16 14:26:01 -04:00
|
|
|
|
"github.com/fatih/color"
|
2015-09-19 05:36:50 -04:00
|
|
|
|
"github.com/minio/cli"
|
2016-03-04 04:50:59 -05:00
|
|
|
|
"github.com/minio/mc/pkg/console"
|
2016-02-10 19:40:09 -05:00
|
|
|
|
"github.com/minio/minio/pkg/minhttp"
|
|
|
|
|
"github.com/minio/minio/pkg/probe"
|
2015-09-19 05:36:50 -04:00
|
|
|
|
)
|
2015-08-20 16:05:47 -04:00
|
|
|
|
|
|
|
|
|
var serverCmd = cli.Command{
|
2016-02-06 21:22:50 -05:00
|
|
|
|
Name: "server",
|
|
|
|
|
Usage: "Start Minio cloud storage server.",
|
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
|
cli.StringFlag{
|
|
|
|
|
Name: "min-free-disk, M",
|
|
|
|
|
Value: "5%",
|
|
|
|
|
},
|
|
|
|
|
},
|
2015-08-20 16:05:47 -04:00
|
|
|
|
Action: serverMain,
|
|
|
|
|
CustomHelpTemplate: `NAME:
|
2015-10-16 14:26:01 -04:00
|
|
|
|
minio {{.Name}} - {{.Usage}}
|
2015-08-20 16:05:47 -04:00
|
|
|
|
|
|
|
|
|
USAGE:
|
2015-10-22 04:31:09 -04:00
|
|
|
|
minio {{.Name}} [OPTION VALUE] PATH
|
|
|
|
|
|
2016-02-06 21:22:50 -05:00
|
|
|
|
OPTIONS:
|
|
|
|
|
{{range .Flags}}{{.}}
|
|
|
|
|
{{end}}
|
2016-02-22 05:15:20 -05:00
|
|
|
|
|
|
|
|
|
ENVIRONMENT VARIABLES:
|
|
|
|
|
MINIO_ACCESS_KEY, MINIO_SECRET_KEY: Access and secret key to use.
|
|
|
|
|
|
2015-08-20 16:05:47 -04:00
|
|
|
|
EXAMPLES:
|
2015-10-16 14:26:01 -04:00
|
|
|
|
1. Start minio server on Linux.
|
|
|
|
|
$ minio {{.Name}} /home/shared
|
2015-08-20 16:05:47 -04:00
|
|
|
|
|
2015-10-16 14:26:01 -04:00
|
|
|
|
2. Start minio server on Windows.
|
|
|
|
|
$ minio {{.Name}} C:\MyShare
|
|
|
|
|
|
|
|
|
|
3. Start minio server bound to a specific IP:PORT, when you have multiple network interfaces.
|
2015-10-17 22:17:33 -04:00
|
|
|
|
$ minio --address 192.168.1.101:9000 {{.Name}} /home/shared
|
|
|
|
|
|
|
|
|
|
4. Start minio server with minimum free disk threshold to 5%
|
2016-02-06 21:22:50 -05:00
|
|
|
|
$ minio {{.Name}} --min-free-disk 5% /home/shared/Pictures
|
2016-02-04 23:40:58 -05:00
|
|
|
|
|
2015-08-20 16:05:47 -04:00
|
|
|
|
`,
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-20 03:33:53 -04:00
|
|
|
|
// cloudServerConfig - http server config
|
|
|
|
|
type cloudServerConfig struct {
|
|
|
|
|
/// HTTP server options
|
2016-02-02 20:38:02 -05:00
|
|
|
|
Address string // Address:Port listening
|
|
|
|
|
AccessLog bool // Enable access log handler
|
2015-10-20 03:33:53 -04:00
|
|
|
|
|
2016-01-23 22:44:32 -05:00
|
|
|
|
// Credentials.
|
|
|
|
|
AccessKeyID string // Access key id.
|
|
|
|
|
SecretAccessKey string // Secret access key.
|
2016-02-15 20:42:39 -05:00
|
|
|
|
Region string // Region string.
|
2016-01-23 22:44:32 -05:00
|
|
|
|
|
2015-10-20 03:33:53 -04:00
|
|
|
|
/// FS options
|
2016-02-02 22:35:47 -05:00
|
|
|
|
Path string // Path to export for cloud storage
|
|
|
|
|
MinFreeDisk int64 // Minimum free disk space for filesystem
|
2016-02-04 23:40:58 -05:00
|
|
|
|
MaxBuckets int // Maximum number of buckets suppported by filesystem.
|
2015-10-20 03:33:53 -04:00
|
|
|
|
|
2016-01-17 04:39:09 -05:00
|
|
|
|
/// TLS service
|
2015-10-20 03:33:53 -04:00
|
|
|
|
TLS bool // TLS on when certs are specified
|
|
|
|
|
CertFile string // Domain certificate
|
|
|
|
|
KeyFile string // Domain key
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-18 05:13:52 -05:00
|
|
|
|
// configureServer configure a new server instance
|
|
|
|
|
func configureServer(conf cloudServerConfig) (*http.Server, *probe.Error) {
|
2015-09-19 05:36:50 -04:00
|
|
|
|
// Minio server config
|
2015-09-19 23:52:57 -04:00
|
|
|
|
apiServer := &http.Server{
|
2015-09-19 05:36:50 -04:00
|
|
|
|
Addr: conf.Address,
|
2016-02-18 05:13:52 -05:00
|
|
|
|
Handler: serverHandler(conf),
|
2015-09-19 05:36:50 -04:00
|
|
|
|
MaxHeaderBytes: 1 << 20,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if conf.TLS {
|
|
|
|
|
var err error
|
2015-09-19 23:52:57 -04:00
|
|
|
|
apiServer.TLSConfig = &tls.Config{}
|
|
|
|
|
apiServer.TLSConfig.Certificates = make([]tls.Certificate, 1)
|
|
|
|
|
apiServer.TLSConfig.Certificates[0], err = tls.LoadX509KeyPair(conf.CertFile, conf.KeyFile)
|
2015-09-19 05:36:50 -04:00
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, probe.NewError(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-30 21:33:33 -05:00
|
|
|
|
return apiServer, nil
|
|
|
|
|
}
|
2015-09-19 05:36:50 -04:00
|
|
|
|
|
2016-02-02 20:38:02 -05:00
|
|
|
|
func printServerMsg(serverConf *http.Server) {
|
|
|
|
|
host, port, e := net.SplitHostPort(serverConf.Addr)
|
2016-01-30 21:33:33 -05:00
|
|
|
|
fatalIf(probe.NewError(e), "Unable to split host port.", nil)
|
2015-09-19 05:36:50 -04:00
|
|
|
|
|
|
|
|
|
var hosts []string
|
|
|
|
|
switch {
|
|
|
|
|
case host != "":
|
|
|
|
|
hosts = append(hosts, host)
|
|
|
|
|
default:
|
2016-01-30 21:33:33 -05:00
|
|
|
|
addrs, e := net.InterfaceAddrs()
|
|
|
|
|
fatalIf(probe.NewError(e), "Unable to get interface address.", nil)
|
|
|
|
|
|
2015-09-19 05:36:50 -04:00
|
|
|
|
for _, addr := range addrs {
|
|
|
|
|
if addr.Network() == "ip+net" {
|
|
|
|
|
host := strings.Split(addr.String(), "/")[0]
|
|
|
|
|
if ip := net.ParseIP(host); ip.To4() != nil {
|
|
|
|
|
hosts = append(hosts, host)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for _, host := range hosts {
|
2016-02-02 20:38:02 -05:00
|
|
|
|
if serverConf.TLSConfig != nil {
|
2016-03-04 04:50:59 -05:00
|
|
|
|
console.Printf(" https://%s:%s\n", host, port)
|
2015-09-19 05:36:50 -04:00
|
|
|
|
} else {
|
2016-03-04 04:50:59 -05:00
|
|
|
|
console.Printf(" http://%s:%s\n", host, port)
|
2015-09-19 05:36:50 -04:00
|
|
|
|
}
|
2015-09-19 23:52:57 -04:00
|
|
|
|
}
|
2015-09-19 05:36:50 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-17 22:17:33 -04:00
|
|
|
|
// parse input string with percent to int64
|
|
|
|
|
func parsePercentToInt(s string, bitSize int) (int64, *probe.Error) {
|
|
|
|
|
i := strings.Index(s, "%")
|
|
|
|
|
if i < 0 {
|
|
|
|
|
// no percentage string found try to parse the whole string anyways
|
2016-02-04 15:52:25 -05:00
|
|
|
|
p, e := strconv.ParseInt(s, 10, bitSize)
|
|
|
|
|
if e != nil {
|
|
|
|
|
return 0, probe.NewError(e)
|
2015-10-17 22:17:33 -04:00
|
|
|
|
}
|
|
|
|
|
return p, nil
|
|
|
|
|
}
|
2016-02-04 15:52:25 -05:00
|
|
|
|
p, e := strconv.ParseInt(s[:i], 10, bitSize)
|
|
|
|
|
if e != nil {
|
|
|
|
|
return 0, probe.NewError(e)
|
2015-10-17 22:17:33 -04:00
|
|
|
|
}
|
|
|
|
|
return p, nil
|
|
|
|
|
}
|
2015-10-21 20:02:40 -04:00
|
|
|
|
func setLogger(conf *configV2) *probe.Error {
|
|
|
|
|
if conf.IsMongoLoggingEnabled() {
|
2016-02-04 15:52:25 -05:00
|
|
|
|
if err := log2Mongo(conf.MongoLogger.Addr, conf.MongoLogger.DB, conf.MongoLogger.Collection); err != nil {
|
|
|
|
|
return err.Trace(conf.MongoLogger.Addr, conf.MongoLogger.DB, conf.MongoLogger.Collection)
|
2015-10-21 20:02:40 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if conf.IsSysloggingEnabled() {
|
2016-02-04 15:52:25 -05:00
|
|
|
|
if err := log2Syslog(conf.SyslogLogger.Network, conf.SyslogLogger.Addr); err != nil {
|
|
|
|
|
return err.Trace(conf.SyslogLogger.Network, conf.SyslogLogger.Addr)
|
2015-10-21 20:02:40 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if conf.IsFileLoggingEnabled() {
|
2016-02-04 15:52:25 -05:00
|
|
|
|
if err := log2File(conf.FileLogger.Filename); err != nil {
|
|
|
|
|
return err.Trace(conf.FileLogger.Filename)
|
2015-10-21 20:02:40 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2015-10-17 22:17:33 -04:00
|
|
|
|
|
2015-10-21 20:02:40 -04:00
|
|
|
|
// Generates config if it doesn't exist, otherwise returns back the saved ones.
|
|
|
|
|
func getConfig() (*configV2, *probe.Error) {
|
2015-10-20 03:33:53 -04:00
|
|
|
|
if err := createConfigPath(); err != nil {
|
2015-10-16 14:26:01 -04:00
|
|
|
|
return nil, err.Trace()
|
|
|
|
|
}
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-03 19:46:56 -05:00
|
|
|
|
if err := createBucketsConfigPath(); err != nil {
|
|
|
|
|
return nil, err.Trace()
|
|
|
|
|
}
|
2015-10-20 03:33:53 -04:00
|
|
|
|
config, err := loadConfigV2()
|
2015-10-16 14:26:01 -04:00
|
|
|
|
if err != nil {
|
|
|
|
|
if os.IsNotExist(err.ToGoError()) {
|
|
|
|
|
// Initialize new config, since config file doesn't exist yet
|
2016-01-18 21:45:24 -05:00
|
|
|
|
config = &configV2{}
|
2015-10-20 03:33:53 -04:00
|
|
|
|
config.Version = "2"
|
|
|
|
|
config.Credentials.AccessKeyID = string(mustGenerateAccessKeyID())
|
|
|
|
|
config.Credentials.SecretAccessKey = string(mustGenerateSecretAccessKey())
|
2016-01-17 04:39:09 -05:00
|
|
|
|
config.Credentials.Region = "us-east-1"
|
2016-01-18 21:45:24 -05:00
|
|
|
|
if err = saveConfig(config); err != nil {
|
2015-10-16 14:26:01 -04:00
|
|
|
|
return nil, err.Trace()
|
|
|
|
|
}
|
|
|
|
|
return config, nil
|
|
|
|
|
}
|
|
|
|
|
return nil, err.Trace()
|
|
|
|
|
}
|
|
|
|
|
return config, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type accessKeys struct {
|
2015-10-20 03:33:53 -04:00
|
|
|
|
*configV2
|
2015-10-16 14:26:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a accessKeys) String() string {
|
|
|
|
|
magenta := color.New(color.FgMagenta, color.Bold).SprintFunc()
|
|
|
|
|
white := color.New(color.FgWhite, color.Bold).SprintfFunc()
|
2016-01-31 06:48:33 -05:00
|
|
|
|
return fmt.Sprint(magenta("AccessKey: ") + white(a.Credentials.AccessKeyID) + " " + magenta("SecretKey: ") + white(a.Credentials.SecretAccessKey) + " " + magenta("Region: ") + white(a.Credentials.Region))
|
2015-10-16 14:26:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// JSON - json formatted output
|
|
|
|
|
func (a accessKeys) JSON() string {
|
2016-02-04 15:52:25 -05:00
|
|
|
|
b, e := json.Marshal(a)
|
|
|
|
|
errorIf(probe.NewError(e), "Unable to marshal json", nil)
|
2015-10-16 14:26:01 -04:00
|
|
|
|
return string(b)
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-21 20:02:40 -04:00
|
|
|
|
// initServer initialize server
|
2016-01-23 22:44:32 -05:00
|
|
|
|
func initServer() (*configV2, *probe.Error) {
|
2015-10-21 20:02:40 -04:00
|
|
|
|
conf, err := getConfig()
|
2015-10-16 14:26:01 -04:00
|
|
|
|
if err != nil {
|
2016-01-23 22:44:32 -05:00
|
|
|
|
return nil, err.Trace()
|
2015-10-16 14:26:01 -04:00
|
|
|
|
}
|
2015-10-21 20:02:40 -04:00
|
|
|
|
if err := setLogger(conf); err != nil {
|
2016-01-23 22:44:32 -05:00
|
|
|
|
return nil, err.Trace()
|
2015-10-21 20:02:40 -04:00
|
|
|
|
}
|
2016-01-23 22:44:32 -05:00
|
|
|
|
return conf, nil
|
2015-10-16 14:26:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 03:46:03 -04:00
|
|
|
|
func checkServerSyntax(c *cli.Context) {
|
2015-10-16 14:26:01 -04:00
|
|
|
|
if !c.Args().Present() || c.Args().First() == "help" {
|
2015-08-20 16:05:47 -04:00
|
|
|
|
cli.ShowCommandHelpAndExit(c, "server", 1)
|
|
|
|
|
}
|
2016-02-06 21:22:50 -05:00
|
|
|
|
if len(c.Args()) > 1 {
|
2015-10-19 03:46:03 -04:00
|
|
|
|
fatalIf(probe.NewError(errInvalidArgument), "Unnecessary arguments passed. Please refer ‘mc server help’", nil)
|
|
|
|
|
}
|
|
|
|
|
path := strings.TrimSpace(c.Args().Last())
|
|
|
|
|
if path == "" {
|
|
|
|
|
fatalIf(probe.NewError(errInvalidArgument), "Path argument cannot be empty.", nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-09 09:09:40 -05:00
|
|
|
|
// extract port number from address.
|
|
|
|
|
// address should be of the form host:port
|
|
|
|
|
func getPort(address string) int {
|
|
|
|
|
_, portStr, e := net.SplitHostPort(address)
|
|
|
|
|
fatalIf(probe.NewError(e), "Unable to split host port.", nil)
|
|
|
|
|
portInt, e := strconv.Atoi(portStr)
|
|
|
|
|
fatalIf(probe.NewError(e), "Invalid port number.", nil)
|
|
|
|
|
return portInt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure that none of the other processes are listening on the
|
|
|
|
|
// specified port on any of the interfaces.
|
|
|
|
|
//
|
|
|
|
|
// On linux if a process is listening on 127.0.0.1:9000 then Listen()
|
|
|
|
|
// on ":9000" fails with the error "port already in use".
|
|
|
|
|
// However on Mac OSX Listen() on ":9000" falls back to the IPv6 address.
|
|
|
|
|
// This causes confusion on Mac OSX that minio server is not reachable
|
|
|
|
|
// on 127.0.0.1 even though minio server is running. So before we start
|
|
|
|
|
// the minio server we make sure that the port is free on all the IPs.
|
|
|
|
|
func checkPortAvailability(port int) {
|
2016-03-16 11:09:24 -04:00
|
|
|
|
isAddrInUse := func(e error) bool {
|
|
|
|
|
// Check if the syscall error is EADDRINUSE.
|
|
|
|
|
// EADDRINUSE is the system call error if another process is
|
|
|
|
|
// already listening at the specified port.
|
|
|
|
|
neterr, ok := e.(*net.OpError)
|
|
|
|
|
if !ok {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
osErr, ok := neterr.Err.(*os.SyscallError)
|
|
|
|
|
if !ok {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
sysErr, ok := osErr.Err.(syscall.Errno)
|
|
|
|
|
if !ok {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if sysErr != syscall.EADDRINUSE {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
2016-03-09 09:09:40 -05:00
|
|
|
|
ifcs, e := net.Interfaces()
|
|
|
|
|
if e != nil {
|
|
|
|
|
fatalIf(probe.NewError(e), "Unable to list interfaces.", nil)
|
|
|
|
|
}
|
|
|
|
|
for _, ifc := range ifcs {
|
|
|
|
|
addrs, e := ifc.Addrs()
|
|
|
|
|
if e != nil {
|
|
|
|
|
fatalIf(probe.NewError(e), fmt.Sprintf("Unable to list addresses on interface %s.", ifc.Name), nil)
|
|
|
|
|
}
|
|
|
|
|
for _, addr := range addrs {
|
2016-03-10 05:48:36 -05:00
|
|
|
|
ipnet, ok := addr.(*net.IPNet)
|
|
|
|
|
if !ok {
|
|
|
|
|
errorIf(probe.NewError(errors.New("")), "Interface type assertion to (*net.IPNet) failed.", nil)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
ip := ipnet.IP
|
|
|
|
|
network := "tcp4"
|
|
|
|
|
if ip.To4() == nil {
|
|
|
|
|
network = "tcp6"
|
|
|
|
|
}
|
2016-03-09 09:09:40 -05:00
|
|
|
|
tcpAddr := net.TCPAddr{IP: ip, Port: port, Zone: ifc.Name}
|
2016-03-10 05:48:36 -05:00
|
|
|
|
l, e := net.ListenTCP(network, &tcpAddr)
|
2016-03-09 09:09:40 -05:00
|
|
|
|
if e != nil {
|
2016-03-16 11:09:24 -04:00
|
|
|
|
if isAddrInUse(e) {
|
|
|
|
|
// Fail if port is already in use.
|
|
|
|
|
fatalIf(probe.NewError(e), fmt.Sprintf("Unable to listen on IP %s, port %.d", tcpAddr.IP, tcpAddr.Port), nil)
|
|
|
|
|
} else {
|
|
|
|
|
// Ignore other errors.
|
|
|
|
|
continue
|
|
|
|
|
}
|
2016-03-09 09:09:40 -05:00
|
|
|
|
}
|
|
|
|
|
e = l.Close()
|
|
|
|
|
if e != nil {
|
|
|
|
|
fatalIf(probe.NewError(e), fmt.Sprintf("Unable to close listener on IP %s, port %.d", tcpAddr.IP, tcpAddr.Port), nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 03:46:03 -04:00
|
|
|
|
func serverMain(c *cli.Context) {
|
|
|
|
|
checkServerSyntax(c)
|
2016-03-09 09:09:40 -05:00
|
|
|
|
address := c.GlobalString("address")
|
|
|
|
|
checkPortAvailability(getPort(address))
|
2015-09-18 02:49:06 -04:00
|
|
|
|
|
2015-10-19 03:46:03 -04:00
|
|
|
|
certFile := c.GlobalString("cert")
|
|
|
|
|
keyFile := c.GlobalString("key")
|
|
|
|
|
if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") {
|
|
|
|
|
fatalIf(probe.NewError(errInvalidArgument), "Both certificate and key are required to enable https.", nil)
|
|
|
|
|
}
|
2015-10-18 17:47:56 -04:00
|
|
|
|
|
2016-03-17 23:00:11 -04:00
|
|
|
|
conf, err := initServer()
|
|
|
|
|
fatalIf(err.Trace(), "Failed to read config for minio.", nil)
|
|
|
|
|
|
2016-02-22 05:15:20 -05:00
|
|
|
|
accessKey := os.Getenv("MINIO_ACCESS_KEY")
|
|
|
|
|
secretKey := os.Getenv("MINIO_SECRET_KEY")
|
|
|
|
|
if accessKey != "" && secretKey != "" {
|
|
|
|
|
if !isValidAccessKey(accessKey) {
|
|
|
|
|
fatalIf(probe.NewError(errInvalidArgument), "Access key does not have required length", nil)
|
|
|
|
|
}
|
|
|
|
|
if !isValidSecretKey(secretKey) {
|
|
|
|
|
fatalIf(probe.NewError(errInvalidArgument), "Secret key does not have required length", nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
conf.Credentials.AccessKeyID = accessKey
|
|
|
|
|
conf.Credentials.SecretAccessKey = secretKey
|
|
|
|
|
|
|
|
|
|
err = saveConfig(conf)
|
|
|
|
|
fatalIf(err.Trace(), "Unable to save credentials to config.", nil)
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-06 21:22:50 -05:00
|
|
|
|
minFreeDisk, err := parsePercentToInt(c.String("min-free-disk"), 64)
|
|
|
|
|
fatalIf(err.Trace(c.String("min-free-disk")), "Invalid minium free disk size "+c.String("min-free-disk")+" passed.", nil)
|
2015-10-18 17:47:56 -04:00
|
|
|
|
|
|
|
|
|
path := strings.TrimSpace(c.Args().Last())
|
|
|
|
|
// Last argument is always path
|
|
|
|
|
if _, err := os.Stat(path); err != nil {
|
|
|
|
|
fatalIf(probe.NewError(err), "Unable to validate the path", nil)
|
|
|
|
|
}
|
2016-02-15 20:42:39 -05:00
|
|
|
|
region := conf.Credentials.Region
|
|
|
|
|
if region == "" {
|
|
|
|
|
region = "us-east-1"
|
|
|
|
|
}
|
2015-10-19 03:46:03 -04:00
|
|
|
|
tls := (certFile != "" && keyFile != "")
|
2016-01-30 21:33:33 -05:00
|
|
|
|
serverConfig := cloudServerConfig{
|
2016-03-09 09:09:40 -05:00
|
|
|
|
Address: address,
|
2016-01-23 22:44:32 -05:00
|
|
|
|
AccessLog: c.GlobalBool("enable-accesslog"),
|
|
|
|
|
AccessKeyID: conf.Credentials.AccessKeyID,
|
|
|
|
|
SecretAccessKey: conf.Credentials.SecretAccessKey,
|
2016-02-15 20:42:39 -05:00
|
|
|
|
Region: region,
|
2016-01-23 22:44:32 -05:00
|
|
|
|
Path: path,
|
|
|
|
|
MinFreeDisk: minFreeDisk,
|
|
|
|
|
TLS: tls,
|
|
|
|
|
CertFile: certFile,
|
|
|
|
|
KeyFile: keyFile,
|
2015-10-19 03:46:03 -04:00
|
|
|
|
}
|
2016-01-30 21:33:33 -05:00
|
|
|
|
|
2016-02-18 05:13:52 -05:00
|
|
|
|
// configure server.
|
|
|
|
|
apiServer, err := configureServer(serverConfig)
|
2016-01-30 21:33:33 -05:00
|
|
|
|
errorIf(err.Trace(), "Failed to configure API server.", nil)
|
|
|
|
|
|
2016-03-17 23:00:11 -04:00
|
|
|
|
console.Println()
|
|
|
|
|
// Print access keys and region.
|
|
|
|
|
console.Println(accessKeys{conf})
|
|
|
|
|
|
2016-03-04 04:50:59 -05:00
|
|
|
|
console.Println("\nMinio Object Storage:")
|
2016-02-02 20:38:02 -05:00
|
|
|
|
printServerMsg(apiServer)
|
2016-01-30 21:33:33 -05:00
|
|
|
|
|
2016-03-04 04:50:59 -05:00
|
|
|
|
console.Println("\nMinio Browser:")
|
2016-02-18 05:13:52 -05:00
|
|
|
|
printServerMsg(apiServer)
|
|
|
|
|
|
2016-03-04 04:50:59 -05:00
|
|
|
|
console.Println("\nTo configure Minio Client:")
|
2016-01-30 21:33:33 -05:00
|
|
|
|
if runtime.GOOS == "windows" {
|
2016-03-04 04:50:59 -05:00
|
|
|
|
console.Println(" Download \"mc\" from https://dl.minio.io/client/mc/release/" + runtime.GOOS + "-" + runtime.GOARCH + "/mc.exe")
|
|
|
|
|
console.Println(" $ mc.exe config host add myminio http://localhost:9000 " + conf.Credentials.AccessKeyID + " " + conf.Credentials.SecretAccessKey)
|
2016-01-30 21:33:33 -05:00
|
|
|
|
} else {
|
2016-03-04 04:50:59 -05:00
|
|
|
|
console.Println(" $ wget https://dl.minio.io/client/mc/release/" + runtime.GOOS + "-" + runtime.GOARCH + "/mc")
|
|
|
|
|
console.Println(" $ chmod 755 mc")
|
|
|
|
|
console.Println(" $ ./mc config host add myminio http://localhost:9000 " + conf.Credentials.AccessKeyID + " " + conf.Credentials.SecretAccessKey)
|
2016-01-30 21:33:33 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Start server.
|
2016-02-16 21:50:36 -05:00
|
|
|
|
err = minhttp.ListenAndServe(apiServer)
|
2016-01-30 21:33:33 -05:00
|
|
|
|
errorIf(err.Trace(), "Failed to start the minio server.", nil)
|
2015-08-20 16:05:47 -04:00
|
|
|
|
}
|