Method: Puma::CLI#generate_restart_data

Defined in:
lib/puma/cli.rb

#generate_restart_dataObject



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/puma/cli.rb', line 329

def generate_restart_data
  # Use the same trick as unicorn, namely favor PWD because
  # it will contain an unresolved symlink, useful for when
  # the pwd is /data/releases/current.
  if dir = ENV['PWD']
    s_env = File.stat(dir)
    s_pwd = File.stat(Dir.pwd)

    if s_env.ino == s_pwd.ino and s_env.dev == s_pwd.dev
      @restart_dir = dir
      @options[:worker_directory] = dir
    end
  end

  @restart_dir ||= Dir.pwd

  @original_argv = ARGV.dup

  if defined? Rubinius::OS_ARGV
    @restart_argv = Rubinius::OS_ARGV
  else
    require 'rubygems'

    # if $0 is a file in the current directory, then restart
    # it the same, otherwise add -S on there because it was
    # picked up in PATH.
    #
    if File.exist?($0)
      arg0 = [Gem.ruby, $0]
    else
      arg0 = [Gem.ruby, "-S", $0]
    end

    # Detect and reinject -Ilib from the command line
    lib = File.expand_path "lib"
    arg0[1,0] = ["-I", lib] if $:[0] == lib

    if defined? Puma::WILD_ARGS
      @restart_argv = arg0 + Puma::WILD_ARGS + ARGV
    else
      @restart_argv = arg0 + ARGV
    end
  end
end