Added shutdown.
This commit is contained in:
@@ -30,7 +30,7 @@ type aService struct{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Run(){
|
func Run(){
|
||||||
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM);
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM);
|
||||||
|
|
||||||
var err error;
|
var err error;
|
||||||
ApiClient, err = client.NewClientWithOpts(client.FromEnv);
|
ApiClient, err = client.NewClientWithOpts(client.FromEnv);
|
||||||
@@ -56,6 +56,13 @@ func Run(){
|
|||||||
http.HandleFunc("/scale/down", scaleDown);
|
http.HandleFunc("/scale/down", scaleDown);
|
||||||
http.HandleFunc("/prepare", prepare);
|
http.HandleFunc("/prepare", prepare);
|
||||||
http.HandleFunc("/cleanup", cleanup);
|
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{
|
ApiClient.NetworkCreate(context.Background(), "blazenaPohar", network.CreateOptions{
|
||||||
Attachable: true,
|
Attachable: true,
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ func prepare(w http.ResponseWriter, r *http.Request){
|
|||||||
Source: bodyDecoded.VolumeId,
|
Source: bodyDecoded.VolumeId,
|
||||||
Target: "/volume",
|
Target: "/volume",
|
||||||
Type: "volume",
|
Type: "volume",
|
||||||
|
ReadOnly: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StopGracePeriod: &stopGracePeriod,
|
StopGracePeriod: &stopGracePeriod,
|
||||||
@@ -90,6 +91,7 @@ func prepare(w http.ResponseWriter, r *http.Request){
|
|||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(7*time.Second);
|
time.Sleep(7*time.Second);
|
||||||
|
|
||||||
fmt.Fprint(w, bodyDecoded.ServiceId);
|
fmt.Fprint(w, bodyDecoded.ServiceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
27
host/host.go
27
host/host.go
@@ -51,10 +51,10 @@ func Run(Config cfg.Config) {
|
|||||||
if !prepareService(Config, service, volume) {continue}
|
if !prepareService(Config, service, volume) {continue}
|
||||||
fmt.Println("Done!");
|
fmt.Println("Done!");
|
||||||
|
|
||||||
|
// Skiping Host Key Check is temporary.
|
||||||
command := `apk add --no-cache rsync openssh-client && \
|
command := `apk add --no-cache rsync openssh-client && \
|
||||||
ping -c 10 BlazenaHelper`;
|
rsync -avz --delete -e "ssh -i /ssh-key -p 2222 -o StrictHostKeyChecking=no" \
|
||||||
//rsync -avz --delete -e "ssh -i /ssh-key -p 2222 -o StrictHostKeyChecking=no" \
|
root@tasks.BlazenaHelper:/volume/ /tmp/` + volume;
|
||||||
//root@`+Config.Nodes[service.Node].Ip+`:/volume/ /tmp`
|
|
||||||
|
|
||||||
|
|
||||||
exec, err := DockerClient.ContainerExecCreate(context.Background(), "BlazenaStorage", container.ExecOptions{
|
exec, err := DockerClient.ContainerExecCreate(context.Background(), "BlazenaStorage", container.ExecOptions{
|
||||||
@@ -86,6 +86,8 @@ func Run(Config cfg.Config) {
|
|||||||
DockerClient.ContainerRemove(context.Background(), "BlazenaStorage", container.RemoveOptions{
|
DockerClient.ContainerRemove(context.Background(), "BlazenaStorage", container.RemoveOptions{
|
||||||
Force: true,
|
Force: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if !shutdown(Config){panic("Failed to shutdown docker api!");}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getServices(Config cfg.Config)[]aService{
|
func getServices(Config cfg.Config)[]aService{
|
||||||
@@ -278,3 +280,22 @@ func createStorageContainer(Config cfg.Config, DockerClient *client.Client){
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func shutdown(Config cfg.Config)bool{
|
||||||
|
rq, err := http.NewRequest("POST", Config.DockerManagerBaseUrl + "/shutdown", nil);
|
||||||
|
|
||||||
|
if err != nil{
|
||||||
|
panic("Failed to create http request"+ err.Error());
|
||||||
|
}
|
||||||
|
|
||||||
|
rq.Header.Set("Authorization", "Bearer "+ token);
|
||||||
|
rq.Close = true;
|
||||||
|
_, err = http.DefaultClient.Do(rq);
|
||||||
|
|
||||||
|
// if err != nil{
|
||||||
|
// panic("Failed to send http request"+ err.Error());
|
||||||
|
// }
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user