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