Class: Uc::Unicorn::Api
- Inherits:
-
Object
- Object
- Uc::Unicorn::Api
- Defined in:
- lib/uc/unicorn/api.rb
Instance Attribute Summary collapse
-
#original_env ⇒ Object
readonly
Returns the value of attribute original_env.
-
#queue_name ⇒ Object
Returns the value of attribute queue_name.
-
#run_id ⇒ Object
readonly
Returns the value of attribute run_id.
Instance Method Summary collapse
- #acquire_shared_lock(lock_file) ⇒ Object
- #clean_env ⇒ Object
- #cleaned_path ⇒ Object
- #end_run(worker) ⇒ Object
- #gradual_shutdown(server, worker) ⇒ Object
- #init(server) ⇒ Object
- #init_original_env ⇒ Object
-
#initialize(event_queue) ⇒ Api
constructor
A new instance of Api.
- #load_env ⇒ Object
- #load_original_env ⇒ Object
- #on_exec_fail ⇒ Object
- #oom_adjust ⇒ Object
- #prestart(server, worker, **kwargs) ⇒ Object
- #send_worker_ready(server, worker, **kwargs) ⇒ Object
- #shared_env ⇒ Object
- #uc_config ⇒ Object
- #wait_for_worker_ready(server, worker, **kwargs) ⇒ Object
Constructor Details
#initialize(event_queue) ⇒ Api
Returns a new instance of Api.
17 18 19 20 21 |
# File 'lib/uc/unicorn/api.rb', line 17 def initialize(event_queue) @queue_name = event_queue @run_id = SecureRandom.hex(3) ::Uc::Logger.event_queue = queue_name end |
Instance Attribute Details
#original_env ⇒ Object (readonly)
Returns the value of attribute original_env.
14 15 16 |
# File 'lib/uc/unicorn/api.rb', line 14 def original_env @original_env end |
#queue_name ⇒ Object
Returns the value of attribute queue_name.
15 16 17 |
# File 'lib/uc/unicorn/api.rb', line 15 def queue_name @queue_name end |
#run_id ⇒ Object (readonly)
Returns the value of attribute run_id.
14 15 16 |
# File 'lib/uc/unicorn/api.rb', line 14 def run_id @run_id end |
Instance Method Details
#acquire_shared_lock(lock_file) ⇒ Object
50 51 52 53 |
# File 'lib/uc/unicorn/api.rb', line 50 def acquire_shared_lock(lock_file) shared_lock = ::Uc::Unicorn::Lock.new(lock_file) shared_lock.acquire end |
#clean_env ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/uc/unicorn/api.rb', line 77 def clean_env return if uc_config.config[:skip_clean_env] ENV.delete "BUNDLE_BIN_PATH" ENV.delete "RUBYLIB" ENV.delete "RUBYOPT" ENV.delete "GEM_HOME" ENV.delete "GEM_PATH" ENV.delete "BUNDLE_GEMFILE" ENV["PATH"] = cleaned_path end |
#cleaned_path ⇒ Object
92 93 94 95 96 |
# File 'lib/uc/unicorn/api.rb', line 92 def cleaned_path paths = (ENV["PATH"] || "").split(File::PATH_SEPARATOR) paths.reject! { |x| x =~ /vendor\/bundle\/ruby/ } paths.uniq.join(File::PATH_SEPARATOR) end |
#end_run(worker) ⇒ Object
67 68 69 |
# File 'lib/uc/unicorn/api.rb', line 67 def end_run(worker) @init.end_run(worker) end |
#gradual_shutdown(server, worker) ⇒ Object
28 29 30 31 |
# File 'lib/uc/unicorn/api.rb', line 28 def gradual_shutdown(server, worker) gradual_shutdown = ::Uc::Unicorn::GradualShutdown.new(server, worker) gradual_shutdown.run end |
#init(server) ⇒ Object
23 24 25 26 |
# File 'lib/uc/unicorn/api.rb', line 23 def init(server) @init ||= ::Uc::Unicorn::Init.new(server) @init.run_once end |
#init_original_env ⇒ Object
105 106 107 108 |
# File 'lib/uc/unicorn/api.rb', line 105 def init_original_env return if @original_env @original_env = ENV.to_h end |
#load_env ⇒ Object
88 89 90 |
# File 'lib/uc/unicorn/api.rb', line 88 def load_env uc_config.load_env end |
#load_original_env ⇒ Object
98 99 100 101 102 103 |
# File 'lib/uc/unicorn/api.rb', line 98 def load_original_env return if not @original_env.is_a? Hash # add unicorn specific environment vars like UNICORN_FD ENV.select { |k,v| k =~ /\AUNICORN_/ }.each { |k,v| @original_env[k] = v } ENV.replace(@original_env) end |
#on_exec_fail ⇒ Object
71 72 73 74 75 |
# File 'lib/uc/unicorn/api.rb', line 71 def on_exec_fail event_stream = ::Uc::Logger.event_stream event_stream.close_connections event_stream.fatal "re-exec failed" end |
#oom_adjust ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/uc/unicorn/api.rb', line 55 def oom_adjust pid = Process.pid oom_file = "/proc/#{pid}/oom_score_adj" File.open(oom_file,"w") do |f| f.write "800" end end |
#prestart(server, worker, **kwargs) ⇒ Object
33 34 35 36 |
# File 'lib/uc/unicorn/api.rb', line 33 def prestart(server, worker, **kwargs) prestart = ::Uc::Unicorn::Prestart.new(server, worker, **kwargs) prestart.run end |
#send_worker_ready(server, worker, **kwargs) ⇒ Object
38 39 40 41 42 |
# File 'lib/uc/unicorn/api.rb', line 38 def send_worker_ready(server, worker, **kwargs) ready_event = ::Uc::Unicorn::ReadyEvent.new(server, worker, **kwargs) ready_event.run_id = run_id ready_event.run end |
#shared_env ⇒ Object
63 64 65 |
# File 'lib/uc/unicorn/api.rb', line 63 def shared_env @shared_env ||= {} end |