mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Use FFI on JRuby to perform fast restart
This commit is contained in:
parent
331764078c
commit
5fc904b099
2 changed files with 29 additions and 2 deletions
|
@ -81,8 +81,13 @@ module Puma
|
|||
end
|
||||
|
||||
def restart!
|
||||
Dir.chdir @restart_dir
|
||||
Kernel.exec(*@restart_argv)
|
||||
if IS_JRUBY
|
||||
require 'puma/jruby_restart'
|
||||
JRubyRestart.chdir_exec(@restart_dir, Gem.ruby, *@restart_argv)
|
||||
else
|
||||
Dir.chdir @restart_dir
|
||||
Kernel.exec(*@restart_argv)
|
||||
end
|
||||
end
|
||||
|
||||
# Write +str+ to +@stdout+
|
||||
|
|
22
lib/puma/jruby_restart.rb
Normal file
22
lib/puma/jruby_restart.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'ffi'
|
||||
|
||||
module Puma
|
||||
module JRubyRestart
|
||||
extend FFI::Library
|
||||
ffi_lib 'c'
|
||||
|
||||
attach_function :execlp, [:string, :varargs], :int
|
||||
attach_function :chdir, [:string], :int
|
||||
|
||||
def self.chdir_exec(dir, cmd, *argv)
|
||||
chdir(dir)
|
||||
argv.unshift(cmd)
|
||||
argv = ([:string] * argv.size).zip(argv).flatten
|
||||
argv <<:int
|
||||
argv << 0
|
||||
execlp(cmd, *argv)
|
||||
raise SystemCallError.new(FFI.errno)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Add table
Reference in a new issue