Class: ReactOnRails::Dev::ProcessManager
- Inherits:
-
Object
- Object
- ReactOnRails::Dev::ProcessManager
- Defined in:
- lib/react_on_rails/dev/process_manager.rb
Constant Summary collapse
- VERSION_CHECK_TIMEOUT =
Timeout for version check operations to prevent hanging
5- ENV_KEYS_TO_PRESERVE =
Env vars set after Bundler.setup that must survive with_unbundled_env. with_unbundled_env restores the pre-Bundler env snapshot, so any var set at runtime (e.g. PORT by PortSelector) is lost. We capture them before entering the block and pass them explicitly to system(). This follows the same pattern used by Rails’ bundle_command (railties), Spring’s process spawning, and this codebase’s own PackGenerator.
REACT_ON_RAILS_BASE_PORT and CONDUCTOR_PORT are intentionally excluded: by the time sub-processes spawn, configure_ports has already derived concrete values into PORT / SHAKAPACKER_DEV_SERVER_PORT / RENDERER_PORT / REACT_RENDERER_URL. Sub-processes should use those fixed ports rather than re-deriving from the base. SHAKAPACKER_SKIP_PRECOMPILE_HOOK is also runtime-only and must survive Bundler’s env reset so nested shakapacker commands don’t rerun the hook. RENDERER_URL is the legacy name for REACT_RENDERER_URL; preserved for mid-migration users (see ServerManager#warn_if_legacy_renderer_url_env_used). Inclusion here also matters when base-port mode scrubs the legacy var: ‘preserve_runtime_env_vars` returns `nil` (not the string “nil”) for unset keys, which `Process.spawn`/`system` use to explicitly unset the variable in the child — preventing `with_unbundled_env` from resurrecting a stale pre-Bundler value. See the comment on `preserve_runtime_env_vars` below.
%w[ PORT SHAKAPACKER_DEV_SERVER_PORT RENDERER_PORT REACT_RENDERER_URL RENDERER_URL SHAKAPACKER_SKIP_PRECOMPILE_HOOK ].freeze
Class Method Summary collapse
- .ensure_procfile(procfile) ⇒ Object
-
.installed?(process) ⇒ Boolean
Check if a process is available and usable in the current execution context This accounts for bundler context where system commands might be intercepted.
- .run_with_process_manager(procfile) ⇒ Object
Class Method Details
.ensure_procfile(procfile) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/react_on_rails/dev/process_manager.rb', line 48 def ensure_procfile(procfile) return if File.exist?(procfile) warn <<~MSG ERROR: Please ensure `#{procfile}` exists in your project! MSG exit 1 end |
.installed?(process) ⇒ Boolean
Check if a process is available and usable in the current execution context This accounts for bundler context where system commands might be intercepted
44 45 46 |
# File 'lib/react_on_rails/dev/process_manager.rb', line 44 def installed?(process) installed_in_current_context?(process) end |
.run_with_process_manager(procfile) ⇒ Object
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 |
# File 'lib/react_on_rails/dev/process_manager.rb', line 58 def run_with_process_manager(procfile) # Validate procfile path for security unless valid_procfile_path?(procfile) warn "ERROR: Invalid procfile path: #{procfile}" exit 1 end # Clean up stale files before starting FileManager.cleanup_stale_files # Try process managers in order of preference # run_process_if_available returns: # - true/false (exit status) if process was found and executed # - nil if process was not found overmind_result = run_process_if_available("overmind", ["start", "-f", procfile]) return if overmind_result == true # Overmind ran successfully foreman_result = run_process_if_available("foreman", ["start", "-f", procfile]) return if foreman_result == true # Foreman ran successfully # If either process was found but exited with error, don't show "not found" message # The process manager itself will have shown its own error message exit 1 if overmind_result == false || foreman_result == false # Neither process manager was found show_process_manager_installation_help exit 1 end |