{"action":"created","issue":{"url":"https://api.github.com/repos/openresty/resty-cli/issues/17","repository_url":"https://api.github.com/repos/openresty/resty-cli","labels_url":"https://api.github.com/repos/openresty/resty-cli/issues/17/labels{/name}","comments_url":"https://api.github.com/repos/openresty/resty-cli/issues/17/comments","events_url":"https://api.github.com/repos/openresty/resty-cli/issues/17/events","html_url":"https://github.com/openresty/resty-cli/pull/17","id":184400865,"number":17,"title":"add other signal handler for more use cases","user":{"login":"kiddkai","id":1309053,"avatar_url":"https://avatars.githubusercontent.com/u/1309053?v=3","gravatar_id":"","url":"https://api.github.com/users/kiddkai","html_url":"https://github.com/kiddkai","followers_url":"https://api.github.com/users/kiddkai/followers","following_url":"https://api.github.com/users/kiddkai/following{/other_user}","gists_url":"https://api.github.com/users/kiddkai/gists{/gist_id}","starred_url":"https://api.github.com/users/kiddkai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kiddkai/subscriptions","organizations_url":"https://api.github.com/users/kiddkai/orgs","repos_url":"https://api.github.com/users/kiddkai/repos","events_url":"https://api.github.com/users/kiddkai/events{/privacy}","received_events_url":"https://api.github.com/users/kiddkai/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-10-21T05:15:08Z","updated_at":"2016-10-25T01:16:57Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/openresty/resty-cli/pulls/17","html_url":"https://github.com/openresty/resty-cli/pull/17","diff_url":"https://github.com/openresty/resty-cli/pull/17.diff","patch_url":"https://github.com/openresty/resty-cli/pull/17.patch"},"body":"Hi @agentzh ,\r\n\r\nI add some other signal handlers into the `resty-cli`. The main reason I do that is let `resty` forward the signal to the actual child process(`nginx`) correctly.\r\n\r\n### Use cases\r\n\r\nI am writing an application using `resty-cli` as my application cli entry point. For example:\r\n\r\n```lua\r\n!#/path/to/resty\r\n\r\ndo_some_prev_steps()\r\n\r\nlocal children = {\r\n  fork_a_new_nginx() -- returns a pid\r\n}\r\n\r\nlocal function forward_fn(sig)\r\n  for _, ch_pid in ipairs(children) do\r\n    sig.kill(ch_pid, sig)\r\n  end\r\nend\r\n\r\nregister_signal_handlers(forward_fn)\r\n```\r\n\r\n### Current behavior\r\n\r\nWhen I do `kill -HUP <resty_pid>`. Currently the process will hangup rather than forward the\r\nsignal to the child process. Same as other signals.\r\n\r\n### Changes\r\n\r\nThis PR is adding other signals which nginx is listening to. Which including:\r\n\r\n```\r\nSIGTERM,\r\nSIGHUP,\r\nSIGUSR1,\r\nSIGUSE2,\r\nSIGWINCH,\r\nSIGQUIT\r\n```\r\n\r\n### Benefits\r\n\r\nWhen using the resty-cli in docker. The lua script will be able to correctly get the signal from\r\nthe docker daemon and do some cleanup. For example, SIGTERM when try to run docker kill. Or SIGHUP when try to reload the nginx configuration without causing any downtime :).\r\n"},"comment":{"url":"https://api.github.com/repos/openresty/resty-cli/issues/comments/255909905","html_url":"https://github.com/openresty/resty-cli/pull/17#issuecomment-255909905","issue_url":"https://api.github.com/repos/openresty/resty-cli/issues/17","id":255909905,"user":{"login":"kiddkai","id":1309053,"avatar_url":"https://avatars.githubusercontent.com/u/1309053?v=3","gravatar_id":"","url":"https://api.github.com/users/kiddkai","html_url":"https://github.com/kiddkai","followers_url":"https://api.github.com/users/kiddkai/followers","following_url":"https://api.github.com/users/kiddkai/following{/other_user}","gists_url":"https://api.github.com/users/kiddkai/gists{/gist_id}","starred_url":"https://api.github.com/users/kiddkai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kiddkai/subscriptions","organizations_url":"https://api.github.com/users/kiddkai/orgs","repos_url":"https://api.github.com/users/kiddkai/repos","events_url":"https://api.github.com/users/kiddkai/events{/privacy}","received_events_url":"https://api.github.com/users/kiddkai/received_events","type":"User","site_admin":false},"created_at":"2016-10-25T01:16:57Z","updated_at":"2016-10-25T01:16:57Z","body":"Hi @agentzh ,\r\n\r\nIt's tricky to add tests for this. But I am kind of figure out to use the `--nginx` option to add tests for it.\r\n\r\nThe steps will be like.\r\n\r\n1. `Test::Resty` create a perl file and make it executable using `--- perlsrc` block.\r\n2. `-- perlsrc` block runs as an executable which sends signals to the parent process(resty).\r\n3. `resty` forwards signal back to the `$child_pid`.\r\n4. `$child_pid` catches the signal and `die`\r\n"}}
{"actor":{"display_login":"kiddkai"}}