2018-03-12 07:16:53 +01:00
|
|
|
/*
|
2019-04-09 20:39:42 +02:00
|
|
|
* MinIO Cloud Storage, (C) 2018 MinIO, Inc.
|
2018-03-12 07:16:53 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2018-07-23 21:21:25 +02:00
|
|
|
"os"
|
|
|
|
|
2019-09-05 11:20:56 +02:00
|
|
|
xhttp "github.com/minio/minio/cmd/http"
|
2018-07-23 21:21:25 +02:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2018-03-12 07:16:53 +01:00
|
|
|
)
|
|
|
|
|
2019-12-28 17:54:43 +01:00
|
|
|
// ReadinessCheckHandler -- Checks if the quorum number of disks are available.
|
|
|
|
// For FS - Checks if the backend disk is available
|
2020-01-02 14:05:01 +01:00
|
|
|
// For Zones - Checks if all the zones have enough read quorum
|
2018-03-12 07:16:53 +01:00
|
|
|
func ReadinessCheckHandler(w http.ResponseWriter, r *http.Request) {
|
2019-12-28 17:54:43 +01:00
|
|
|
ctx := newContext(r, w, "ReadinessCheckHandler")
|
|
|
|
|
2020-01-15 03:45:17 +01:00
|
|
|
objLayer := newObjectLayerWithoutSafeModeFn()
|
2019-12-28 17:54:43 +01:00
|
|
|
// Service not initialized yet
|
|
|
|
if objLayer == nil || !objLayer.IsReady(ctx) {
|
2018-03-12 07:16:53 +01:00
|
|
|
writeResponse(w, http.StatusServiceUnavailable, nil, mimeNone)
|
|
|
|
return
|
|
|
|
}
|
2019-12-28 17:54:43 +01:00
|
|
|
|
2018-03-12 07:16:53 +01:00
|
|
|
writeResponse(w, http.StatusOK, nil, mimeNone)
|
|
|
|
}
|
|
|
|
|
2018-07-23 21:21:25 +02:00
|
|
|
// LivenessCheckHandler -- checks if server can reach its disks internally.
|
|
|
|
// If not, server is considered to have failed and needs to be restarted.
|
2018-03-12 07:16:53 +01:00
|
|
|
// Liveness probes are used to detect situations where application (minio)
|
|
|
|
// has gone into a state where it can not recover except by being restarted.
|
|
|
|
func LivenessCheckHandler(w http.ResponseWriter, r *http.Request) {
|
2018-07-23 21:21:25 +02:00
|
|
|
ctx := newContext(r, w, "LivenessCheckHandler")
|
|
|
|
|
2020-01-15 03:45:17 +01:00
|
|
|
objLayer := newObjectLayerWithoutSafeModeFn()
|
2018-03-12 07:16:53 +01:00
|
|
|
// Service not initialized yet
|
2019-11-09 18:27:23 +01:00
|
|
|
if objLayer == nil {
|
2019-09-05 11:20:56 +02:00
|
|
|
// Respond with 200 OK while server initializes to ensure a distributed cluster
|
|
|
|
// is able to start on orchestration platforms like Docker Swarm.
|
|
|
|
// Refer https://github.com/minio/minio/issues/8140 for more details.
|
|
|
|
// Make sure to add server not initialized status in header
|
2019-11-02 00:58:11 +01:00
|
|
|
w.Header().Set(xhttp.MinIOServerStatus, "server-not-initialized")
|
2019-09-05 11:20:56 +02:00
|
|
|
writeSuccessResponseHeadersOnly(w)
|
2018-03-12 07:16:53 +01:00
|
|
|
return
|
|
|
|
}
|
2018-07-31 19:55:34 +02:00
|
|
|
|
2019-01-20 05:58:36 +01:00
|
|
|
if !globalIsXL && !globalIsDistXL {
|
|
|
|
s := objLayer.StorageInfo(ctx)
|
2019-11-02 00:58:11 +01:00
|
|
|
if s.Backend.Type == BackendGateway {
|
|
|
|
if !s.Backend.GatewayOnline {
|
2019-01-20 05:58:36 +01:00
|
|
|
writeResponse(w, http.StatusServiceUnavailable, nil, mimeNone)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
writeResponse(w, http.StatusOK, nil, mimeNone)
|
2018-07-31 19:55:34 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 05:58:36 +01:00
|
|
|
// For FS and Erasure backend, check if local disks are up.
|
2018-07-23 21:21:25 +02:00
|
|
|
var erroredDisks int
|
2019-11-20 02:42:27 +01:00
|
|
|
for _, ep := range globalEndpoints {
|
|
|
|
for _, endpoint := range ep.Endpoints {
|
|
|
|
// Check only if local disks are accessible, we do not have
|
|
|
|
// to reach to rest of the other servers in a distributed setup.
|
|
|
|
if !endpoint.IsLocal {
|
|
|
|
continue
|
|
|
|
}
|
2018-07-23 21:21:25 +02:00
|
|
|
// Attempt a stat to backend, any error resulting
|
|
|
|
// from this Stat() operation is considered as backend
|
|
|
|
// is not available, count them as errors.
|
2019-11-20 02:42:27 +01:00
|
|
|
if _, err := os.Stat(endpoint.Path); err != nil && os.IsNotExist(err) {
|
2018-07-23 21:21:25 +02:00
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
erroredDisks++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-11 22:44:10 +02:00
|
|
|
|
2019-11-20 02:42:27 +01:00
|
|
|
// Any errored disks, we let orchestrators take us down.
|
|
|
|
if erroredDisks > 0 {
|
2018-03-12 07:16:53 +01:00
|
|
|
writeResponse(w, http.StatusServiceUnavailable, nil, mimeNone)
|
|
|
|
return
|
|
|
|
}
|
2020-01-15 03:45:17 +01:00
|
|
|
|
2018-03-12 07:16:53 +01:00
|
|
|
writeResponse(w, http.StatusOK, nil, mimeNone)
|
|
|
|
}
|