Adds mechanism to remove pid from pidfile if mount is sigtermd
parent
3d3e6a14e7
commit
aab0cb6d2a
|
@ -21,6 +21,7 @@ import (
|
|||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -29,17 +30,20 @@ import (
|
|||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/minikube/pkg/minikube/cluster"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/detect"
|
||||
"k8s.io/minikube/pkg/minikube/driver"
|
||||
"k8s.io/minikube/pkg/minikube/exit"
|
||||
"k8s.io/minikube/pkg/minikube/localpath"
|
||||
"k8s.io/minikube/pkg/minikube/mustload"
|
||||
"k8s.io/minikube/pkg/minikube/out"
|
||||
"k8s.io/minikube/pkg/minikube/reason"
|
||||
"k8s.io/minikube/pkg/minikube/style"
|
||||
pkgnetwork "k8s.io/minikube/pkg/network"
|
||||
"k8s.io/minikube/pkg/util/lock"
|
||||
"k8s.io/minikube/third_party/go9p/ufs"
|
||||
)
|
||||
|
||||
|
@ -202,7 +206,7 @@ var mountCmd = &cobra.Command{
|
|||
out.Infof("Bind Address: {{.Address}}", out.V{"Address": net.JoinHostPort(bindIP, fmt.Sprint(port))})
|
||||
|
||||
var wg sync.WaitGroup
|
||||
pid := make(chan int)
|
||||
pidchan := make(chan int)
|
||||
if cfg.Type == nineP {
|
||||
wg.Add(1)
|
||||
go func(pid chan int) {
|
||||
|
@ -211,8 +215,9 @@ var mountCmd = &cobra.Command{
|
|||
ufs.StartServer(net.JoinHostPort(bindIP, strconv.Itoa(port)), debugVal, hostPath)
|
||||
out.Step(style.Stopped, "Userspace file server is shutdown")
|
||||
wg.Done()
|
||||
}(pid)
|
||||
}(pidchan)
|
||||
}
|
||||
pid := <-pidchan
|
||||
|
||||
// Unmount if Ctrl-C or kill request is received.
|
||||
c := make(chan os.Signal, 1)
|
||||
|
@ -224,11 +229,17 @@ var mountCmd = &cobra.Command{
|
|||
if err != nil {
|
||||
out.FailureT("Failed unmount: {{.error}}", out.V{"error": err})
|
||||
}
|
||||
|
||||
err = removePidFromFile(pid)
|
||||
if err != nil {
|
||||
out.FailureT("Failed removing pid from pidfile: {{.error}}", out.V{"error": err})
|
||||
}
|
||||
|
||||
exit.Message(reason.Interrupted, "Received {{.name}} signal", out.V{"name": sig})
|
||||
}
|
||||
}()
|
||||
|
||||
err = cluster.Mount(co.CP.Runner, ip.String(), vmPath, cfg, <-pid)
|
||||
err = cluster.Mount(co.CP.Runner, ip.String(), vmPath, cfg, pid)
|
||||
if err != nil {
|
||||
if rtErr, ok := err.(*cluster.MountError); ok && rtErr.ErrorType == cluster.MountErrorConnect {
|
||||
exit.Error(reason.GuestMountCouldNotConnect, "mount could not connect", rtErr)
|
||||
|
@ -268,3 +279,58 @@ func getPort() (int, error) {
|
|||
defer l.Close()
|
||||
return l.Addr().(*net.TCPAddr).Port, nil
|
||||
}
|
||||
|
||||
// removePidFromFile looks at the default locations for the mount-pids file,
|
||||
// for the profile in use. If a file is found and its content shows PID, PID gets removed.
|
||||
func removePidFromFile(pid int) error {
|
||||
profile := viper.GetString("profile")
|
||||
paths := []string{
|
||||
localpath.MiniPath(), // legacy mount-process path for backwards compatibility
|
||||
localpath.Profile(profile),
|
||||
}
|
||||
|
||||
for _, path := range paths {
|
||||
err := removePid(path, pid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// removePid reads the file at PATH and tries to remove PID from it if found
|
||||
func removePid(path string, pid int) error {
|
||||
// is it the file we're looking for?
|
||||
pidPath := filepath.Join(path, constants.MountProcessFileName)
|
||||
if _, err := os.Stat(pidPath); os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// we found the correct file
|
||||
// we're reading the pids...
|
||||
out, err := os.ReadFile(pidPath)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "ReadFile")
|
||||
}
|
||||
|
||||
pids := []int{}
|
||||
strPids := strings.Fields(string(out))
|
||||
for _, p := range strPids {
|
||||
intPid, err := strconv.Atoi(p)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "while converting pids")
|
||||
}
|
||||
|
||||
// we skip the pid we're looking for
|
||||
if intPid == pid {
|
||||
continue
|
||||
}
|
||||
|
||||
pids = append(pids, intPid)
|
||||
}
|
||||
|
||||
// we convert the pids list back to string and write it back to file
|
||||
newPids := fmt.Sprintf("%s ", strings.Trim(strings.Join(strings.Fields(fmt.Sprint(pids)), " "), "[]"))
|
||||
return lock.WriteFile(pidPath, []byte(newPids), 0o644)
|
||||
}
|
||||
|
|
|
@ -249,6 +249,7 @@
|
|||
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "Port, der für das über den Proxy erreichbare Dashboard freigegeben wird. Wenn man 0 angibt, wird ein zufälliger Port ausgewählt.",
|
||||
"External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "Externer Adapter, auf dem der externe Switch erzeugt wird, wenn kein externer Switch gefunden wurde. (nur hyperv Treiber)",
|
||||
"Fail check if container paused": "Schlägt fehl, wenn der Container pausiert ist",
|
||||
"Failed removing pid from pidfile: {{.error}}": "",
|
||||
"Failed runtime": "Runtime fehlgeschlagen",
|
||||
"Failed to build image": "Bau des Images fehlgeschlagen",
|
||||
"Failed to cache and load images": "Cachen und laden der Images fehlgeschlagen",
|
||||
|
|
|
@ -258,6 +258,7 @@
|
|||
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "",
|
||||
"External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
|
||||
"Fail check if container paused": "",
|
||||
"Failed removing pid from pidfile: {{.error}}": "",
|
||||
"Failed runtime": "",
|
||||
"Failed to build image": "No se pudo construir la imagen",
|
||||
"Failed to cache and load images": "",
|
||||
|
|
|
@ -245,6 +245,7 @@
|
|||
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "Port exposé du tableau de bord proxyfié. Réglez sur 0 pour choisir un port aléatoire.",
|
||||
"External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "L'adaptateur externe sur lequel un commutateur externe sera créé si aucun commutateur externe n'est trouvé. (pilote hyperv uniquement)",
|
||||
"Fail check if container paused": "Échec de la vérification si le conteneur est en pause",
|
||||
"Failed removing pid from pidfile: {{.error}}": "",
|
||||
"Failed runtime": "Échec de l'exécution",
|
||||
"Failed to build image": "Échec de la création de l'image",
|
||||
"Failed to cache and load images": "Échec de la mise en cache et du chargement des images",
|
||||
|
|
|
@ -235,6 +235,7 @@
|
|||
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "プロキシー化されたダッシュボードの公開ポート。0 に設定すると、ランダムなポートが選ばれます。",
|
||||
"External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "外部スイッチが見つからない場合に、外部スイッチが作成される外部アダプター (hyperv ドライバーのみ)。",
|
||||
"Fail check if container paused": "コンテナーが一時停止しているかどうかのチェックに失敗しました",
|
||||
"Failed removing pid from pidfile: {{.error}}": "",
|
||||
"Failed runtime": "ランタイムが失敗しました",
|
||||
"Failed to build image": "イメージのビルドに失敗しました",
|
||||
"Failed to cache and load images": "イメージのキャッシュとロードに失敗しました",
|
||||
|
|
|
@ -267,6 +267,7 @@
|
|||
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "",
|
||||
"External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
|
||||
"Fail check if container paused": "",
|
||||
"Failed removing pid from pidfile: {{.error}}": "",
|
||||
"Failed runtime": "런타임이 실패하였습니다",
|
||||
"Failed to build image": "",
|
||||
"Failed to cache ISO": "ISO 캐싱에 실패하였습니다",
|
||||
|
|
|
@ -258,6 +258,7 @@
|
|||
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "",
|
||||
"External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
|
||||
"Fail check if container paused": "",
|
||||
"Failed removing pid from pidfile: {{.error}}": "",
|
||||
"Failed runtime": "",
|
||||
"Failed to build image": "",
|
||||
"Failed to cache and load images": "",
|
||||
|
|
|
@ -232,6 +232,7 @@
|
|||
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "",
|
||||
"External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
|
||||
"Fail check if container paused": "",
|
||||
"Failed removing pid from pidfile: {{.error}}": "",
|
||||
"Failed runtime": "",
|
||||
"Failed to build image": "",
|
||||
"Failed to cache and load images": "",
|
||||
|
|
|
@ -232,6 +232,7 @@
|
|||
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "",
|
||||
"External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
|
||||
"Fail check if container paused": "",
|
||||
"Failed removing pid from pidfile: {{.error}}": "",
|
||||
"Failed runtime": "",
|
||||
"Failed to build image": "",
|
||||
"Failed to cache and load images": "",
|
||||
|
|
|
@ -318,6 +318,7 @@
|
|||
"Fail check if container paused": "如果容器已挂起,则检查失败",
|
||||
"Failed runtime": "运行时失败",
|
||||
"Failed to build image": "构建镜像失败",
|
||||
"Failed removing pid from pidfile: {{.error}}": "",
|
||||
"Failed to cache ISO": "缓存ISO 时失败",
|
||||
"Failed to cache and load images": "缓存以及导入镜像失败",
|
||||
"Failed to cache binaries": "缓存二进制文件失败",
|
||||
|
@ -1208,4 +1209,4 @@
|
|||
"{{.profile}} profile is not valid: {{.err}}": "",
|
||||
"{{.type}} is not yet a supported filesystem. We will try anyways!": "",
|
||||
"{{.url}} is not accessible: {{.error}}": ""
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue