Class: Jets::Rack::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/rack/server.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.startObject



5
6
7
# File 'lib/jets/rack/server.rb', line 5

def self.start
  new.start
end

Instance Method Details

#rack_projectObject



43
44
45
# File 'lib/jets/rack/server.rb', line 43

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

#serveObject

Runs in the child process



33
34
35
36
37
38
39
40
41
# File 'lib/jets/rack/server.rb', line 33

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

#startObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jets/rack/server.rb', line 9

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