diff --git a/commands.go b/commands.go index 26a52bdce..ba7bd8560 100644 --- a/commands.go +++ b/commands.go @@ -1,7 +1,10 @@ package main import ( + "os" + "os/signal" "os/user" + "syscall" "github.com/minio/cli" "github.com/minio/minio/pkg/controller" @@ -67,13 +70,33 @@ func getServerConfig(c *cli.Context) api.Config { } } +func trapServer(doneCh chan struct{}) { + // Go signal notification works by sending `os.Signal` + // values on a channel. + sigs := make(chan os.Signal, 1) + + // `signal.Notify` registers the given channel to + // receive notifications of the specified signals. + signal.Notify(sigs, syscall.SIGHUP, syscall.SIGUSR2) + + // This executes a blocking receive for signals. + // When it gets one it'll then notify the program + // that it can finish. + <-sigs + doneCh <- struct{}{} +} + func runServer(c *cli.Context) { _, err := user.Current() if err != nil { Fatalf("Unable to determine current user. Reason: %s\n", err) } + doneCh := make(chan struct{}) + go trapServer(doneCh) + apiServerConfig := getServerConfig(c) - if err := server.StartServices(apiServerConfig); err != nil { + err = server.StartServices(apiServerConfig, doneCh) + if err != nil { Fatalln(err) } } diff --git a/pkg/server/rpc/setdonut.go b/pkg/server/rpc/setdonut.go index b75d8bf18..2017613e6 100644 --- a/pkg/server/rpc/setdonut.go +++ b/pkg/server/rpc/setdonut.go @@ -23,8 +23,9 @@ type DonutService struct{} // DonutArgs collections of disks and name to initialize donut type DonutArgs struct { - Name string - Disks []string + MaxSize int64 + Name string + Disks []string } // Reply reply for successful or failed Set operation diff --git a/pkg/server/server.go b/pkg/server/server.go index 220f7f337..1ebe9a243 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -17,6 +17,7 @@ package server import ( + "crypto/tls" "fmt" "net" "net/http" @@ -37,6 +38,20 @@ func startAPI(errCh chan error, conf api.Config, apiHandler http.Handler) { MaxHeaderBytes: 1 << 20, } + if conf.TLS { + config := &tls.Config{} + if httpServer.TLSConfig != nil { + *config = *httpServer.TLSConfig + } + + var err error + config.Certificates = make([]tls.Certificate, 1) + config.Certificates[0], err = tls.LoadX509KeyPair(conf.CertFile, conf.KeyFile) + if err != nil { + errCh <- iodine.New(err, nil) + } + } + host, port, err := net.SplitHostPort(conf.Address) if err != nil { errCh <- iodine.New(err, nil) @@ -62,18 +77,16 @@ func startAPI(errCh chan error, conf api.Config, apiHandler http.Handler) { } } } - switch { - default: - for _, host := range hosts { - fmt.Printf("Starting minio server on: http://%s:%s\n", host, port) - } - errCh <- httpServer.ListenAndServe() - case conf.TLS == true: - for _, host := range hosts { + + for _, host := range hosts { + if conf.TLS { fmt.Printf("Starting minio server on: https://%s:%s\n", host, port) + } else { + fmt.Printf("Starting minio server on: http://%s:%s\n", host, port) } - errCh <- httpServer.ListenAndServeTLS(conf.CertFile, conf.KeyFile) + } + errCh <- httpServer.ListenAndServe() } // Start RPC listener @@ -99,7 +112,7 @@ func startTM(a api.Minio) { } // StartServices starts basic services for a server -func StartServices(conf api.Config) error { +func StartServices(conf api.Config, doneCh chan struct{}) error { apiErrCh := make(chan error) rpcErrCh := make(chan error) @@ -113,5 +126,7 @@ func StartServices(conf api.Config) error { return iodine.New(err, nil) case err := <-rpcErrCh: return iodine.New(err, nil) + case <-doneCh: + return nil } }