Added shutdown.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -72,6 +72,7 @@ func prepare(w http.ResponseWriter, r *http.Request){
|
||||
Source: bodyDecoded.VolumeId,
|
||||
Target: "/volume",
|
||||
Type: "volume",
|
||||
ReadOnly: true,
|
||||
},
|
||||
},
|
||||
StopGracePeriod: &stopGracePeriod,
|
||||
@@ -90,6 +91,7 @@ func prepare(w http.ResponseWriter, r *http.Request){
|
||||
}
|
||||
|
||||
time.Sleep(7*time.Second);
|
||||
|
||||
fmt.Fprint(w, bodyDecoded.ServiceId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user