mirror of
https://github.com/fosrl/olm.git
synced 2026-02-08 05:56:41 +00:00
21
api/api.go
21
api/api.go
@@ -361,20 +361,23 @@ func (s *API) handleExit(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
logger.Info("Received exit request via API")
|
logger.Info("Received exit request via API")
|
||||||
|
|
||||||
// Call the exit handler if set
|
// Return a success response first
|
||||||
if s.onExit != nil {
|
|
||||||
if err := s.onExit(); err != nil {
|
|
||||||
http.Error(w, fmt.Sprintf("Exit failed: %v", err), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a success response
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(map[string]string{
|
json.NewEncoder(w).Encode(map[string]string{
|
||||||
"status": "shutdown initiated",
|
"status": "shutdown initiated",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Call the exit handler after responding, in a goroutine with a small delay
|
||||||
|
// to ensure the response is fully sent before shutdown begins
|
||||||
|
if s.onExit != nil {
|
||||||
|
go func() {
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
if err := s.onExit(); err != nil {
|
||||||
|
logger.Error("Exit handler failed: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleSwitchOrg handles the /switch-org endpoint
|
// handleSwitchOrg handles the /switch-org endpoint
|
||||||
|
|||||||
@@ -214,10 +214,6 @@ func StartTunnel(config TunnelConfig) {
|
|||||||
// debug print out the whole config
|
// debug print out the whole config
|
||||||
logger.Debug("Starting tunnel with config: %+v", config)
|
logger.Debug("Starting tunnel with config: %+v", config)
|
||||||
|
|
||||||
if config.Holepunch {
|
|
||||||
logger.Warn("Hole punching is enabled. This is EXPERIMENTAL and may not work in all environments.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a cancellable context for this tunnel process
|
// Create a cancellable context for this tunnel process
|
||||||
tunnelCtx, cancel := context.WithCancel(globalCtx)
|
tunnelCtx, cancel := context.WithCancel(globalCtx)
|
||||||
tunnelCancel = cancel
|
tunnelCancel = cancel
|
||||||
|
|||||||
Reference in New Issue
Block a user