lib/puma/single.rb in piesync-puma-3.12.6.1 vs lib/puma/single.rb in piesync-puma-5.4.0.1

- old
+ new

@@ -11,111 +11,55 @@ # # At the core of this class is running an instance of `Puma::Server` which # gets created via the `start_server` method from the `Puma::Runner` class # that this inherits from. class Single < Runner + # @!attribute [r] stats def stats - b = @server.backlog || 0 - r = @server.running || 0 - t = @server.pool_capacity || 0 - m = @server.max_threads || 0 - %Q!{ "backlog": #{b}, "running": #{r}, "pool_capacity": #{t}, "max_threads": #{m} }! + { + started_at: @started_at.utc.iso8601 + }.merge(@server.stats) end def restart @server.begin_restart end def stop - @server.stop false + @server.stop(false) if @server end def halt @server.halt end def stop_blocked log "- Gracefully stopping, waiting for requests to finish" @control.stop(true) if @control - @server.stop(true) + @server.stop(true) if @server end - def jruby_daemon? - daemon? and Puma.jruby? - end - - def jruby_daemon_start - require 'puma/jruby_restart' - JRubyRestart.daemon_start(@restart_dir, @launcher.restart_args) - end - def run - already_daemon = false - - if jruby_daemon? - require 'puma/jruby_restart' - - if JRubyRestart.daemon? - # load and bind before redirecting IO so errors show up on stdout/stderr - load_and_bind - redirect_io - end - - already_daemon = JRubyRestart.daemon_init - end - output_header "single" - if jruby_daemon? - if already_daemon - JRubyRestart.perm_daemonize - else - pid = nil + load_and_bind - Signal.trap "SIGUSR2" do - log "* Started new process #{pid} as daemon..." - - # Must use exit! so we don't unwind and run the ensures - # that will be run by the new child (such as deleting the - # pidfile) - exit!(true) - end - - Signal.trap "SIGCHLD" do - log "! Error starting new process as daemon, exiting" - exit 1 - end - - jruby_daemon_start - sleep - end - else - if daemon? - log "* Daemonizing..." - Process.daemon(true) - redirect_io - end - - load_and_bind - end - Plugins.fire_background @launcher.write_state start_control @server = server = start_server + server_thread = server.run - unless daemon? - log "Use Ctrl-C to stop" - redirect_io - end + log "Use Ctrl-C to stop" + redirect_io @launcher.events.fire_on_booted! begin - server.run.join + server_thread.join rescue Interrupt # Swallow it end end end