Added shutdown.

This commit is contained in:
rony5394
2026-03-05 14:25:04 +01:00
parent 44f533bd43
commit 2dda7dbb38
3 changed files with 34 additions and 4 deletions

View File

@@ -30,7 +30,7 @@ type aService struct{
}
func Run(){
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM);
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM);
var err error;
ApiClient, err = client.NewClientWithOpts(client.FromEnv);
@@ -56,6 +56,13 @@ func Run(){
http.HandleFunc("/scale/down", scaleDown);
http.HandleFunc("/prepare", prepare);
http.HandleFunc("/cleanup", cleanup);
// I'll make it better someday.
http.HandleFunc("/shutdown", func(w http.ResponseWriter, r *http.Request) {
if !bearerAuth(w, r){return}
fmt.Fprint(w, "Shutdown!");
time.Sleep(1*time.Second);
stop();
});
ApiClient.NetworkCreate(context.Background(), "blazenaPohar", network.CreateOptions{
Attachable: true,