This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -276,6 +277,23 @@ func ParseKV(lines []string) map[string]string {
|
||||
return m
|
||||
}
|
||||
|
||||
// RunDetached starts name with args in a new process group (Setsid) and returns
|
||||
// immediately once the child has started. The child is reaped in the background
|
||||
// so it does not become a zombie.
|
||||
//
|
||||
// Use this for operations where the synchronous path would kill the caller
|
||||
// (e.g. "systemctl restart nadir" would SIGTERM the process serving the
|
||||
// request before the response is written).
|
||||
func RunDetached(name string, args ...string) (*StatusOutput, error) {
|
||||
cmd := exec.Command(name, args...)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
||||
if err := cmd.Start(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
go cmd.Wait()
|
||||
return OK(), nil
|
||||
}
|
||||
|
||||
// StatusOutput is the shared response for write operations that just report
|
||||
// success. Reusing one type means all such endpoints share a single OpenAPI
|
||||
// schema.
|
||||
|
||||
Reference in New Issue
Block a user