Skip to content

Commit

Permalink
fix(dbm-services): ignore kill mysql client process not exist error T…
Browse files Browse the repository at this point in the history
  • Loading branch information
ymakedaq authored and iSecloud committed Jan 14, 2025
1 parent 4d173c8 commit 7bbded4
Showing 1 changed file with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"dbm-services/mysql/db-tools/dbactuator/pkg/util"
"dbm-services/mysql/db-tools/dbactuator/pkg/util/osutil"

"github.com/mitchellh/go-ps"
"github.com/shirou/gopsutil/v3/process"
)

Expand Down Expand Up @@ -271,34 +270,37 @@ func (u *UnInstallMySQLComp) ClearMachine() (err error) {
// @receiver u
// @return err
func (u *UnInstallMySQLComp) KillDirtyProcess() (err error) {
dirtyProcessNames := []string{
"mysql",
}
processes, err := ps.Processes()
mysqlClient := "mysql"
processes, err := process.Processes()
if err != nil {
return fmt.Errorf("list processes failed, err:%s", err.Error())
}
msgs := make([]string, 0)
for _, proc := range processes {
processName := proc.Executable()
if !cmutil.HasElem(processName, dirtyProcessNames) {
processName, err := proc.Name()
if err != nil {
logger.Warn("get process name failed, err:%s")
continue
}

p, err := process.NewProcess(int32(proc.Pid()))
if err != nil {
msgs = append(msgs, fmt.Sprintf("process:%s, err:%s", processName, err.Error()))
if processName != mysqlClient {
continue
}
if err := p.Terminate(); err != nil {
msg := fmt.Sprintf("terminate process %s failed, err:%s", processName, err.Error())
msgs = append(msgs, msg)
cmdline, errx := proc.Cmdline()
if errx != nil {
logger.Warn("get process cmdline failed, err:%s", errx.Error())
continue
}
for _, port := range u.Params.Ports {
if strings.Contains(cmdline, strconv.Itoa(port)) {
if err := proc.Kill(); err != nil {
if err == process.ErrorProcessNotRunning {
continue
}
logger.Error("terminate process %s failed, err:%s", processName, err.Error())
continue
}
}
}
logger.Info("success terminate dirty process %s", processName)
}
if len(msgs) != 0 {
return fmt.Errorf("failed kill %d processes, they are: %s", len(msgs), strings.Join(msgs, "\n"))
}
return nil
}

0 comments on commit 7bbded4

Please sign in to comment.