fix: 添加后台执行设置以防止进程阻塞
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/creack/pty"
|
"github.com/creack/pty"
|
||||||
)
|
)
|
||||||
@@ -13,10 +12,7 @@ import (
|
|||||||
func NewClientSession(cols, rows int) (*LocalClientSession, error) {
|
func NewClientSession(cols, rows int) (*LocalClientSession, error) {
|
||||||
// Create arbitrary command.
|
// Create arbitrary command.
|
||||||
c := exec.Command("bash")
|
c := exec.Command("bash")
|
||||||
// 为防止当前进程阻塞,设置为后台执行
|
|
||||||
c.SysProcAttr = &syscall.SysProcAttr{
|
|
||||||
Setpgid: true, // 设置新进程组,确保安装进程与当前进程不在同一进程组
|
|
||||||
}
|
|
||||||
// Start the command with a pty.
|
// Start the command with a pty.
|
||||||
ptmx, err := pty.StartWithSize(c, &pty.Winsize{
|
ptmx, err := pty.StartWithSize(c, &pty.Winsize{
|
||||||
Rows: uint16(rows), // ws_row: Number of rows (in cells).
|
Rows: uint16(rows), // ws_row: Number of rows (in cells).
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ func (r NeVersion) operateCommand(action, neType string, neFilePaths []string) (
|
|||||||
|
|
||||||
// 2s后执行omc相关命令
|
// 2s后执行omc相关命令
|
||||||
cmdStrArr = append(cmdStrArr, fmt.Sprintf("sudo rm -f /tmp/operate_run_%s_omc.out \n", action))
|
cmdStrArr = append(cmdStrArr, fmt.Sprintf("sudo rm -f /tmp/operate_run_%s_omc.out \n", action))
|
||||||
cmdStrArr = append(cmdStrArr, fmt.Sprintf("nohup sh -c \"sleep 2s && %s\" > /tmp/operate_run_%s_omc.out2>&1 & \n", strings.Join(omcStrArr, " && "), action))
|
cmdStrArr = append(cmdStrArr, fmt.Sprintf("nohup sh -c \"sleep 2s && %s\" > /tmp/operate_run_%s_omc.out >&1 & \n", strings.Join(omcStrArr, " && "), action))
|
||||||
cmdStrArr = append(cmdStrArr, fmt.Sprintf("echo '%s' \n", okFlagStr))
|
cmdStrArr = append(cmdStrArr, fmt.Sprintf("echo '%s' \n", okFlagStr))
|
||||||
return okFlagStr, cmdStrArr, nil
|
return okFlagStr, cmdStrArr, nil
|
||||||
} else if neType == "IMS" {
|
} else if neType == "IMS" {
|
||||||
|
|||||||
Reference in New Issue
Block a user