2015-01-21 02:16:06 -05:00
|
|
|
/*
|
2015-03-19 17:35:50 -04:00
|
|
|
* Minimalist Object Storage, (C) 2014 Minio, Inc.
|
2015-01-21 02:16:06 -05:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2015-06-30 23:15:48 -04:00
|
|
|
package server
|
2015-01-18 16:31:22 -05:00
|
|
|
|
|
|
|
import (
|
2015-06-03 21:27:13 -04:00
|
|
|
"fmt"
|
|
|
|
"net"
|
2015-01-18 16:31:22 -05:00
|
|
|
"net/http"
|
2015-06-03 21:27:13 -04:00
|
|
|
"strings"
|
2015-01-25 20:15:18 -05:00
|
|
|
|
2015-06-30 23:15:48 -04:00
|
|
|
"github.com/minio/minio/pkg/server/api"
|
|
|
|
)
|
2015-01-18 16:31:22 -05:00
|
|
|
|
2015-07-02 18:40:16 -04:00
|
|
|
func startAPI(errCh chan error, conf api.Config, apiHandler http.Handler) {
|
2015-06-30 17:42:29 -04:00
|
|
|
defer close(errCh)
|
2015-01-25 20:15:18 -05:00
|
|
|
|
2015-01-21 03:50:23 -05:00
|
|
|
// Minio server config
|
2015-01-28 19:29:47 -05:00
|
|
|
httpServer := &http.Server{
|
2015-06-30 23:15:48 -04:00
|
|
|
Addr: conf.Address,
|
2015-07-02 18:40:16 -04:00
|
|
|
Handler: apiHandler,
|
2015-01-21 03:50:23 -05:00
|
|
|
MaxHeaderBytes: 1 << 20,
|
|
|
|
}
|
2015-06-03 21:27:13 -04:00
|
|
|
|
2015-06-30 23:15:48 -04:00
|
|
|
host, port, err := net.SplitHostPort(conf.Address)
|
2015-06-29 02:53:53 -04:00
|
|
|
if err != nil {
|
2015-06-30 17:42:29 -04:00
|
|
|
errCh <- err
|
2015-06-29 02:53:53 -04:00
|
|
|
return
|
|
|
|
}
|
2015-06-03 21:27:13 -04:00
|
|
|
|
|
|
|
var hosts []string
|
|
|
|
switch {
|
|
|
|
case host != "":
|
|
|
|
hosts = append(hosts, host)
|
|
|
|
default:
|
|
|
|
addrs, err := net.InterfaceAddrs()
|
2015-06-29 03:12:28 -04:00
|
|
|
if err != nil {
|
2015-06-30 17:42:29 -04:00
|
|
|
errCh <- err
|
2015-06-29 03:12:28 -04:00
|
|
|
return
|
|
|
|
}
|
2015-06-03 21:27:13 -04:00
|
|
|
for _, addr := range addrs {
|
|
|
|
if addr.Network() == "ip+net" {
|
2015-06-29 02:53:53 -04:00
|
|
|
host := strings.Split(addr.String(), "/")[0]
|
|
|
|
if ip := net.ParseIP(host); ip.To4() != nil {
|
|
|
|
hosts = append(hosts, host)
|
2015-06-03 21:27:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-07 03:14:58 -04:00
|
|
|
switch {
|
|
|
|
default:
|
2015-06-03 21:27:13 -04:00
|
|
|
for _, host := range hosts {
|
|
|
|
fmt.Printf("Starting minio server on: http://%s:%s\n", host, port)
|
|
|
|
}
|
2015-07-01 03:37:43 -04:00
|
|
|
errCh <- httpServer.ListenAndServe()
|
2015-06-30 23:15:48 -04:00
|
|
|
case conf.TLS == true:
|
2015-06-08 23:10:59 -04:00
|
|
|
for _, host := range hosts {
|
|
|
|
fmt.Printf("Starting minio server on: https://%s:%s\n", host, port)
|
|
|
|
}
|
2015-07-01 03:37:43 -04:00
|
|
|
errCh <- httpServer.ListenAndServeTLS(conf.CertFile, conf.KeyFile)
|
2015-01-25 20:15:18 -05:00
|
|
|
}
|
2015-06-30 17:42:29 -04:00
|
|
|
}
|
2015-06-29 02:53:53 -04:00
|
|
|
|
2015-07-02 18:40:16 -04:00
|
|
|
func startRPC(errCh chan error, rpcHandler http.Handler) {
|
2015-06-30 23:15:48 -04:00
|
|
|
defer close(errCh)
|
|
|
|
|
|
|
|
// Minio server config
|
|
|
|
httpServer := &http.Server{
|
2015-07-01 03:37:43 -04:00
|
|
|
Addr: "127.0.0.1:9001", // TODO make this configurable
|
2015-07-02 18:40:16 -04:00
|
|
|
Handler: rpcHandler,
|
2015-06-30 23:15:48 -04:00
|
|
|
MaxHeaderBytes: 1 << 20,
|
|
|
|
}
|
2015-07-01 03:37:43 -04:00
|
|
|
errCh <- httpServer.ListenAndServe()
|
2015-06-30 17:42:29 -04:00
|
|
|
}
|
|
|
|
|
2015-07-02 18:40:16 -04:00
|
|
|
func startTM(a api.Minio) {
|
|
|
|
for {
|
|
|
|
for op := range a.OP {
|
|
|
|
close(op.ProceedCh)
|
|
|
|
}
|
|
|
|
}
|
2015-07-02 01:36:33 -04:00
|
|
|
}
|
|
|
|
|
2015-06-30 23:15:48 -04:00
|
|
|
// StartServices starts basic services for a server
|
|
|
|
func StartServices(conf api.Config) error {
|
|
|
|
apiErrCh := make(chan error)
|
|
|
|
rpcErrCh := make(chan error)
|
|
|
|
|
2015-07-02 18:40:16 -04:00
|
|
|
apiHandler, minioAPI := getAPIHandler(conf)
|
|
|
|
go startAPI(apiErrCh, conf, apiHandler)
|
|
|
|
rpcHandler := getRPCHandler()
|
|
|
|
go startRPC(rpcErrCh, rpcHandler)
|
|
|
|
go startTM(minioAPI)
|
2015-06-30 23:15:48 -04:00
|
|
|
|
|
|
|
select {
|
|
|
|
case err := <-apiErrCh:
|
2015-07-01 03:37:43 -04:00
|
|
|
return err
|
2015-06-30 23:15:48 -04:00
|
|
|
case err := <-rpcErrCh:
|
2015-07-01 03:37:43 -04:00
|
|
|
return err
|
2015-06-30 17:42:29 -04:00
|
|
|
}
|
2015-01-18 16:31:22 -05:00
|
|
|
}
|