{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/10459","repository_url":"https://api.github.com/repos/hashicorp/terraform","labels_url":"https://api.github.com/repos/hashicorp/terraform/issues/10459/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/terraform/issues/10459/comments","events_url":"https://api.github.com/repos/hashicorp/terraform/issues/10459/events","html_url":"https://github.com/hashicorp/terraform/issues/10459","id":192810299,"number":10459,"title":"terraform should gracefully quit on SIGTERM","user":{"login":"mildred","id":33804,"avatar_url":"https://avatars.githubusercontent.com/u/33804?v=3","gravatar_id":"","url":"https://api.github.com/users/mildred","html_url":"https://github.com/mildred","followers_url":"https://api.github.com/users/mildred/followers","following_url":"https://api.github.com/users/mildred/following{/other_user}","gists_url":"https://api.github.com/users/mildred/gists{/gist_id}","starred_url":"https://api.github.com/users/mildred/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mildred/subscriptions","organizations_url":"https://api.github.com/users/mildred/orgs","repos_url":"https://api.github.com/users/mildred/repos","events_url":"https://api.github.com/users/mildred/events{/privacy}","received_events_url":"https://api.github.com/users/mildred/received_events","type":"User","site_admin":false},"labels":[{"id":85946957,"url":"https://api.github.com/repos/hashicorp/terraform/labels/bug","name":"bug","color":"f7c6c7","default":true},{"id":127939292,"url":"https://api.github.com/repos/hashicorp/terraform/labels/core","name":"core","color":"cccccc","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-12-01T10:44:24Z","updated_at":"2016-12-08T16:01:15Z","closed_at":"2016-12-08T01:53:34Z","body":"Terraform Version: 0.7.5-132-g7e04082\r\n\r\nLooking at code, it seems that terraform gracefully shuts down on `SIGINT` (`os.Terminate` in go) but does not respond to `SIGTERM` (`syscall.SIGTERM`). The first signal is used when interrupting from command line (Ctrl-C0 while the latter is used when using the `kill` command.\r\n\r\nI am using terraform unattended in a system service, and systemd generally uses `SIGTERM` to notify a service to stop. It can be reconfigured to use `SIGINT` but it would be nice if terraform could make use of `SIGTERM`.\r\n"},"comment":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/comments/265776894","html_url":"https://github.com/hashicorp/terraform/issues/10459#issuecomment-265776894","issue_url":"https://api.github.com/repos/hashicorp/terraform/issues/10459","id":265776894,"user":{"login":"mildred","id":33804,"avatar_url":"https://avatars.githubusercontent.com/u/33804?v=3","gravatar_id":"","url":"https://api.github.com/users/mildred","html_url":"https://github.com/mildred","followers_url":"https://api.github.com/users/mildred/followers","following_url":"https://api.github.com/users/mildred/following{/other_user}","gists_url":"https://api.github.com/users/mildred/gists{/gist_id}","starred_url":"https://api.github.com/users/mildred/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mildred/subscriptions","organizations_url":"https://api.github.com/users/mildred/orgs","repos_url":"https://api.github.com/users/mildred/repos","events_url":"https://api.github.com/users/mildred/events{/privacy}","received_events_url":"https://api.github.com/users/mildred/received_events","type":"User","site_admin":false},"created_at":"2016-12-08T16:01:15Z","updated_at":"2016-12-08T16:01:15Z","body":"@mitchellh you merged part of the solution only. there is still a problem with panicwrap. it ignores the SIGTERM signal instead of forwarding it to the main process. Contrary to SIGINT, SIGTERM is generally sent only to the parent process, so ignoring it in panicwrap is not a guarantee that it will reach the main process.\r\n\r\nOn some circumstances (using killall or systemd where it kill the complete cgroup, this is configurable) this will work. on some other setups (running inside docker for instance) this will fail.\r\n\r\nThat's why I think that panicwrap should be modified to allow forwarding some signals.\r\n\r\nAlso, I was just thinking that forwarding the SIGTERM signal could cause it to be received twice on the main process, forcing the shutdown instead of keeping graceful. In that circumstance, I think SIGTERM should not trigger a force shutdown when received more than once. here are the two use cases:\r\n\r\n1. where the signal is sent to the parent process only (docker, ...):\r\n\r\n* terraform starts\r\n* SIGTERM is sent to the parent process (panicwrap)\r\n* panicwrap forwards the SIGTERM signal to the main process\r\n* the mainprocess received SIGTERM only once, it gracefully shuts down\r\n* to force shutdown, SIGINT could be used on the main process\r\n\r\n2. where the signals is sent to all processes of the control group, or through killall:\r\n\r\n* terraform starts\r\n* SIGTERM is sent to all processes, including the panicwrap process and the main process\r\n* panicwrap forwards the SIGTERM signal to the main process\r\n* the mainprocess received SIGTERM twice, it ignores the second occurence and gracefully shuts down\r\n* to force shutdown, SIGINT could be used on the main process\r\n\r\nDo you think this could be a good way to implement it ?"}}
{"actor":{"display_login":"mildred"}}