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

stop puma from sending INT on SIGHUP which we use for logrotate #2637

Merged
merged 1 commit into from Mar 9, 2018

Conversation

grosser
Copy link
Contributor

@grosser grosser commented Mar 9, 2018

@grosser grosser force-pushed the grosser/sighup branch 2 times, most recently from 132d483 to 00c1b23 Compare March 9, 2018 00:55
# The rails logger does not know what file it opened, so we have to help it https://github.com/rails/rails/issues/32211
# If we do not have a file-based logger we still do not want to kill the process, but log that we got the signal.
# We need to use self-pipe since we cannot reopen logs in an interrupt.
# This will break stdout_redirect feature of puma, which I hope nobody uses.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice comment! <3

# This will break stdout_redirect feature of puma, which I hope nobody uses.
if ENV["SERVER_MODE"]
read, write = IO.pipe
Signal.trap(:SIGHUP) { write.puts }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't this swallow SIGHUP entirely? Don't we need to propagate the signal somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

swallowing is exactly what we want since puma translates HUP -> INT

Rails.logger.info "Received SIGHUP ... reopening logs"
dev = Rails.logger.instance_variable_get(:@logdev)&.dev
path = dev.path if dev&.is_a?(File)
Rails.logger.reopen(path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We want to call Rails.logger.reopen(nil) if dev isn't a file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling with nil is a noop for all the other loggers, so not calling it is fine too ... maybe more obvious what is going on by not calling it

@grosser grosser force-pushed the grosser/sighup branch 2 times, most recently from 5f4aca5 to dfdcbf6 Compare March 9, 2018 01:49
@grosser
Copy link
Contributor Author

grosser commented Mar 9, 2018

reworked to make our hack more obvious since we don't need all this file reopen logic anyway ...

looks good ?

Rails.logger.info "Received SIGHUP ... reopening logs"
# Rails.logger does not know what file it opened, so we help it https://github.com/rails/rails/issues/32211
dev = Rails.logger.instance_variable_get(:@logdev)&.dev
Rails.logger.reopen(dev.path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't it possible for dev to be nil here, so you'd be calling nil.path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no since this must be a file logger at that point ... I'll remove the &. too that was ;eftover from previous approach

Copy link
Collaborator

@jonmoter jonmoter left a comment

Choose a reason for hiding this comment

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

Other than the possibility of calling path on nil, looks good.

@grosser grosser merged commit a36063d into master Mar 9, 2018
@grosser grosser deleted the grosser/sighup branch March 9, 2018 17:02
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.

None yet

2 participants