Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: restart and health #1366

Merged
merged 17 commits into from
Jul 12, 2016
Merged

feature: restart and health #1366

merged 17 commits into from
Jul 12, 2016

Conversation

subnetmarco
Copy link
Member

@subnetmarco subnetmarco commented Jul 7, 2016

Adds the restart and health CLI commands.

The stop command accepts an optional --graceful parameter.

@subnetmarco subnetmarco force-pushed the refactor/restart branch 2 times, most recently from 7be85a0 to 2c3710d Compare July 7, 2016 06:28
@Tieske
Copy link
Member

Tieske commented Jul 7, 2016

shouldn't this be graceful by default, and have an option --force, as that's the more common case.

or possibly a timeout, after which it is forced.

@subnetmarco
Copy link
Member Author

subnetmarco commented Jul 7, 2016

My first thought was to have both quit and stop, but maybe that would be overkill. Then I thought that if we only keep stop, it assumes an hard stop. When you stop something you want to TERM-inate it.

Of course it can work both ways. Either a stop that sends a QUIT signal by default (instead of TERM) or the other way around. Just to me stop == TERM, and stop --graceful == QUIT.

@thibaultcha
Copy link
Member

feature/restart

@thibaultcha thibaultcha changed the title restart and health feature: restart and health Jul 7, 2016
local kill = require "kong.cmd.utils.kill"
local pl_stringx = require "pl.stringx"
local pl_path = require "pl.path"
local pl_tablex = require "pl.tablex"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please order those (I know it sounds silly but so far all new modules are ordered and as a result among many other efforts, the code is more readable).

See: https://github.com/Mashape/kong/blob/refactor/cli/kong/cmd/stop.lua#L1-L7

@subnetmarco
Copy link
Member Author

subnetmarco commented Jul 7, 2016

Also @Tieske the graceful QUIT signal returns immediately and doesn't really terminate nginx right away. If you run kong stop --graceful and then you run ps aux | grep nginx, nginx may still be running because it's still processing existing requests.

I think that a stop command that by default does not stop the service right away is very misleading.

local function is_running(pid_path)
if not pl_path.exists(pid_path) then return nil end
local code = kill(pid_path, "-0")
return code == 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to for the code local.

@Tieske
Copy link
Member

Tieske commented Jul 7, 2016

@thefosk a forcefull stop should never be the default, quitting an app half way transactions, with open files, and connections etc. is a last resort, not a default.

Default should be gracefull and blocking, with a --timeout=xxx option (which could be 0). Result is either ok, or timeout error. The --force option would quit immediately.

@thibaultcha
Copy link
Member

Just pushed a revised version of those with more tests.

@thibaultcha
Copy link
Member

(Of health and restart. I agree to make quit graceful by default too)

@subnetmarco
Copy link
Member Author

subnetmarco commented Jul 8, 2016

a forceful stop should never be the default

I disagree (nginx also disagrees, stop is a SIGTERM). With a graceful-by-default stop you have this behavior which is very wrong:

$ bin/kong stop
$ ps aux | grep nginx
marco           33552   0.0  0.0  2618256   6380   ??  S     7:28PM   0:00.02 nginx: worker process
marco           33551   0.0  0.0  2610704   5480   ??  S     7:28PM   0:00.01 nginx: worker process
marco           33550   0.0  0.0  2607528    544   ??  Ss    7:28PM   0:00.00 nginx: master process /usr/local/openresty/nginx/sbin/nginx -p /usr/local/kong -c nginx.conf

Which would mean that stop, doesn't really stop. It only stops later when the connections are done.

I am not even arguing that stop should be a SIGTERM, that it's the standard behavior of nginx itself (and of every service that I know of), my point another one and it was in the number of commands that we offer in the CLI: should we introduce kong quit (one more command to learn and document), or just use kong stop --graceful?

I am fine to have both kong stop (which correctly sends a SIGTERM) and kong quit (which properly sends a SIGQUIT), but absolutely I don't agree with a default kong stop to send a SIGQUIT.

@subnetmarco
Copy link
Member Author

I have added kong quit. So now we have:

  • Graceful: kong quit and kong reload
  • Forceful: kong stop and kong restart

it("force-leaves a node", function()
assert(helpers.kong_exec("start --conf "..helpers.test_conf_path))
local _, _, stdout = assert(helpers.kong_exec("cluster force-leave 127.0.0.1 --conf "..helpers.test_conf_path))
assert.matches("left node 127.0.0.1", stdout)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be

assert.matches("left node 127.0.0.1", stdout, nil, true)

Because arg #1 will be interpreted as a pattern otherwise, which means . can be any character. Better to have sane examples to not lead to errors in the future.

@Tieske
Copy link
Member

Tieske commented Jul 8, 2016

Which would mean that stop, doesn't really stop. It only stops later when the connections are done.

true, that's why I said;

Default should be gracefull _and blocking, with a --timeout=xxx option (which could be 0)_.

personally I find having both stop and quit commands confusing.

As an example; git commandline, where ever things might get dangerous, defaults are safe and --force overrides. Also, I don't think nginx sets the standard on "intuitive" configuration...

@Tieske
Copy link
Member

Tieske commented Jul 8, 2016

I have added kong quit. So now we have:

  • Graceful: kong quit and kong reload
  • Forceful: kong stop and kong restart

I think the graceful versions should still get a --timeout=xxx option. Such that one could script as;

kong quit --timeout=3
if error {
  kong stop
}

Commands expecting a running Kong should not accept a --conf argument
@thibaultcha thibaultcha added the pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. label Jul 11, 2016
thibaultcha and others added 7 commits July 11, 2016 17:59
- abstract away `is_running()` in `kill.lua` util
- add missing `kong health` to `kong --help` message
- some linting inherited from the base branch of this branch
@thibaultcha thibaultcha removed the pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. label Jul 12, 2016
@thibaultcha thibaultcha merged commit e17c192 into refactor/cli Jul 12, 2016
@thibaultcha thibaultcha deleted the refactor/restart branch July 12, 2016 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants