Class: Bridgetown::Commands::Start
- Inherits:
-
Bridgetown::Command
- Object
- Samovar::Command
- Bridgetown::Command
- Bridgetown::Commands::Start
- Includes:
- ConfigurationOverridable, Freyia::Setup, Inclusive
- Defined in:
- bridgetown-core/lib/bridgetown-core/commands/start.rb
Instance Method Summary collapse
-
#call ⇒ Object
rubocop:disable Metrics.
Methods included from ConfigurationOverridable
#configuration_with_overrides, include_options
Methods inherited from Bridgetown::Command
Instance Method Details
#call ⇒ Object
rubocop:disable Metrics
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'bridgetown-core/lib/bridgetown-core/commands/start.rb', line 49 def call # rubocop:disable Metrics pid_tracker = packages[Bridgetown::Foundation::Packages::PidTracker] Bridgetown.logger.writer.enable_prefix Bridgetown::Commands::Build. sleep 0.25 = HashWithDotAccess::Hash.new(self.) [:start_command] = true # Load Bridgetown configuration into thread memory = configuration_with_overrides() .port = port = load_env_and_determine_port(, ) # TODO: support Puma serving HTTPS directly? bt_bound_url = "http://#{.bind}:#{port}" # Set a local site URL in the config if one is not available if Bridgetown.env.development? && !["url"] .url = bt_bound_url.sub("0.0.0.0", "localhost") end Bridgetown::Server.new({ Host: .bind, Port: port, config: rack_config_file, }).tap do |server| if server.serveable? pid_tracker.create_pid_dir .skip_live_reload ||= !server.using_puma? build_args = ["-w"] + Array(ARGV[1..]) build_pid = Process.fork { Bridgetown::Commands::Build[*build_args].() } pid_tracker.add_pid(build_pid, file: :bridgetown) after_stop_callback = -> { say "Stopping Bridgetown server..." Bridgetown::Hooks.trigger :site, :server_shutdown Process.kill "SIGINT", build_pid pid_tracker.remove_pidfile :bridgetown # Shut down the frontend bundler etc. if they're running unless Bridgetown.env.production? || [:skip_frontend] Bridgetown::Utils::Aux.kill_processes end } Bridgetown.logger.info "" Bridgetown.logger.info "Booting #{server.name} at:", bt_bound_url.to_s.magenta Bridgetown.logger.info "" server.start(after_stop_callback) else say "Unable to find a Rack server." end end end |