2022-07-26 13:29:07 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
|
2023-08-23 11:07:52 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/logs"
|
2022-07-26 13:29:07 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Service serves metrics.
|
|
|
|
type Service struct {
|
|
|
|
*http.Server
|
|
|
|
enabled bool
|
|
|
|
log *zap.Logger
|
|
|
|
serviceType string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start runs http service with the exposed endpoint on the configured port.
|
|
|
|
func (ms *Service) Start() {
|
|
|
|
if ms.enabled {
|
2023-08-23 11:07:52 +00:00
|
|
|
ms.log.Info(logs.ServiceIsRunning, zap.String("endpoint", ms.Addr))
|
2022-07-26 13:29:07 +00:00
|
|
|
err := ms.ListenAndServe()
|
|
|
|
if err != nil && err != http.ErrServerClosed {
|
2023-08-23 11:07:52 +00:00
|
|
|
ms.log.Warn(logs.ServiceCouldntStartOnConfiguredPort)
|
2022-07-26 13:29:07 +00:00
|
|
|
}
|
|
|
|
} else {
|
2023-08-23 11:07:52 +00:00
|
|
|
ms.log.Info(logs.ServiceHasntStartedSinceItsDisabled)
|
2022-07-26 13:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ShutDown stops the service.
|
|
|
|
func (ms *Service) ShutDown(ctx context.Context) {
|
2023-08-23 11:07:52 +00:00
|
|
|
ms.log.Info(logs.ShuttingDownService, zap.String("endpoint", ms.Addr))
|
2022-07-26 13:29:07 +00:00
|
|
|
err := ms.Shutdown(ctx)
|
|
|
|
if err != nil {
|
2023-12-27 10:06:11 +00:00
|
|
|
ms.log.Error(logs.CantGracefullyShutDownService, zap.Error(err))
|
|
|
|
if err = ms.Close(); err != nil {
|
|
|
|
ms.log.Panic(logs.CantShutDownService, zap.Error(err))
|
|
|
|
}
|
2022-07-26 13:29:07 +00:00
|
|
|
}
|
|
|
|
}
|