mirror of
https://github.com/Octops/quake-kube.git
synced 2026-04-05 17:20:33 +00:00
Add yaml server config, restart server when ConfigMap changes
This commit is contained in:
30
internal/util/exec/exec.go
Normal file
30
internal/util/exec/exec.go
Normal file
@ -0,0 +1,30 @@
|
||||
package exec
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
type Cmd struct {
|
||||
*exec.Cmd
|
||||
}
|
||||
|
||||
func (cmd *Cmd) Restart(ctx context.Context) error {
|
||||
if cmd.Process != nil {
|
||||
if err := cmd.Process.Kill(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
newCmd := exec.CommandContext(ctx, cmd.Args[0], cmd.Args[1:]...)
|
||||
newCmd.Dir = cmd.Dir
|
||||
newCmd.Env = cmd.Env
|
||||
newCmd.Stdin = cmd.Stdin
|
||||
newCmd.Stdout = cmd.Stdout
|
||||
newCmd.Stderr = cmd.Stderr
|
||||
cmd.Cmd = newCmd
|
||||
return cmd.Start()
|
||||
}
|
||||
|
||||
func CommandContext(ctx context.Context, name string, args ...string) *Cmd {
|
||||
return &Cmd{Cmd: exec.CommandContext(ctx, name, args...)}
|
||||
}
|
||||
Reference in New Issue
Block a user