This commit is contained in:
wanyaoqi
2019-01-16 16:02:21 +08:00
parent f6d06eed73
commit 6810bd8b50
8 changed files with 26 additions and 15 deletions
+1
View File
@@ -25,6 +25,7 @@ func (s *SServiceBase) TrapSignals(quitHandler signalutils.Trap) {
utils.DumpAllGoroutineStack(log.Logger().Out)
}
signalutils.RegisterSignal(dumpStack, syscall.SIGUSR1)
signalutils.StartTrap()
}
func (s *SServiceBase) StartService() {
-1
View File
@@ -193,7 +193,6 @@ func (s *SKVMGuestInstance) getNetdevDesc(nic jsonutils.JSONObject) (string, err
ifname, _ := nic.GetString("ifname")
driver, _ := nic.GetString("driver")
// TODO
if err := s.generateNicScripts(nic); err != nil {
return "", err
}
+7 -6
View File
@@ -112,9 +112,11 @@ func (h *SHostInfo) Init() error {
if err := h.prepareEnv(); err != nil {
return err
}
log.Infof("Start parseConfig")
if err := h.parseConfig(); err != nil {
return err
}
log.Infof("Start detectHostInfo")
if err := h.detectHostInfo(); err != nil {
return err
}
@@ -144,9 +146,9 @@ func (h *SHostInfo) parseConfig() error {
h.Nics[i].SetupDhcpRelay()
}
if err := storageman.Init(h); err != nil {
return err
}
// if err := storageman.Init(h); err != nil {
// return err
// }
if man, err := isolated_device.NewManager(h); err != nil {
return fmt.Errorf("NewIsolatedManager: %v", err)
@@ -404,10 +406,9 @@ func (h *SHostInfo) TuneSystem() {
func (h *SHostInfo) resetIptables() error {
for _, tbl := range []string{"filter", "nat", "mangle"} {
_, err := exec.Command(fmt.Sprintf("iptables -t %s -F", tbl)).Output()
err := exec.Command("iptables", "-t", tbl, "-F").Run()
if err != nil {
e := err.(*exec.ExitError)
return fmt.Errorf("Fail to clean NAT iptable: %s", e.Stderr)
return fmt.Errorf("Fail to clean NAT iptable: %s", err)
}
}
return nil
+3 -2
View File
@@ -46,12 +46,13 @@ func DetectCpuInfo() (*SCPUInfo, error) {
return nil, err
}
strCpuFreq := spec["cpu_freq"]
freq, err := strconv.ParseInt(strCpuFreq, 10, 0)
freq, err := strconv.ParseFloat(strCpuFreq, 64)
if err != nil {
log.Errorln(err)
return nil, err
}
cpuinfo.cpuFreq = freq
cpuinfo.cpuFreq = int64(freq)
log.Infof("cpuinfo freq %d", cpuinfo.cpuFreq)
// cpu.Percent(interval, false)
ret, err := fileutils2.FileGetContents("/proc/cpuinfo")
-3
View File
@@ -5,9 +5,6 @@ import "yunion.io/x/onecloud/pkg/cloudcommon"
type SHostOptions struct {
cloudcommon.CommonOptions
//host agent default disable rbac
EnableRbac bool `help:"Switch on Role-based Access Control" default:"false"`
HostType string `help:"Host server type, either hypervisor or kubelet" default:"hypervisor"`
ListenInterface string `help:"Master address of host server"`
BridgeDriver string `help:"Bridge driver, bridge or openvswitch" default: "openvswitch"`
+4 -2
View File
@@ -25,6 +25,9 @@ type SHostService struct {
func (host *SHostService) StartService() {
cloudcommon.ParseOptions(&options.HostOptions, os.Args, "host.conf", "host")
app := cloudcommon.InitApp(&options.HostOptions.CommonOptions, false)
host.TrapSignals(func() { host.quitSignalHandler(app) })
// isolatedman.Init()
hostInstance := hostinfo.Instance()
@@ -48,8 +51,6 @@ func (host *SHostService) StartService() {
close(c)
})
app := cloudcommon.InitApp(&options.HostOptions.CommonOptions, false)
host.TrapSignals(func() { host.quitSignalHandler(app) })
host.initHandlers(app)
<-c // wait host and guest init
@@ -58,6 +59,7 @@ func (host *SHostService) StartService() {
}
func (host *SHostService) quitSignalHandler(app *appsrv.Application) {
log.Infof("Received quit signal")
err := app.ShowDown(context.Background())
if err != nil {
log.Errorln(err.Error())
+3 -1
View File
@@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"strings"
@@ -75,7 +76,7 @@ func ModuleIsMounted(module string) bool {
return false
} else if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
// is link
fullPath, err = os.Readlink(fullPath)
fullPath, err = filepath.EvalSymlinks(fullPath)
if err != nil {
log.Errorln(err)
}
@@ -330,6 +331,7 @@ func (c *CGroupTask) init() bool {
return false
}
}
log.Errorln(module)
if err := exec.Command("mount", "-t", "cgroup", "-o",
module, module, moduleDir).Run(); err != nil {
log.Errorln(err)
+8
View File
@@ -4,10 +4,18 @@ import (
"fmt"
"os/exec"
"time"
"yunion.io/x/log"
)
func AddTimeout(second time.Duration, callback func()) {
go func() {
defer func() {
if r := recover(); r != nil {
log.Errorln(r)
}
}()
<-time.NewTimer(second).C
callback()
}()