Sha256: 66e74b999c75eb711cfaedaf20dd3cfef979283e61d0d8dce61d2cf65e56d7d9

Contents?: true

Size: 1.71 KB

Versions: 4

Compression:

Stored size: 1.71 KB

Contents

require 'puma/runner'

module Puma
  class Single < Runner
    def stats
      b = @server.backlog
      r = @server.running
      %Q!{ "backlog": #{b}, "running": #{r} }!
    end

    def restart
      @server.begin_restart
    end

    def stop
      @server.stop false
    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)
    end

    def jruby_daemon?
      daemon? and @cli.jruby?
    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
        end

        already_daemon = JRubyRestart.daemon_init
      end

      output_header "single"

      if jruby_daemon?
        unless already_daemon
          pid = nil

          Signal.trap "SIGUSR2" do
            log "* Started new process #{pid} as daemon..."
            exit
          end

          Signal.trap "SIGCHLD" do
            log "! Error starting new process as daemon, exitting"
            exit 1
          end

          pid = @cli.jruby_daemon_start
          sleep
        end
      else
        load_and_bind

        if daemon?
          log "* Daemonizing..."
          Process.daemon(true)
        end
      end

      @cli.write_state

      start_control

      @server = server = start_server

      unless @options[:daemon]
        log "Use Ctrl-C to stop"
      end

      redirect_io

      @cli.events.fire_on_booted!

      begin
        server.run.join
      rescue Interrupt
        # Swallow it
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
puma-2.4.1-java lib/puma/single.rb
puma-2.4.1 lib/puma/single.rb
puma-2.4.0-java lib/puma/single.rb
puma-2.4.0 lib/puma/single.rb