123456789_123456789_123456789_123456789_123456789_

Module: Puma::JRubyRestart

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, FFI::Library
Defined in: lib/puma/jruby_restart.rb

Constant Summary

Class Attribute Summary

Class Method Summary

Class Attribute Details

.daemon?Boolean (readonly)

[ GitHub ]

  
# File 'lib/puma/jruby_restart.rb', line 36

def self.daemon?
  ENV.key?(PermKey) || ENV.key?(RestartKey)
end

Class Method Details

.chdir_exec(dir, argv)

Raises:

  • (SystemCallError)
[ GitHub ]

  
# File 'lib/puma/jruby_restart.rb', line 16

def self.chdir_exec(dir, argv)
  chdir(dir)
  cmd = argv.first
  argv = ([:string] * argv.size).zip(argv).flatten
  argv << :string
  argv << nil
  execlp(cmd, *argv)
  raise SystemCallError.new(FFI.errno)
end

.daemon_init

[ GitHub ]

  
# File 'lib/puma/jruby_restart.rb', line 40

def self.daemon_init
  return true if ENV.key?(PermKey)

  return false unless ENV.key? RestartKey

  master = ENV[RestartKey]

  # In case the master disappears early
  begin
    Process.kill "SIGUSR2", master.to_i
  rescue SystemCallError => e
  end

  ENV[RestartKey] = ""

  setsid

  null = File.open "/dev/null", "w+"
  STDIN.reopen null
  STDOUT.reopen null
  STDERR.reopen null

  true
end

.daemon_start(dir, argv)

Raises:

  • (SystemCallError)
[ GitHub ]

  
# File 'lib/puma/jruby_restart.rb', line 65

def self.daemon_start(dir, argv)
  ENV[RestartKey] = Process.pid.to_s

  if k = ENV['PUMA_JRUBY_DAEMON_OPTS']
    ENV['JRUBY_OPTS'] = k
  end

  cmd = argv.first
  argv = ([:string] * argv.size).zip(argv).flatten
  argv << :string
  argv << nil

  chdir(dir)
  ret = fork
  return ret if ret != 0
  execlp(cmd, *argv)
  raise SystemCallError.new(FFI.errno)
end

.perm_daemonize

Called to tell things “Your now always in daemon mode, don’t try to reenter it.”

[ GitHub ]

  
# File 'lib/puma/jruby_restart.rb', line 32

def self.perm_daemonize
  ENV[PermKey] = "1"
end