{"action":"created","comment":{"url":"https://api.github.com/repos/openshift/source-to-image/pulls/comments/58340328","id":58340328,"diff_hunk":"@@ -608,49 +601,54 @@ func (d *stiDocker) RunContainer(opts RunContainerOptions) error {\n \n \tcontainerName := containerNameOrID(container)\n \n-\t// Container was created, so we defer its removal.\n-\tdefer func() {\n+\t// Container was created, so we defer its removal, and also remove it if we get a SIGINT/SIGTERM/SIGQUIT/SIGHUP.\n+\tremoveContainer := func() {\n \t\tglog.V(4).Infof(\"Removing container %q ...\", containerName)\n \t\tif err := d.RemoveContainer(container.ID); err != nil {\n \t\t\tglog.Warningf(\"Failed to remove container %q: %v\", containerName, err)\n \t\t} else {\n \t\t\tglog.V(4).Infof(\"Removed container %q\", containerName)\n \t\t}\n-\t}()\n-\n-\t// Attach to the container.\n-\tglog.V(2).Infof(\"Attaching to container %q ...\", containerName)\n-\tattachOpts := opts.asDockerAttachToContainerOptions()\n-\tattachOpts.Container = container.ID\n-\tif _, err = d.client.AttachToContainerNonBlocking(attachOpts); err != nil {\n-\t\tglog.Errorf(\"Unable to attach to container %q with options %+v: %v\", containerName, attachOpts, err)\n-\t\treturn err\n-\t}\n-\n-\t// Start the container.\n-\tglog.V(2).Infof(\"Starting container %q ...\", containerName)\n-\tif err := util.TimeoutAfter(DefaultDockerTimeout, \"timeout after waiting %v for Docker to start container\", func() error {\n-\t\treturn d.client.StartContainer(container.ID, nil)\n-\t}); err != nil {\n-\t\treturn err\n \t}\n+\tdumpStack := func(signal os.Signal) {\n+\t\tif signal == syscall.SIGQUIT {\n+\t\t\tbuf := make([]byte, 1<<16)\n+\t\t\truntime.Stack(buf, true)\n+\t\t\tfmt.Printf(\"%s\", buf)\n+\t\t}\n+\t\tos.Exit(1)\n+\t}\n+\treturn util.NewInterruptHandler(dumpStack, removeContainer).Run(func() error {\n+\t\t// Attach to the container.\n+\t\tglog.V(2).Infof(\"Attaching to container %q ...\", containerName)\n+\t\tattachOpts := opts.asDockerAttachToContainerOptions()\n+\t\tattachOpts.Container = container.ID\n+\t\tif _, err = d.client.AttachToContainerNonBlocking(attachOpts); err != nil {\n+\t\t\tglog.Errorf(\"Unable to attach to container %q with options %+v: %v\", containerName, attachOpts, err)\n+\t\t\treturn err\n+\t\t}\n \n-\t// Run OnStart hook if defined.\n-\tif opts.OnStart != nil {\n-\t\tif err = opts.OnStart(container.ID); err != nil {\n+\t\t// Start the container.\n+\t\tglog.V(2).Infof(\"Starting container %q ...\", containerName)\n+\t\tif err := util.TimeoutAfter(DefaultDockerTimeout, \"timeout after waiting %v for Docker to start container\", func() error {\n+\t\t\treturn d.client.StartContainer(container.ID, nil)\n+\t\t}); err != nil {\n \t\t\treturn err\n \t\t}\n-\t}\n \n-\t// We either block waiting for a user-originated SIGINT, or wait for the\n-\t// container to terminate. When TargetImage is true, we're dealing with\n-\t// an invocation of `s2i build ... --run` so this will, e.g., run a web\n-\t// server and block until the user interrupts it. The other case is seen\n-\t// when running the assemble script or other commands that are meant to\n-\t// terminate in a finite amount of time.\n-\tif opts.TargetImage {\n-\t\trunContainerDockerRun(container, d, image)\n-\t} else {\n+\t\t// Run OnStart hook if defined.\n+\t\tif opts.OnStart != nil {\n+\t\t\tif err = opts.OnStart(container.ID); err != nil {\n+\t\t\t\treturn err\n+\t\t\t}\n+\t\t}\n+\n+\t\tif opts.TargetImage {\n+\t\t\t// When TargetImage is true, we're dealing with an invocation of `s2i build ... --run`\n+\t\t\t// so this will, e.g., run a web server and block until the user interrupts it (or\n+\t\t\t// the container exits normally).  dump port/etc information for the user.\n+\t\t\tdumpContainerInfo(container, d, image)","path":"pkg/docker/docker.go","position":122,"original_position":122,"commit_id":"462fb5f194eddf405400d6792e90530320f1d561","original_commit_id":"462fb5f194eddf405400d6792e90530320f1d561","user":{"login":"soltysh","id":576341,"avatar_url":"https://avatars.githubusercontent.com/u/576341?v=3","gravatar_id":"","url":"https://api.github.com/users/soltysh","html_url":"https://github.com/soltysh","followers_url":"https://api.github.com/users/soltysh/followers","following_url":"https://api.github.com/users/soltysh/following{/other_user}","gists_url":"https://api.github.com/users/soltysh/gists{/gist_id}","starred_url":"https://api.github.com/users/soltysh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soltysh/subscriptions","organizations_url":"https://api.github.com/users/soltysh/orgs","repos_url":"https://api.github.com/users/soltysh/repos","events_url":"https://api.github.com/users/soltysh/events{/privacy}","received_events_url":"https://api.github.com/users/soltysh/received_events","type":"User","site_admin":false},"body":":+1: especially that is what we show everywhere to do, see `docker run` of our builder image.","created_at":"2016-04-04T08:08:52Z","updated_at":"2016-04-04T08:08:52Z","html_url":"https://github.com/openshift/source-to-image/pull/452#discussion_r58340328","pull_request_url":"https://api.github.com/repos/openshift/source-to-image/pulls/452","_links":{"self":{"href":"https://api.github.com/repos/openshift/source-to-image/pulls/comments/58340328"},"html":{"href":"https://github.com/openshift/source-to-image/pull/452#discussion_r58340328"},"pull_request":{"href":"https://api.github.com/repos/openshift/source-to-image/pulls/452"}}},"pull_request":{"url":"https://api.github.com/repos/openshift/source-to-image/pulls/452","id":64684006,"html_url":"https://github.com/openshift/source-to-image/pull/452","diff_url":"https://github.com/openshift/source-to-image/pull/452.diff","patch_url":"https://github.com/openshift/source-to-image/pull/452.patch","issue_url":"https://api.github.com/repos/openshift/source-to-image/issues/452","number":452,"state":"open","locked":false,"title":"remove running containers in case of a sigterm","user":{"login":"bparees","id":4974046,"avatar_url":"https://avatars.githubusercontent.com/u/4974046?v=3","gravatar_id":"","url":"https://api.github.com/users/bparees","html_url":"https://github.com/bparees","followers_url":"https://api.github.com/users/bparees/followers","following_url":"https://api.github.com/users/bparees/following{/other_user}","gists_url":"https://api.github.com/users/bparees/gists{/gist_id}","starred_url":"https://api.github.com/users/bparees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bparees/subscriptions","organizations_url":"https://api.github.com/users/bparees/orgs","repos_url":"https://api.github.com/users/bparees/repos","events_url":"https://api.github.com/users/bparees/events{/privacy}","received_events_url":"https://api.github.com/users/bparees/received_events","type":"User","site_admin":false},"body":null,"created_at":"2016-03-30T19:35:10Z","updated_at":"2016-04-04T08:08:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"96d945fa79250dd021907a74863129a8d56d7fb5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openshift/source-to-image/pulls/452/commits","review_comments_url":"https://api.github.com/repos/openshift/source-to-image/pulls/452/comments","review_comment_url":"https://api.github.com/repos/openshift/source-to-image/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openshift/source-to-image/issues/452/comments","statuses_url":"https://api.github.com/repos/openshift/source-to-image/statuses/462fb5f194eddf405400d6792e90530320f1d561","head":{"label":"bparees:sigterm","ref":"sigterm","sha":"462fb5f194eddf405400d6792e90530320f1d561","user":{"login":"bparees","id":4974046,"avatar_url":"https://avatars.githubusercontent.com/u/4974046?v=3","gravatar_id":"","url":"https://api.github.com/users/bparees","html_url":"https://github.com/bparees","followers_url":"https://api.github.com/users/bparees/followers","following_url":"https://api.github.com/users/bparees/following{/other_user}","gists_url":"https://api.github.com/users/bparees/gists{/gist_id}","starred_url":"https://api.github.com/users/bparees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bparees/subscriptions","organizations_url":"https://api.github.com/users/bparees/orgs","repos_url":"https://api.github.com/users/bparees/repos","events_url":"https://api.github.com/users/bparees/events{/privacy}","received_events_url":"https://api.github.com/users/bparees/received_events","type":"User","site_admin":false},"repo":{"id":26235612,"name":"source-to-image","full_name":"bparees/source-to-image","owner":{"login":"bparees","id":4974046,"avatar_url":"https://avatars.githubusercontent.com/u/4974046?v=3","gravatar_id":"","url":"https://api.github.com/users/bparees","html_url":"https://github.com/bparees","followers_url":"https://api.github.com/users/bparees/followers","following_url":"https://api.github.com/users/bparees/following{/other_user}","gists_url":"https://api.github.com/users/bparees/gists{/gist_id}","starred_url":"https://api.github.com/users/bparees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bparees/subscriptions","organizations_url":"https://api.github.com/users/bparees/orgs","repos_url":"https://api.github.com/users/bparees/repos","events_url":"https://api.github.com/users/bparees/events{/privacy}","received_events_url":"https://api.github.com/users/bparees/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bparees/source-to-image","description":"A tool for building/building artifacts from source and injecting into docker images","fork":true,"url":"https://api.github.com/repos/bparees/source-to-image","forks_url":"https://api.github.com/repos/bparees/source-to-image/forks","keys_url":"https://api.github.com/repos/bparees/source-to-image/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bparees/source-to-image/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bparees/source-to-image/teams","hooks_url":"https://api.github.com/repos/bparees/source-to-image/hooks","issue_events_url":"https://api.github.com/repos/bparees/source-to-image/issues/events{/number}","events_url":"https://api.github.com/repos/bparees/source-to-image/events","assignees_url":"https://api.github.com/repos/bparees/source-to-image/assignees{/user}","branches_url":"https://api.github.com/repos/bparees/source-to-image/branches{/branch}","tags_url":"https://api.github.com/repos/bparees/source-to-image/tags","blobs_url":"https://api.github.com/repos/bparees/source-to-image/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bparees/source-to-image/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bparees/source-to-image/git/refs{/sha}","trees_url":"https://api.github.com/repos/bparees/source-to-image/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bparees/source-to-image/statuses/{sha}","languages_url":"https://api.github.com/repos/bparees/source-to-image/languages","stargazers_url":"https://api.github.com/repos/bparees/source-to-image/stargazers","contributors_url":"https://api.github.com/repos/bparees/source-to-image/contributors","subscribers_url":"https://api.github.com/repos/bparees/source-to-image/subscribers","subscription_url":"https://api.github.com/repos/bparees/source-to-image/subscription","commits_url":"https://api.github.com/repos/bparees/source-to-image/commits{/sha}","git_commits_url":"https://api.github.com/repos/bparees/source-to-image/git/commits{/sha}","comments_url":"https://api.github.com/repos/bparees/source-to-image/comments{/number}","issue_comment_url":"https://api.github.com/repos/bparees/source-to-image/issues/comments{/number}","contents_url":"https://api.github.com/repos/bparees/source-to-image/contents/{+path}","compare_url":"https://api.github.com/repos/bparees/source-to-image/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bparees/source-to-image/merges","archive_url":"https://api.github.com/repos/bparees/source-to-image/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bparees/source-to-image/downloads","issues_url":"https://api.github.com/repos/bparees/source-to-image/issues{/number}","pulls_url":"https://api.github.com/repos/bparees/source-to-image/pulls{/number}","milestones_url":"https://api.github.com/repos/bparees/source-to-image/milestones{/number}","notifications_url":"https://api.github.com/repos/bparees/source-to-image/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bparees/source-to-image/labels{/name}","releases_url":"https://api.github.com/repos/bparees/source-to-image/releases{/id}","deployments_url":"https://api.github.com/repos/bparees/source-to-image/deployments","created_at":"2014-11-05T19:23:26Z","updated_at":"2016-01-17T16:46:06Z","pushed_at":"2016-04-01T20:37:28Z","git_url":"git://github.com/bparees/source-to-image.git","ssh_url":"git@github.com:bparees/source-to-image.git","clone_url":"https://github.com/bparees/source-to-image.git","svn_url":"https://github.com/bparees/source-to-image","homepage":"","size":2280,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"openshift:master","ref":"master","sha":"fb6df26bef9876c1274132e34f4bc3006a219aca","user":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"repo":{"id":16323162,"name":"source-to-image","full_name":"openshift/source-to-image","owner":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openshift/source-to-image","description":"A tool for building/building artifacts from source and injecting into docker images","fork":false,"url":"https://api.github.com/repos/openshift/source-to-image","forks_url":"https://api.github.com/repos/openshift/source-to-image/forks","keys_url":"https://api.github.com/repos/openshift/source-to-image/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openshift/source-to-image/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openshift/source-to-image/teams","hooks_url":"https://api.github.com/repos/openshift/source-to-image/hooks","issue_events_url":"https://api.github.com/repos/openshift/source-to-image/issues/events{/number}","events_url":"https://api.github.com/repos/openshift/source-to-image/events","assignees_url":"https://api.github.com/repos/openshift/source-to-image/assignees{/user}","branches_url":"https://api.github.com/repos/openshift/source-to-image/branches{/branch}","tags_url":"https://api.github.com/repos/openshift/source-to-image/tags","blobs_url":"https://api.github.com/repos/openshift/source-to-image/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openshift/source-to-image/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openshift/source-to-image/git/refs{/sha}","trees_url":"https://api.github.com/repos/openshift/source-to-image/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openshift/source-to-image/statuses/{sha}","languages_url":"https://api.github.com/repos/openshift/source-to-image/languages","stargazers_url":"https://api.github.com/repos/openshift/source-to-image/stargazers","contributors_url":"https://api.github.com/repos/openshift/source-to-image/contributors","subscribers_url":"https://api.github.com/repos/openshift/source-to-image/subscribers","subscription_url":"https://api.github.com/repos/openshift/source-to-image/subscription","commits_url":"https://api.github.com/repos/openshift/source-to-image/commits{/sha}","git_commits_url":"https://api.github.com/repos/openshift/source-to-image/git/commits{/sha}","comments_url":"https://api.github.com/repos/openshift/source-to-image/comments{/number}","issue_comment_url":"https://api.github.com/repos/openshift/source-to-image/issues/comments{/number}","contents_url":"https://api.github.com/repos/openshift/source-to-image/contents/{+path}","compare_url":"https://api.github.com/repos/openshift/source-to-image/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openshift/source-to-image/merges","archive_url":"https://api.github.com/repos/openshift/source-to-image/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openshift/source-to-image/downloads","issues_url":"https://api.github.com/repos/openshift/source-to-image/issues{/number}","pulls_url":"https://api.github.com/repos/openshift/source-to-image/pulls{/number}","milestones_url":"https://api.github.com/repos/openshift/source-to-image/milestones{/number}","notifications_url":"https://api.github.com/repos/openshift/source-to-image/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openshift/source-to-image/labels{/name}","releases_url":"https://api.github.com/repos/openshift/source-to-image/releases{/id}","deployments_url":"https://api.github.com/repos/openshift/source-to-image/deployments","created_at":"2014-01-28T19:32:40Z","updated_at":"2016-03-28T10:31:30Z","pushed_at":"2016-04-01T20:37:29Z","git_url":"git://github.com/openshift/source-to-image.git","ssh_url":"git@github.com:openshift/source-to-image.git","clone_url":"https://github.com/openshift/source-to-image.git","svn_url":"https://github.com/openshift/source-to-image","homepage":"","size":2368,"stargazers_count":210,"watchers_count":210,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":98,"mirror_url":null,"open_issues_count":23,"forks":98,"open_issues":23,"watchers":210,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openshift/source-to-image/pulls/452"},"html":{"href":"https://github.com/openshift/source-to-image/pull/452"},"issue":{"href":"https://api.github.com/repos/openshift/source-to-image/issues/452"},"comments":{"href":"https://api.github.com/repos/openshift/source-to-image/issues/452/comments"},"review_comments":{"href":"https://api.github.com/repos/openshift/source-to-image/pulls/452/comments"},"review_comment":{"href":"https://api.github.com/repos/openshift/source-to-image/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openshift/source-to-image/pulls/452/commits"},"statuses":{"href":"https://api.github.com/repos/openshift/source-to-image/statuses/462fb5f194eddf405400d6792e90530320f1d561"}}}}