Make sure Puma has restarted properly #4127
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
We were getting an error when restarting Puma after upgrading Ruby. Even if the restart command was sent successfully, Puma silently crashed and the log had the following error:
So it looks like the crash happens because Puma was started when the application used Ruby 2.4 and now when it's restarted it still tries to use Ruby 2.4, even if the application now uses Ruby 2.5.
Objectives
Notes
I haven't found a proper way to configure Puma so we can avoid this, so as a workaround I've added the
puma:start
task after restarting Puma. If Puma was successfully restarted,puma:start
will do nothing; if Puma crashed,puma:start
will start it.To guarantee the tasks will be executed in the proper order, the tasks introduced by capistrano3-delayed_job and capistrano3-puma are cleared, and then we configure the order so first we restart Puma, then restart the Delayed Jobs processes (so there's enough time for Puma to crash if Ruby was upgraded) and then start Puma.