mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #17527 from wanyaoqi/fix/host-find-python-path
fix(host): find python path on guestman init
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
package guestman
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@@ -94,7 +95,8 @@ type SGuestManager struct {
|
||||
qemuMachineCpuMax map[string]uint
|
||||
qemuMaxMem int
|
||||
|
||||
cpuSet *CpuSetCounter
|
||||
cpuSet *CpuSetCounter
|
||||
pythonPath string
|
||||
}
|
||||
|
||||
func NewGuestManager(host hostutils.IHost, serversPath string) *SGuestManager {
|
||||
@@ -162,6 +164,37 @@ func (m *SGuestManager) InitQemuMaxMems(maxMems uint) {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *SGuestManager) InitPythonPath() error {
|
||||
defer func() {
|
||||
log.Infof("Python path %s", m.pythonPath)
|
||||
}()
|
||||
out, err := procutils.NewRemoteCommandAsFarAsPossible("which", "python").Output()
|
||||
if err == nil {
|
||||
m.pythonPath = string(bytes.TrimSpace(out))
|
||||
return nil
|
||||
}
|
||||
log.Infof("No python found %s: %s", out, err)
|
||||
|
||||
out, err = procutils.NewRemoteCommandAsFarAsPossible("which", "python3").Output()
|
||||
if err == nil {
|
||||
m.pythonPath = string(bytes.TrimSpace(out))
|
||||
return nil
|
||||
}
|
||||
log.Infof("No python3 found %s: %s", out, err)
|
||||
|
||||
out, err = procutils.NewRemoteCommandAsFarAsPossible("which", "python2").Output()
|
||||
if err == nil {
|
||||
m.pythonPath = string(bytes.TrimSpace(out))
|
||||
return nil
|
||||
}
|
||||
log.Infof("No python2 found %s: %s", out, err)
|
||||
return errors.Errorf("No python/python2/python3 found in PATH")
|
||||
}
|
||||
|
||||
func (m *SGuestManager) getPythonPath() string {
|
||||
return m.pythonPath
|
||||
}
|
||||
|
||||
func (m *SGuestManager) QemuLogDir() string {
|
||||
return path.Join(m.ServersPath, "logs")
|
||||
}
|
||||
|
||||
@@ -1756,7 +1756,7 @@ func (s *SKVMGuestInstance) pyLauncherPath() string {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) scriptStart(ctx context.Context) error {
|
||||
output, err := procutils.NewRemoteCommandAsFarAsPossible("python", s.pyLauncherPath()).Output()
|
||||
output, err := procutils.NewRemoteCommandAsFarAsPossible(s.manager.getPythonPath(), s.pyLauncherPath()).Output()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Start VM Failed %s %s", output, err)
|
||||
}
|
||||
|
||||
@@ -95,6 +95,9 @@ func (host *SHostService) RunService() {
|
||||
hostInstance.GetQemuMachineInfoList(), hostInstance.GetKVMMaxCpus(),
|
||||
)
|
||||
guestman.GetGuestManager().InitQemuMaxMems(uint(hostInstance.GetMemoryTotal()))
|
||||
if err := guestman.GetGuestManager().InitPythonPath(); err != nil {
|
||||
log.Fatalf("Guest manager init python path %s", err)
|
||||
}
|
||||
|
||||
hostInstance.StartRegister(2, func() {
|
||||
guestChan = guestman.GetGuestManager().Bootstrap()
|
||||
|
||||
Reference in New Issue
Block a user