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
Restarting via USR2 forgets about ARGV arguments #1363
Comments
(The same behavior exists when restarting via USR1 btw) I experimented a bit and created a dummy $ bundle exec puma -b tcp://127.0.0.1:9292 Then I gave it a USR1 signal:
As can be seen, it used the right port here; it properly handled the USR1 signal. So I am suspecting it is specifically when |
small example with reproduction based on |
Here goes: # config.ru
class HelloWorld
def call(env)
[200, {"Content-Type" => "text/html"}, ["Hello World!"]]
end
end
run HelloWorld.new
# server.rb
#!/usr/bin/env ruby
require 'rack'
server = Rack::Server.new(
config: 'config.ru',
server: 'puma',
Port: ARGV[0]
)
server.start Here is the output when running this. Note how it forgets the port number when restarted. I would guess this is because the $ bundle exec ruby server.rb 12345
Puma starting in single mode...
* Version 3.9.1 (ruby 2.4.1-p111), codename: Private Caller
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://0.0.0.0:12345
Use Ctrl-C to stop
* Restarting...
Puma starting in single mode...
* Version 3.9.1 (ruby 2.4.1-p111), codename: Private Caller
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://0.0.0.0:9292
* Closing unused inherited connection: tcp://0.0.0.0:12345
Use Ctrl-C to stop |
@stereobooster Any ideas? |
Yeah, starting a server via Rack::Server like this and then expecting the port to be remembered is Not Supported. Example of something you could do: require 'puma/cli'
cli = Puma::CLI.new(["--port=12345"])
cli.run An alternative might be to use |
Thanks @nateberkopec, sorry for the delay on my part. Our problem is that we do not only use the command line arguments for the port number, but we also have other things like We can use ENV variables for all of this, but it feels a bit clumsy. Are you saying this is the expected behavior, the command line arguments are expected to be erased between restarts? Is this something that could be fixed, would you accept PRs that changes the behavior or do you consider this to be "the way it should behave"? |
Well, it does work when you use Puma::CLI, which is what is supported. |
Ah, I see - thanks for making that super-clear! Keep up the great work here and elsewhere, @nateberkopec. 👍 |
@nateberkopec Trying out this approach now, but I am struggling with getting it accepting my def start_server
config_path = File.join(UxFactory::ServerConfig.instance_path, 'server/config.ru')
cli = Puma::CLI.new(["--port=12345 #{config_path}"])
cli.run
end ...but this is what it outputs:
The rackup = Rack::Builder.app do
use Rack::Chunked
use Rack::Deflater unless UxFactory::ServerConfig.disable_compression
run UxFactory::Server::SinatraApp.new
end
run rackup
|
Anyone? |
@perlun Puma::CLI.new takes an array of arguments: |
Doh! Silly me. 😃 Thanks, will try that instead. |
FWIW, the
|
I noted this while trying to apply suggestions from #1363.
Steps to reproduce
(
uxfactory
is our own in-house application server, built on top of Sinatra, puma etc)Expected behavior
When restarting, the same port as used when starting puma should be used.
Actual behavior
It fell back to using port 8000, which is the default port used by uxfactory.
System configuration
Ruby version: 2.4.1
Rails version: N/A
Extended description
Here is the code for our Puma startup:
I wonder if the problem here could be with command line arguments or something? As can be seen in this case, the specific port number (8777) is being passed in as a command line argument to the initial process. When the USR2 handler detects a restart coming, does it pass in the original command line arguments which were passed to the parent process or how does it work?
The text was updated successfully, but these errors were encountered: