Add yaml server config, restart server when ConfigMap changes

This commit is contained in:
chris
2020-08-03 16:35:41 -04:00
committed by Chris Marshall
parent ffca54fdb8
commit 1ce209bdbc
9 changed files with 326 additions and 149 deletions

View 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...)}
}