mirror of
https://github.com/minio/minio.git
synced 2024-12-25 14:45:54 -05:00
parent
2959c104b3
commit
caecd75a2a
@ -50,24 +50,6 @@ func (adminAPI adminAPIHandlers) ServiceStatusHandler(w http.ResponseWriter, r *
|
||||
writeSuccessResponseJSON(w, jsonBytes)
|
||||
}
|
||||
|
||||
// ServiceStopHandler - POST /?service
|
||||
// HTTP header x-minio-operation: stop
|
||||
// ----------
|
||||
// Stops minio server gracefully. In a distributed setup, stops all the
|
||||
// servers in the cluster.
|
||||
func (adminAPI adminAPIHandlers) ServiceStopHandler(w http.ResponseWriter, r *http.Request) {
|
||||
adminAPIErr := checkRequestAuthType(r, "", "", "")
|
||||
if adminAPIErr != ErrNone {
|
||||
writeErrorResponse(w, adminAPIErr, r.URL)
|
||||
return
|
||||
}
|
||||
|
||||
// Reply to the client before stopping minio server.
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
sendServiceCmd(globalAdminPeers, serviceStop)
|
||||
}
|
||||
|
||||
// ServiceRestartHandler - POST /?service
|
||||
// HTTP header x-minio-operation: restart
|
||||
// ----------
|
||||
|
@ -56,8 +56,6 @@ func (c cmdType) apiMethod() string {
|
||||
switch c {
|
||||
case statusCmd:
|
||||
return "GET"
|
||||
case stopCmd:
|
||||
return "POST"
|
||||
case restartCmd:
|
||||
return "POST"
|
||||
}
|
||||
@ -70,8 +68,6 @@ func (c cmdType) toServiceSignal() serviceSignal {
|
||||
switch c {
|
||||
case statusCmd:
|
||||
return serviceStatus
|
||||
case stopCmd:
|
||||
return serviceStop
|
||||
case restartCmd:
|
||||
return serviceRestart
|
||||
}
|
||||
@ -187,11 +183,6 @@ func TestServiceStatusHandler(t *testing.T) {
|
||||
testServicesCmdHandler(statusCmd, t)
|
||||
}
|
||||
|
||||
// Test for service stop management REST API.
|
||||
func TestServiceStopHandler(t *testing.T) {
|
||||
testServicesCmdHandler(stopCmd, t)
|
||||
}
|
||||
|
||||
// Test for service restart management REST API.
|
||||
func TestServiceRestartHandler(t *testing.T) {
|
||||
testServicesCmdHandler(restartCmd, t)
|
||||
|
@ -33,8 +33,7 @@ func registerAdminRouter(mux *router.Router) {
|
||||
|
||||
// Service status
|
||||
adminRouter.Methods("GET").Queries("service", "").Headers(minioAdminOpHeader, "status").HandlerFunc(adminAPI.ServiceStatusHandler)
|
||||
// Service stop
|
||||
adminRouter.Methods("POST").Queries("service", "").Headers(minioAdminOpHeader, "stop").HandlerFunc(adminAPI.ServiceStopHandler)
|
||||
|
||||
// Service restart
|
||||
adminRouter.Methods("POST").Queries("service", "").Headers(minioAdminOpHeader, "restart").HandlerFunc(adminAPI.ServiceRestartHandler)
|
||||
|
||||
|
@ -36,18 +36,10 @@ type remoteAdminClient struct {
|
||||
// adminCmdRunner - abstracts local and remote execution of admin
|
||||
// commands like service stop and service restart.
|
||||
type adminCmdRunner interface {
|
||||
Stop() error
|
||||
Restart() error
|
||||
ListLocks(bucket, prefix string, relTime time.Duration) ([]VolumeLockInfo, error)
|
||||
}
|
||||
|
||||
// Stop - Sends a message over channel to the go-routine responsible
|
||||
// for stopping the process.
|
||||
func (lc localAdminClient) Stop() error {
|
||||
globalServiceSignalCh <- serviceStop
|
||||
return nil
|
||||
}
|
||||
|
||||
// Restart - Sends a message over channel to the go-routine
|
||||
// responsible for restarting the process.
|
||||
func (lc localAdminClient) Restart() error {
|
||||
@ -60,13 +52,6 @@ func (lc localAdminClient) ListLocks(bucket, prefix string, relTime time.Duratio
|
||||
return listLocksInfo(bucket, prefix, relTime), nil
|
||||
}
|
||||
|
||||
// Stop - Sends stop command to remote server via RPC.
|
||||
func (rc remoteAdminClient) Stop() error {
|
||||
args := AuthRPCArgs{}
|
||||
reply := AuthRPCReply{}
|
||||
return rc.Call("Admin.Shutdown", &args, &reply)
|
||||
}
|
||||
|
||||
// Restart - Sends restart command to remote server via RPC.
|
||||
func (rc remoteAdminClient) Restart() error {
|
||||
args := AuthRPCArgs{}
|
||||
@ -88,7 +73,7 @@ func (rc remoteAdminClient) ListLocks(bucket, prefix string, relTime time.Durati
|
||||
return reply.volLocks, nil
|
||||
}
|
||||
|
||||
// adminPeer - represents an entity that implements Stop and Restart methods.
|
||||
// adminPeer - represents an entity that implements Restart methods.
|
||||
type adminPeer struct {
|
||||
addr string
|
||||
cmdRunner adminCmdRunner
|
||||
@ -146,18 +131,16 @@ func initGlobalAdminPeers(eps []*url.URL) {
|
||||
globalAdminPeers = makeAdminPeers(eps)
|
||||
}
|
||||
|
||||
// invokeServiceCmd - Invoke Stop/Restart command.
|
||||
// invokeServiceCmd - Invoke Restart command.
|
||||
func invokeServiceCmd(cp adminPeer, cmd serviceSignal) (err error) {
|
||||
switch cmd {
|
||||
case serviceStop:
|
||||
err = cp.cmdRunner.Stop()
|
||||
case serviceRestart:
|
||||
err = cp.cmdRunner.Restart()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// sendServiceCmd - Invoke Stop/Restart command on remote peers
|
||||
// sendServiceCmd - Invoke Restart command on remote peers
|
||||
// adminPeer followed by on the local peer.
|
||||
func sendServiceCmd(cps adminPeers, cmd serviceSignal) {
|
||||
// Send service command like stop or restart to all remote nodes and finally run on local node.
|
||||
|
@ -45,16 +45,6 @@ type ListLocksReply struct {
|
||||
volLocks []VolumeLockInfo
|
||||
}
|
||||
|
||||
// Shutdown - Shutdown this instance of minio server.
|
||||
func (s *adminCmd) Shutdown(args *AuthRPCArgs, reply *AuthRPCReply) error {
|
||||
if err := args.IsAuthenticated(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
globalServiceSignalCh <- serviceStop
|
||||
return nil
|
||||
}
|
||||
|
||||
// Restart - Restart this instance of minio server.
|
||||
func (s *adminCmd) Restart(args *AuthRPCArgs, reply *AuthRPCReply) error {
|
||||
if err := args.IsAuthenticated(); err != nil {
|
||||
|
@ -47,17 +47,13 @@ func testAdminCmd(cmd cmdType, t *testing.T) {
|
||||
}
|
||||
|
||||
go func() {
|
||||
// mocking signal receiver
|
||||
// A test signal receiver
|
||||
<-globalServiceSignalCh
|
||||
}()
|
||||
|
||||
ga := AuthRPCArgs{AuthToken: reply.AuthToken, RequestTime: time.Now().UTC()}
|
||||
genReply := AuthRPCReply{}
|
||||
switch cmd {
|
||||
case stopCmd:
|
||||
if err = adminServer.Shutdown(&ga, &genReply); err != nil {
|
||||
t.Errorf("stopCmd: Expected: <nil>, got: %v", err)
|
||||
}
|
||||
case restartCmd:
|
||||
if err = adminServer.Restart(&ga, &genReply); err != nil {
|
||||
t.Errorf("restartCmd: Expected: <nil>, got: %v", err)
|
||||
@ -65,10 +61,6 @@ func testAdminCmd(cmd cmdType, t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminShutdown(t *testing.T) {
|
||||
testAdminCmd(stopCmd, t)
|
||||
}
|
||||
|
||||
func TestAdminRestart(t *testing.T) {
|
||||
testAdminCmd(restartCmd, t)
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ func main() {
|
||||
| Service operations|LockInfo operations|Healing operations|
|
||||
|:---|:---|:---|
|
||||
|[`ServiceStatus`](#ServiceStatus)| | |
|
||||
|[`ServiceStop`](#ServiceStop)| | |
|
||||
|[`ServiceRestart`](#ServiceRestart)| | |
|
||||
|
||||
## 1. Constructor
|
||||
@ -98,23 +97,6 @@ Fetch service status, replies disk space used, backend type and total disks offl
|
||||
|
||||
```
|
||||
|
||||
<a name="ServiceStop"></a>
|
||||
### ServiceStop() (error)
|
||||
If successful shuts down the running minio service, for distributed setup stops all remote minio servers.
|
||||
|
||||
__Example__
|
||||
|
||||
|
||||
```go
|
||||
|
||||
st, err := madmClnt.ServiceStop()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
log.Printf("Succes")
|
||||
|
||||
```
|
||||
|
||||
<a name="ServiceRestart"></a>
|
||||
### ServiceRestart() (error)
|
||||
If successful restarts the running minio service, for distributed setup restarts all remote minio servers.
|
||||
|
@ -105,7 +105,6 @@ go run service-status.go
|
||||
### API Reference : Service Operations
|
||||
|
||||
* [`ServiceStatus`](./API.md#ServiceStatus)
|
||||
* [`ServiceStop`](./API.md#ServiceStop)
|
||||
* [`ServiceRestart`](./API.md#ServiceRestart)
|
||||
|
||||
## Full Examples
|
||||
@ -113,7 +112,6 @@ go run service-status.go
|
||||
#### Full Examples : Service Operations
|
||||
|
||||
* [service-status.go](https://github.com/minio/minio/blob/master/pkg/madmin/examples/service-status.go)
|
||||
* [service-stop.go](https://github.com/minio/minio/blob/master/pkg/madmin/examples/service-stop.go)
|
||||
* [service-restart.go](https://github.com/minio/minio/blob/master/pkg/madmin/examples/service-restart.go)
|
||||
|
||||
## Contribute
|
||||
|
@ -1,44 +0,0 @@
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
* Minio Cloud Storage, (C) 2016 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
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
|
||||
// dummy values, please replace them with original values.
|
||||
|
||||
// API requests are secure (HTTPS) if secure=true and insecure (HTTPS) otherwise.
|
||||
// New returns an Minio Admin client object.
|
||||
madmClnt, err := madmin.New("your-minio.example.com:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
err = madmClnt.ServiceStop()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
log.Println("Success")
|
||||
}
|
@ -95,30 +95,6 @@ func (adm *AdminClient) ServiceStatus() (ServiceStatusMetadata, error) {
|
||||
return storageInfo, nil
|
||||
}
|
||||
|
||||
// ServiceStop - Call Service Stop Management API to stop a specified Minio server
|
||||
func (adm *AdminClient) ServiceStop() error {
|
||||
//
|
||||
reqData := requestData{}
|
||||
reqData.queryValues = make(url.Values)
|
||||
reqData.queryValues.Set("service", "")
|
||||
reqData.customHeaders = make(http.Header)
|
||||
reqData.customHeaders.Set(minioAdminOpHeader, "stop")
|
||||
|
||||
// Execute GET on bucket to list objects.
|
||||
resp, err := adm.executeMethod("POST", reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return errors.New("Got HTTP Status: " + resp.Status)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ServiceRestart - Call Service Restart API to restart a specified Minio server
|
||||
func (adm *AdminClient) ServiceRestart() error {
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user