Skip to content

Instantly share code, notes, and snippets.

@termie
Created July 14, 2015 20:43
Show Gist options
  • Save termie/29d0d711e376812d5f10 to your computer and use it in GitHub Desktop.
Save termie/29d0d711e376812d5f10 to your computer and use it in GitHub Desktop.
kill stuff in a container
// killProcesses sends a signal to all the processes on the machine except
// for PID 1, somewhat naive but seems to work
func (s *WatchStep) killProcesses(containerID string, signal string) error {
client, err := NewDockerClient(s.options.DockerOptions)
if err != nil {
return err
}
cmd := []string{`/bin/sh`, `-c`, fmt.Sprintf(`ps | grep -v PID | awk "{if (\$1 != 1) print \$1}" | xargs -n 1 kill -s %s`, signal)}
err = client.ExecOne(containerID, cmd, os.Stdout)
if err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment