- proc.nohup:后台运行命令并将 stdout/stderr 追加写入日志, Unix 下新会话、Windows 下 DETACHED_PROCESS 脱离终端 - docker.save:等价 docker save <镜像> -o <镜像名>.tar,文件名按 仓库名+标签生成(alpine:3.20 → alpine_3.20.tar),传镜像 ID 时 先解析出对应名称;docker.load 改为归档文件作位置参数 - 移除 Podman 支持,所有容器命令只走 docker
28 lines
858 B
Go
28 lines
858 B
Go
//go:build !windows
|
|
|
|
package executor
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"syscall"
|
|
)
|
|
|
|
// prepareNohup applies the Unix half of `nohup ... &`: the child's stdin is
|
|
// closed, stdout and stderr are appended to logFile ("> output.log 2>&1") and,
|
|
// with detach, the child becomes a session leader with no controlling terminal
|
|
// — which also shields it from terminal-generated SIGHUP/SIGINT/SIGQUIT.
|
|
//
|
|
// Go's os/exec cannot reset a child's signal dispositions before exec (there is
|
|
// no hook between fork and exec), so "ignore SIGHUP" itself is only provided by
|
|
// the detached session, not by a signal handler.
|
|
func prepareNohup(cmd *exec.Cmd, logFile *os.File, detach bool) {
|
|
// A nil stdin hands the child /dev/null instead of the terminal.
|
|
cmd.Stdout = logFile
|
|
cmd.Stderr = logFile
|
|
|
|
if detach {
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
|
}
|
|
}
|