forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes rails#52459 The current default `bin/dev` execs the Rails server directly and doesn't support Procfiles. Therefore, gems like `jsbundling-rails`, `tailwindcss-rails`, and soon `solid_queue` need to overwrite the `bin/dev` script with their own version. With this new version, gems can skip overwriting the `bin/dev` script and add to the Procfile instead. It spawns Foreman in the background to allow breakpoints in the Rails process without Foreman eating the inputs or interleaving its output.
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 36 additions & 1 deletion
37
railties/lib/rails/generators/rails/app/templates/bin/dev.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,36 @@ | ||
exec "./bin/rails", "server", *ARGV | ||
ENV["PORT"] ||= "3000" | ||
VERBOSE = ARGV.include?("--verbose") || ARGV.include?("-v") || ENV["VERBOSE"] | ||
RAILS_ARGS = ARGV - [ "--verbose", "-v" ] | ||
PROCFILE = "Procfile.dev" | ||
Process.exec(*%w[bundle exec rails server], *RAILS_ARGS) unless File.exist?(PROCFILE) | ||
|
||
Signal.trap("INT") { } | ||
|
||
if system(*%w[gem list --no-installed --exact --silent foreman]) | ||
puts "Installing foreman..." | ||
system(*%w[gem install foreman]) | ||
end | ||
|
||
begin | ||
in_r, in_w = IO.pipe | ||
in_w.close | ||
foreman_pid = Process.spawn( | ||
*%w[foreman start -f Procfile.dev -m all=1,web=0 --env /dev/null], | ||
in: in_r, | ||
out: (VERBOSE ? STDOUT : "/dev/null"), | ||
err: (VERBOSE ? STDOUT : "/dev/null"), | ||
pgroup: true, | ||
) | ||
foreman_pgid = Process.getpgid(foreman_pid) | ||
pid = Process.spawn(*%w[bundle exec rails server], *RAILS_ARGS) | ||
|
||
Process.wait(pid) | ||
pid = nil | ||
ensure | ||
Process.kill("INT", -foreman_pgid) | ||
Process.wait(-foreman_pgid) | ||
begin | ||
Process.kill("KILL", pid) if pid | ||
rescue Errno::ESRCH | ||
end | ||
end |