Method: Spring::Client::Run#run_command

Defined in:
lib/spring/client/run.rb

#run_command(client, application) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/spring/client/run.rb', line 121

def run_command(client, application)
  log "sending command"

  application.send_io STDOUT
  application.send_io STDERR
  application.send_io STDIN

  send_json application, "args" => args, "env" => ENV.to_hash

  pid = server.gets
  pid = pid.chomp if pid

  # We must not close the client socket until we are sure that the application has
  # received the FD. Otherwise the FD can end up getting closed while it's in the server
  # socket buffer on OS X. This doesn't happen on Linux.
  client.close

  if pid && !pid.empty?
    log "got pid: #{pid}"

    forward_signals(pid.to_i)
    status = application.read.to_i

    log "got exit status #{status}"

    exit status
  else
    log "got no pid"
    exit 1
  end
ensure
  application.close
end