Class: Raptor::CLI
- Inherits:
-
Object
- Object
- Raptor::CLI
- Defined in:
- lib/raptor/cli.rb
Overview
Command-line interface for the Raptor web server.
CLI parses command-line arguments and starts the server cluster with the specified configuration options. It supports configuring the number of workers, threads, ractors, bind addresses, and various client timeout settings.
Constant Summary collapse
- DEFAULT_WORKER_COUNT =
Etc.nprocessors
- DEFAULT_OPTIONS =
{ binds: ["tcp://0.0.0.0:9292"].freeze, threads: 3, ractors: 1, workers: DEFAULT_WORKER_COUNT, rackup: "config.ru", client: { first_data_timeout: 30, chunk_data_timeout: 10, persistent_data_timeout: 65, max_body_size: nil, body_spool_threshold: 1024 * 1024, }, stats_file: "tmp/raptor.json", pidfile: nil, }.freeze
Class Method Summary collapse
-
.load_config_file(path) ⇒ Hash{Symbol => untyped}
Loads a configuration file and returns the hash it evaluates to.
Instance Method Summary collapse
-
#initialize(argv) ⇒ void
constructor
Creates a new CLI instance and parses command-line arguments.
-
#run ⇒ void
Runs the requested command.
Constructor Details
#initialize(argv) ⇒ void
Creates a new CLI instance and parses command-line arguments.
Parses the provided command-line arguments and configures the server options accordingly. A rackup file can be provided as the first positional argument (defaults to config.ru).
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/raptor/cli.rb', line 85 def initialize(argv) if argv.first == "stats" argv.shift @command = :stats else @command = :server end @options = DEFAULT_OPTIONS.dup @options[:client] = @options[:client].dup apply_config_file(extract_config_path(argv)) @parser = create_parser @parser.parse!(argv) @options[:rackup] = argv.first if @command == :server && argv.first end |
Class Method Details
.load_config_file(path) ⇒ Hash{Symbol => untyped}
Loads a configuration file and returns the hash it evaluates to.
The file is evaluated at the top level so constants like ‘Raptor::*` resolve the same as in a regular Ruby script. The final expression must be a Hash of cluster options (the same keys accepted by Raptor::Cluster#initialize).
57 58 59 60 61 62 |
# File 'lib/raptor/cli.rb', line 57 def self.load_config_file(path) config = eval(File.read(path), TOPLEVEL_BINDING, path, 1) raise ArgumentError, "Config file at #{path.inspect} must return a Hash, got #{config.class}" unless config.is_a?(Hash) config end |