getProcess finds the ais process by 'lsof' using a port number, it finds the ais process's original command line by 'ps', returns the command line for later to restart(restore) the process.
(port string)
| 498 | // getProcess finds the ais process by 'lsof' using a port number, it finds the ais process's |
| 499 | // original command line by 'ps', returns the command line for later to restart(restore) the process. |
| 500 | func getProcess(port string) (pid int, cmd string, args []string, err error) { |
| 501 | pid, err = getPID(port) |
| 502 | if err != nil { |
| 503 | return 0, "", nil, fmt.Errorf("error getting pid on port: %v", err) |
| 504 | } |
| 505 | |
| 506 | output, err := exec.Command("ps", "-p", strconv.Itoa(pid), "-o", "command").CombinedOutput() |
| 507 | if err != nil { |
| 508 | return 0, "", nil, fmt.Errorf("error executing PS command: %v", err) |
| 509 | } |
| 510 | |
| 511 | line := strings.Split(string(output), "\n")[1] |
| 512 | fields := strings.Fields(line) |
| 513 | if len(fields) == 0 { |
| 514 | return 0, "", nil, fmt.Errorf("no returned fields") |
| 515 | } |
| 516 | |
| 517 | return pid, fields[0], fields[1:], nil |
| 518 | } |
| 519 | |
| 520 | func WaitForNodeToTerminate(pid int, timeout ...time.Duration) error { |
| 521 | var ( |
no test coverage detected