mirror of
https://github.com/linka-cloud/d2vm.git
synced 2025-02-18 14:35:50 +00:00
d2vm/run: hetzner: use tcp to wait for the server to be ready, do not store server key in UserKnownHostsFile
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
parent
1ec9d99445
commit
b7ebeeae45
@ -5,9 +5,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
@ -242,21 +242,10 @@ func runHetzner(ctx context.Context, imgPath string, stdin io.Reader, stderr io.
|
|||||||
if err := <-errs; err != nil {
|
if err := <-errs; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logrus.Infof("server created")
|
|
||||||
remove = false
|
remove = false
|
||||||
args := []string{"-o", "StrictHostKeyChecking=no"}
|
logrus.Infof("waiting for server to be ready")
|
||||||
if hetznerSSHKeyPath != "" {
|
|
||||||
args = append(args, "-i", hetznerSSHKeyPath)
|
|
||||||
}
|
|
||||||
args = append(args, fmt.Sprintf("%s@%s", hetznerSSHUser, sres.Server.PublicNet.IPv4.IP.String()))
|
|
||||||
makeCmd := func() *exec.Cmd {
|
|
||||||
cmd := exec.CommandContext(ctx, "ssh", args...)
|
|
||||||
cmd.Stdin = stdin
|
|
||||||
cmd.Stderr = stderr
|
|
||||||
cmd.Stdout = stdout
|
|
||||||
return cmd
|
|
||||||
}
|
|
||||||
t := time.NewTimer(time.Minute)
|
t := time.NewTimer(time.Minute)
|
||||||
|
wait:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-t.C:
|
case <-t.C:
|
||||||
@ -264,16 +253,25 @@ func runHetzner(ctx context.Context, imgPath string, stdin io.Reader, stderr io.
|
|||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
default:
|
default:
|
||||||
cmd := makeCmd()
|
conn, err := net.Dial("tcp", fmt.Sprintf("%s:22", sres.Server.PublicNet.IPv4.IP.String()))
|
||||||
if err := cmd.Run(); err != nil {
|
if err == nil {
|
||||||
if strings.Contains(err.Error(), "exit status 255") {
|
conn.Close()
|
||||||
time.Sleep(time.Second)
|
break wait
|
||||||
continue
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
} else {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
time.Sleep(time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
args := []string{"-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null"}
|
||||||
|
if hetznerSSHKeyPath != "" {
|
||||||
|
args = append(args, "-i", hetznerSSHKeyPath)
|
||||||
|
}
|
||||||
|
args = append(args, fmt.Sprintf("%s@%s", hetznerSSHUser, sres.Server.PublicNet.IPv4.IP.String()))
|
||||||
|
cmd := exec.CommandContext(ctx, "ssh", args...)
|
||||||
|
cmd.Stdin = stdin
|
||||||
|
cmd.Stderr = stderr
|
||||||
|
cmd.Stdout = stdout
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user