Sha256: c19cace733c470ce1bf419081dd54954dcb29730b036bb73c0c47eda149ceb59

Contents?: true

Size: 1.32 KB

Versions: 18

Compression:

Stored size: 1.32 KB

Contents

require 'fileutils'

module Jets::Rack
  class Server
    def self.start
      new.start
    end

    def start
      puts "Jets::Rack#start"
      return unless File.exist?("#{rack_project}/config.ru")
      puts "Starting additional rack server for the project under the rack subfolder..." if ENV['JETS_DEBUG']

      if ENV['FOREGROUND']
        serve
        return
      end

      # Reaching here means we'll run the server in the background.
      # Handle daemonzing ourselves because it keeps the stdout of the 2nd
      # rack server. The rackup --daemonize option ends up hiding the output.
      pid = Process.fork
      if pid.nil?
        # we're in the child process
        serve
      else
        # we're in the parent process
        Process.detach(pid) # dettached but still in the "foreground" since bin/rackup runs in the foreground
      end
    end

    # Runs in the child process
    def serve
      # Note, looks like stopping jets server with Ctrl-C sends the TERM signal
      # down to the sub bin/rackup command cleans up the child process fine.
      Bundler.with_clean_env do
        command = "cd #{rack_project} && bin/rackup" # leads to the same wrapper rack scripts
        puts "=> #{command}".colorize(:green)
        system(command)
      end
    end

    def rack_project
      "#{Jets.root}rack"
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
jets-1.0.18 lib/jets/rack/server.rb
jets-1.0.17 lib/jets/rack/server.rb
jets-1.0.16 lib/jets/rack/server.rb
jets-1.0.15 lib/jets/rack/server.rb
jets-1.0.13 lib/jets/rack/server.rb
jets-1.0.12 lib/jets/rack/server.rb
jets-1.0.11 lib/jets/rack/server.rb
jets-1.0.10 lib/jets/rack/server.rb
jets-1.0.9 lib/jets/rack/server.rb
jets-1.0.8 lib/jets/rack/server.rb
jets-1.0.7 lib/jets/rack/server.rb
jets-1.0.6 lib/jets/rack/server.rb
jets-1.0.5 lib/jets/rack/server.rb
jets-1.0.4 lib/jets/rack/server.rb
jets-1.0.3 lib/jets/rack/server.rb
jets-1.0.2 lib/jets/rack/server.rb
jets-1.0.1 lib/jets/rack/server.rb
jets-1.0.0 lib/jets/rack/server.rb