diff --git a/docs/user_guide/api/other.md b/docs/user_guide/api/other.md index 53b17696..3d181065 100644 --- a/docs/user_guide/api/other.md +++ b/docs/user_guide/api/other.md @@ -15,4 +15,15 @@ Health check endpoint for Kubernetes or similar { "status": "healthy" } - ``` \ No newline at end of file + ``` + +## /api/v1/admin/shutdown + +### `POST /api/v1/admin/shutdown` + +Gracefully shut down the application + +=== "Request" + ```bash + curl --request POST gnmic-api-address:port/api/v1/admin/shutdown + ``` diff --git a/pkg/app/api.go b/pkg/app/api.go index 3a2ca7e0..cc3c56fa 100644 --- a/pkg/app/api.go +++ b/pkg/app/api.go @@ -330,6 +330,11 @@ func (a *App) handleHealthzGet(w http.ResponseWriter, r *http.Request) { w.Write(b) } +func (a *App) handleAdminShutdown(w http.ResponseWriter, r *http.Request) { + a.Logger.Printf("shutting down due to user request") + a.Cfn() +} + func (a *App) handleClusteringMembersGet(w http.ResponseWriter, r *http.Request) { if a.Config.Clustering == nil { return diff --git a/pkg/app/routes.go b/pkg/app/routes.go index 52d4a2cc..8738acc5 100644 --- a/pkg/app/routes.go +++ b/pkg/app/routes.go @@ -20,6 +20,7 @@ func (a *App) routes() { a.configRoutes(apiV1) a.targetRoutes(apiV1) a.healthRoutes(apiV1) + a.adminRoutes(apiV1) } func (a *App) clusterRoutes(r *mux.Router) { @@ -64,3 +65,7 @@ func (a *App) targetRoutes(r *mux.Router) { func (a *App) healthRoutes(r *mux.Router) { r.HandleFunc("/healthz", a.handleHealthzGet).Methods(http.MethodGet) } + +func (a *App) adminRoutes(r *mux.Router) { + r.HandleFunc("/admin/shutdown", a.handleAdminShutdown).Methods(http.MethodPost) +}