节点在线、应用在线、配置在线使用令牌查询
大石头 authored at 2021-12-16 19:49:30
609.00 B
Stardust
//go:build !windows

package command

import (
	"context"
	"os"
	"os/exec"
	"syscall"
	"time"
)

func shellSupported(shell string) bool { return shell == "bash" }

func platformRunShell(ctx context.Context, _ string, script string, _ time.Duration) (string, int, bool, error) {
	path := "/bin/bash"
	if _, err := os.Stat(path); err != nil {
		path = "bash"
	}

	cmd := exec.Command(path, "-c", script)
	cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}

	return runProcess(ctx, cmd, func() error {
		if cmd.Process == nil {
			return nil
		}
		return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
	})
}