Skip to content

Commit

Permalink
Merge pull request #496 from mwdomino/restart-app
Browse files Browse the repository at this point in the history
Add shutdown route
  • Loading branch information
karimra authored Aug 1, 2024
2 parents 7b31588 + 80e39d6 commit 9b75580
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion docs/user_guide/api/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,15 @@ Health check endpoint for Kubernetes or similar
{
"status": "healthy"
}
```
```

## /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
```
5 changes: 5 additions & 0 deletions pkg/app/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/app/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}

0 comments on commit 9b75580

Please sign in to comment.