yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
blob 63ab3730b5ef84a9f659e06c1847fc55f2e9f3ae 1754 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
# Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
# License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
# frozen_string_literal: true
require_relative '../yahns'

module Yahns::RackupHandler # :nodoc:
  def self.default_host
    environment  = ENV['RACK_ENV'] || 'development'
    environment == 'development' ? '127.0.0.1' : '0.0.0.0'
  end

  def self.run(app, o)
    cfg = Yahns::Config.new
    cfg.instance_eval do
      # we need this because "rackup -D" sends us to "/", which might be
      # fine for most apps, but we have SIGUSR2 restarts to support
      working_directory(Yahns::START[:cwd])

      app(:rack, app) do
        addr = o[:listen] || "#{o[:Host]||default_host}:#{o[:Port]||8080}"
        # allow listening to multiple addresses
        addr.split(',').each { |l| listen(l) }

        val = o[:client_timeout] and client_timeout(val)
      end

      queue do
        wt = o[:worker_threads] and worker_threads(wt)
      end

      %w(stderr_path stdout_path).each do |x|
        val = o[x] and __send__(x, val)
      end
    end
    Yahns::Server.new(cfg).start.join
  end

  # this is called by Rack::Server
  def self.valid_options
    # these should be the most common options
    {
      "listen=ADDRESS" => "address(es) to listen on (e.g. /tmp/sock)",
      "worker_threads=NUM" => "number of worker threads to run",

      # this affects how quickly graceful shutdown goes
      "client_timeout=SECONDS" => "timeout for idle clients",

      # I don't want these here, but rackup supports daemonize and
      # we lose useful information when that sends stdout/stderr to /dev/null
      "stderr_path=PATH" => "stderr destination",
      "stdout_path=PATH" => "stdout destination",
    }
  end
end

debug log:

solving 63ab373 ...
found 63ab373 in https://yhbt.net/yahns.git

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/yahns.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).