From 0df8a33b9e5a7c1bd1efc7268ea475b40e1d4efb Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 17 Jun 2025 16:08:53 +0800 Subject: [PATCH] fix: Fix the problem of failed start of swap in the toolbox (#9143) Refs #9142 --- agent/app/service/device.go | 17 +++++++++++------ core/app/service/entry.go | 1 - 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/agent/app/service/device.go b/agent/app/service/device.go index 5d4e894ec..1aa30b268 100644 --- a/agent/app/service/device.go +++ b/agent/app/service/device.go @@ -246,18 +246,23 @@ func (u *DeviceService) UpdateSwap(req dto.SwapHelper) error { } return operateSwapWithFile(true, req) } - std1, err := cmd.RunDefaultWithStdoutBashCf("%s dd if=/dev/zero of=%s bs=1024 count=%d", cmd.SudoHandleCmd(), req.Path, req.Size) + stdDD, err := cmd.RunDefaultWithStdoutBashCf("%s dd if=/dev/zero of=%s bs=1024 count=%d", cmd.SudoHandleCmd(), req.Path, req.Size) if err != nil { - return fmt.Errorf("handle dd path %s failed, err: %s", req.Path, std1) + return fmt.Errorf("handle dd %s failed, std: %s, err: %s", req.Path, stdDD, err) } - std2, err := cmd.RunDefaultWithStdoutBashCf("%s mkswap -f %s", cmd.SudoHandleCmd(), req.Path) + stdChmod, err := cmd.RunDefaultWithStdoutBashCf("%s chmod 0600 %s", cmd.SudoHandleCmd(), req.Path) if err != nil { - return fmt.Errorf("handle dd path %s failed, err: %s", req.Path, std2) + return fmt.Errorf("handle chmod 0600 %s failed,std: %s, err: %s", req.Path, stdChmod, err) } - std3, err := cmd.RunDefaultWithStdoutBashCf("%s swapon %s", cmd.SudoHandleCmd(), req.Path) + stdMkswap, err := cmd.RunDefaultWithStdoutBashCf("%s mkswap -f %s", cmd.SudoHandleCmd(), req.Path) + if err != nil { + return fmt.Errorf("handle mkswap -f %s failed, std: %s, err: %s", req.Path, stdMkswap, err) + } + + stdSwapon, err := cmd.RunDefaultWithStdoutBashCf("%s swapon %s", cmd.SudoHandleCmd(), req.Path) if err != nil { _, _ = cmd.RunDefaultWithStdoutBashCf("%s swapoff %s", cmd.SudoHandleCmd(), req.Path) - return fmt.Errorf("handle dd path %s failed, err: %s", req.Path, std3) + return fmt.Errorf("handle swapoff %s failed,std: %s, err: %s", req.Path, stdSwapon, err) } return operateSwapWithFile(false, req) } diff --git a/core/app/service/entry.go b/core/app/service/entry.go index 032823c75..51a327954 100644 --- a/core/app/service/entry.go +++ b/core/app/service/entry.go @@ -11,7 +11,6 @@ var ( groupRepo = repo.NewIGroupRepo() upgradeLogRepo = repo.NewIUpgradeLogRepo() - taskRepo = repo.NewITaskRepo() agentRepo = repo.NewIAgentRepo() scriptRepo = repo.NewIScriptRepo() )