mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
add rpm file, add socket used check
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
[Unit]
|
||||
Description=Yunion Command Executor
|
||||
Documentation=https://docs.yunion.cn
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
Group=root
|
||||
ExecStart=/opt/yunion/bin/executor-server
|
||||
WorkingDirectory=/opt/yunion/bin
|
||||
KillMode=process
|
||||
Restart=always
|
||||
RestartSec=30
|
||||
LimitNOFILE=500000
|
||||
LimitNPROC=500000
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
2
build/executor-server/vars
Normal file
2
build/executor-server/vars
Normal file
@@ -0,0 +1,2 @@
|
||||
DESCRIPTION="Yunion Executor Server Command Line Utility"
|
||||
SERVICE="yes"
|
||||
@@ -58,6 +58,12 @@ func (s *SExecuteService) runService() {
|
||||
grpcServer := grpc.NewServer()
|
||||
apis.RegisterExecutorServer(grpcServer, &server.Executor{})
|
||||
if _, err := os.Stat(socketPath); !os.IsNotExist(err) {
|
||||
conn, err := net.Dial("unix", socketPath)
|
||||
if err == nil {
|
||||
conn.Close()
|
||||
log.Fatalf("socket %s already listening", socketPath)
|
||||
}
|
||||
|
||||
// socket file already exist, remove first
|
||||
if err := os.Remove(socketPath); err != nil {
|
||||
log.Fatalln(err)
|
||||
|
||||
@@ -916,7 +916,7 @@ func (s *SKVMGuestInstance) Stop() bool {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) scriptStart() error {
|
||||
output, err := procutils.NewCommand("sh", s.GetStartScriptPath()).Output()
|
||||
output, err := procutils.NewRemoteCommandAsFarAsPossible("sh", s.GetStartScriptPath()).Output()
|
||||
if err != nil {
|
||||
s.scriptStop()
|
||||
return fmt.Errorf("Start VM Failed %s %s", output, err)
|
||||
@@ -925,7 +925,7 @@ func (s *SKVMGuestInstance) scriptStart() error {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) scriptStop() bool {
|
||||
_, err := procutils.NewCommand("sh", s.GetStopScriptPath()).Output()
|
||||
_, err := procutils.NewRemoteCommandAsFarAsPossible("sh", s.GetStopScriptPath()).Output()
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return false
|
||||
|
||||
@@ -209,12 +209,12 @@ func (s *SDeployService) RunService() {
|
||||
|
||||
func (s *SDeployService) FixPathEnv() error {
|
||||
var paths = []string{
|
||||
"/usr/bin",
|
||||
"/usr/local/sbin",
|
||||
"/usr/local/bin",
|
||||
"/sbin",
|
||||
"/bin",
|
||||
"/usr/sbin",
|
||||
"/usr/bin",
|
||||
}
|
||||
return os.Setenv("PATH", strings.Join(paths, ":"))
|
||||
}
|
||||
|
||||
@@ -253,12 +253,12 @@ func (h *SHostInfo) prepareEnv() error {
|
||||
return fmt.Errorf("Qemu not installed")
|
||||
}
|
||||
|
||||
_, err = procutils.NewCommand(qemutils.GetQemu(""), "-version").Output()
|
||||
_, err = procutils.NewRemoteCommandAsFarAsPossible(qemutils.GetQemu(""), "-version").Output()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Qemu/Kvm not installed")
|
||||
}
|
||||
|
||||
_, err = procutils.NewCommand("/sbin/ethtool", "-h").Output()
|
||||
_, err = procutils.NewCommand("ethtool", "-h").Output()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Ethtool not installed")
|
||||
}
|
||||
@@ -547,7 +547,7 @@ func (h *SHostInfo) detectiveSyssoftwareInfo() error {
|
||||
|
||||
func (h *SHostInfo) detectiveQemuVersion() error {
|
||||
cmd := qemutils.GetQemu(options.HostOptions.DefaultQemuVersion)
|
||||
version, err := procutils.NewCommand(cmd, "--version").Output()
|
||||
version, err := procutils.NewRemoteCommandAsFarAsPossible(cmd, "--version").Output()
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return err
|
||||
|
||||
@@ -76,7 +76,8 @@ func (r *SRbdImageCache) Acquire(ctx context.Context, zone, srcUrl, format strin
|
||||
r.imageName = localImageCache.GetName()
|
||||
if !r.Load() {
|
||||
log.Debugf("convert local image %s to rbd pool %s", r.imageId, r.Manager.GetPath())
|
||||
err := procutils.NewCommand(qemutils.GetQemuImg(), "convert", "-O", "raw", localImageCache.GetPath(), r.GetPath()).Run()
|
||||
err := procutils.NewRemoteCommandAsFarAsPossible(qemutils.GetQemuImg(),
|
||||
"convert", "-O", "raw", localImageCache.GetPath(), r.GetPath()).Run()
|
||||
if err != nil {
|
||||
log.Errorf("failed to convert image %s", options.HostOptions.ServersPath)
|
||||
return false
|
||||
|
||||
@@ -658,7 +658,7 @@ func (s *SRbdStorage) saveToGlance(ctx context.Context, imageId, imagePath strin
|
||||
format = options.HostOptions.DefaultImageSaveFormat
|
||||
}
|
||||
|
||||
err = procutils.NewCommand(qemutils.GetQemuImg(),
|
||||
err = procutils.NewRemoteCommandAsFarAsPossible(qemutils.GetQemuImg(),
|
||||
"convert", "-f", "raw", "-O", format, imagePath, tmpImageFile).Run()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -27,29 +27,33 @@ var (
|
||||
type SSystemdServiceManager struct {
|
||||
}
|
||||
|
||||
func systemctl(args ...string) *procutils.Command {
|
||||
return procutils.NewRemoteCommandAsFarAsPossible("systemctl", args...)
|
||||
}
|
||||
|
||||
func (manager *SSystemdServiceManager) Detect() bool {
|
||||
return procutils.NewCommand("systemctl", "--version").Run() == nil
|
||||
return systemctl("--version").Run() == nil
|
||||
}
|
||||
|
||||
func (manager *SSystemdServiceManager) Start(srvname string) error {
|
||||
return procutils.NewCommand("systemctl", "restart", srvname).Run()
|
||||
return systemctl("restart", srvname).Run()
|
||||
}
|
||||
|
||||
func (manager *SSystemdServiceManager) Enable(srvname string) error {
|
||||
return procutils.NewCommand("systemctl", "enable", srvname).Run()
|
||||
return systemctl("enable", srvname).Run()
|
||||
}
|
||||
|
||||
func (manager *SSystemdServiceManager) Stop(srvname string) error {
|
||||
return procutils.NewCommand("systemctl", "stop", srvname).Run()
|
||||
return systemctl("stop", srvname).Run()
|
||||
}
|
||||
|
||||
func (manager *SSystemdServiceManager) Disable(srvname string) error {
|
||||
return procutils.NewCommand("systemctl", "disable", srvname).Run()
|
||||
return systemctl("disable", srvname).Run()
|
||||
}
|
||||
|
||||
func (manager *SSystemdServiceManager) GetStatus(srvname string) SServiceStatus {
|
||||
res, _ := procutils.NewCommand("systemctl", "status", srvname).Output()
|
||||
res2, _ := procutils.NewCommand("systemctl", "is-enabled", srvname).Output()
|
||||
res, _ := systemctl("status", srvname).Output()
|
||||
res2, _ := systemctl("is-enabled", srvname).Output()
|
||||
return parseSystemdStatus(string(res), string(res2), srvname)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,14 +9,18 @@ import (
|
||||
"yunion.io/x/executor/client"
|
||||
)
|
||||
|
||||
var execInstance Executor
|
||||
var (
|
||||
execInstance Executor
|
||||
localExecutor = new(defaultExecutor)
|
||||
_remoteExecutor = new(remoteExecutor)
|
||||
)
|
||||
|
||||
func init() {
|
||||
execInstance = new(defaultExecutor)
|
||||
execInstance = localExecutor
|
||||
}
|
||||
|
||||
func SetRemoteExecutor() {
|
||||
execInstance = new(remoteExecutor)
|
||||
execInstance = _remoteExecutor
|
||||
}
|
||||
|
||||
type Cmd interface {
|
||||
|
||||
@@ -38,7 +38,7 @@ func NewCommand(name string, args ...string) *Command {
|
||||
return &Command{
|
||||
path: name,
|
||||
args: args,
|
||||
cmd: execInstance.Command(name, args...),
|
||||
cmd: localExecutor.Command(name, args...),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,16 @@ func NewCommandContext(ctx context.Context, name string, args ...string) *Comman
|
||||
return &Command{
|
||||
path: name,
|
||||
args: args,
|
||||
cmd: execInstance.CommandContext(ctx, name, args...),
|
||||
cmd: localExecutor.CommandContext(ctx, name, args...),
|
||||
}
|
||||
}
|
||||
|
||||
// exec remote command as far as possible
|
||||
func NewRemoteCommandAsFarAsPossible(name string, args ...string) *Command {
|
||||
return &Command{
|
||||
path: name,
|
||||
args: args,
|
||||
cmd: execInstance.Command(name, args...),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ var (
|
||||
)
|
||||
|
||||
func getQemuImgVersion() string {
|
||||
out, err := procutils.NewCommand(qemutils.GetQemuImg(), "--version").Output()
|
||||
out, err := procutils.NewRemoteCommandAsFarAsPossible(qemutils.GetQemuImg(), "--version").Output()
|
||||
if err != nil {
|
||||
log.Errorf("check qemu-img version fail %s", out)
|
||||
return ""
|
||||
|
||||
@@ -111,7 +111,7 @@ func (img *SQemuImage) parse() error {
|
||||
img.ActualSizeBytes = fileInfo.Size()
|
||||
}
|
||||
}
|
||||
cmd := procutils.NewCommand(qemutils.GetQemuImg(), "info", img.Path)
|
||||
cmd := procutils.NewRemoteCommandAsFarAsPossible(qemutils.GetQemuImg(), "info", img.Path)
|
||||
|
||||
var stdin io.WriteCloser
|
||||
var err error
|
||||
@@ -234,7 +234,7 @@ func (img *SQemuImage) doConvert(name string, format TImageFormat, options []str
|
||||
}
|
||||
cmdline = append(cmdline, img.Path, name)
|
||||
log.Infof("XXXX qemu-img command: %s", cmdline)
|
||||
cmd := procutils.NewCommand("ionice", cmdline...)
|
||||
cmd := procutils.NewRemoteCommandAsFarAsPossible("ionice", cmdline...)
|
||||
var stdin io.WriteCloser
|
||||
var err error
|
||||
if len(img.Password) > 0 || len(password) > 0 {
|
||||
@@ -443,7 +443,7 @@ func (img *SQemuImage) create(sizeMB int, format TImageFormat, options []string)
|
||||
if sizeMB > 0 {
|
||||
args = append(args, fmt.Sprintf("%dM", sizeMB))
|
||||
}
|
||||
cmd := procutils.NewCommand("ionice", args...)
|
||||
cmd := procutils.NewRemoteCommandAsFarAsPossible("ionice", args...)
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Errorf("%v create error %s %s", args, output, err)
|
||||
@@ -490,7 +490,7 @@ func (img *SQemuImage) Resize(sizeMB int) error {
|
||||
if !img.IsValid() {
|
||||
return fmt.Errorf("self is not valid")
|
||||
}
|
||||
cmd := procutils.NewCommand("ionice", "-c", strconv.Itoa(int(img.IoLevel)),
|
||||
cmd := procutils.NewRemoteCommandAsFarAsPossible("ionice", "-c", strconv.Itoa(int(img.IoLevel)),
|
||||
qemutils.GetQemuImg(), "resize", img.Path, fmt.Sprintf("%dM", sizeMB))
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
@@ -510,7 +510,7 @@ func (img *SQemuImage) Rebase(backPath string, force bool) error {
|
||||
args = append(args, "-u")
|
||||
}
|
||||
args = append(args, "-b", backPath, img.Path)
|
||||
cmd := procutils.NewCommand("ionice", args...)
|
||||
cmd := procutils.NewRemoteCommandAsFarAsPossible("ionice", args...)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
log.Errorf("rebase fail %s", err)
|
||||
|
||||
Reference in New Issue
Block a user