Skip to content

Commit

Permalink
Merge pull request #1249 from unclejack/507-add_sigterm_sigint_handli…
Browse files Browse the repository at this point in the history
…ng_to_docker_run

#507 - make docker run handle SIGINT/SIGTERM
  • Loading branch information
crosbymichael committed Aug 14, 2013
2 parents 5ad8840 + 641ddae commit 84a0274
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,17 @@ func (cli *DockerCli) CmdRun(args ...string) error {
v.Set("stderr", "1")
}

signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
go func() {
for sig := range signals {
fmt.Printf("\nReceived signal: %s; cleaning up\n", sig)
if err := cli.CmdStop("-t", "4", runResult.ID); err != nil {
fmt.Printf("failed to stop container: %v", err)
}
}
}()

if err := cli.hijack("POST", "/containers/"+runResult.ID+"/attach?"+v.Encode(), config.Tty, cli.in, cli.out); err != nil {
utils.Debugf("Error hijack: %s", err)
return err
Expand Down

0 comments on commit 84a0274

Please sign in to comment.