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

Send/recieve commands via pipe instead of sending signals #50

Merged
merged 24 commits into from
Aug 19, 2016

Conversation

unak
Copy link
Contributor

@unak unak commented Aug 10, 2016

Windows does not support interprocess signals.
Ruby emulates it a little, but not enough.
Therefore, ServerEngine should use another mechanism to send commands.
This patch implements piped command interface.
see also fluent/fluentd#1084

module Signal
private
def _stop(graceful)
_send_signal(!ServerEngine.windows? && graceful ? Daemon::Signals::GRACEFUL_STOP : Daemon::Signals::IMMEDIATE_STOP)
Copy link
Contributor

Choose a reason for hiding this comment

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

Daemon::Signals::IMMEDIATE_STOP is assigned dynamically to use KILL when it runs on Windows.
Are there any reason not to do it for GRACEFUL_STOP? Is it to show "it's not graceful on Windows" explicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because Windows cannot setd :TERM (GRACEFUL_STOP) to other process.

Copy link
Member

Choose a reason for hiding this comment

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

then why don't you redefine Signals::GRACEFUL_STOP to :KILL?

Copy link
Contributor

Choose a reason for hiding this comment

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

Because :KILL is not for "GRACEFUL" stop.

@tagomoris
Copy link
Contributor

In #main in daemon.rb, there aren't so many things between code for Windows and code for others (unix-like systems).
@unak IMO it's better to split these code into two methods. How do you think about this idea?


def stop(stop_graceful)
if @command_sender == "pipe"
@pm.command_pipe.write stop_graceful ? "GRACEFUL_STOP\n" : "IMMEDIATE_STOP\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about the order of priority of operators and method calls.
So it's better for me to use parenthesis.

@unak
Copy link
Contributor Author

unak commented Aug 15, 2016

@tagomoris Do you mean to write two methods windows_main and unix_main ?
The patched main is about 90 lines, and Windows specific code is only 10 lines.
I agree that main is too big, but the point of splitting should be determined by functionality, IMO.


log.warn "test4"*20
File.read("tmp/se1.log.0") =~ /test5$/
unless ServerEngine.windows?
Copy link
Contributor

@tagomoris tagomoris Aug 15, 2016

Choose a reason for hiding this comment

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

Why is this test omitted for windows environment? Just for path concatenation, or any other reasons?
It's better to use pending "reason..." to show the test skipped if there are any reason to be skipped instead of using unless block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, it's because these tests are not passed on Windows (with/without this patch).
I don't know why the tests are not passed, then I can't write the reason :P
I omitted them for my purpose, but I should leave them as is.

@tagomoris
Copy link
Contributor

@unak Right (or main_unix and main_windows :P )
That method uses two kind of pipes but one is not used in Windows environment. I think splitting these code into two methods makes much more readable than unified one.
If functionality based split is needed, we can name these methods as daemonize_with_spawn and daemonize_with_double_fork.

@tagomoris
Copy link
Contributor

LGTM.
@frsyuki @naritta Could you take a glance on this?

@tagomoris tagomoris mentioned this pull request Aug 17, 2016

@pid = nil
@command_pipe = @config.fetch(:command_pipe, nil)
@command_sender = @config.fetch(:command_sender, "signal")
Copy link
Member

Choose a reason for hiding this comment

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

Signals don't work on Windows at all, is that right?
If yes, this requires all server application developers to set "pipe" if the app is running on Windows. But most of users don't want to care about the execution platform and write the same code (I believe). So it sounds better that here uses "pipe" as the default value on Windows.

Copy link
Member

Choose a reason for hiding this comment

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

Please update README.md.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Signals don't work on Windows at all, is that right?

Yes.
To sending signals to other processes, only :INT (often ignored by target processes by various reasons) and :KILL are supported on ruby on Windows.

So it sounds better that here uses "pipe" as the default value on Windows.

At first, I thought that we had to keep compatibility with already existing ServerEngine scripts.
But, rethinking now, there are no scripts which correctly be run on Windows :P
So I agree.

@unak
Copy link
Contributor Author

unak commented Aug 17, 2016

Now this patch supports "pipe"ed Supervisor also on Unix.
Yes, I know this departs from @frsyuki's expectation, but inconsistency is removed, I hope...

@tagomoris
Copy link
Contributor

@unak I added two comments which are also commented by @frsyuki. IMO, we can remove those value assignments from configuration simply.
Others look good to me.

@tagomoris
Copy link
Contributor

LGTM. Thank you for making great change!

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