Class: Uc::Server
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logger
#event_queue, event_stream, #event_stream, logger, #logger, stderr, #stderr
#cmd, #kill, #process_running?
Constructor Details
#initialize(app_dir, rails_env: "production", debug: false) ⇒ Server
Returns a new instance of Server.
19
20
21
22
23
|
# File 'lib/uc/server.rb', line 19
def initialize(app_dir, rails_env: "production", debug: false)
@app_dir = app_dir
@rails_env = rails_env
@debug = debug
end
|
Instance Attribute Details
#app_dir ⇒ Object
Returns the value of attribute app_dir.
16
17
18
|
# File 'lib/uc/server.rb', line 16
def app_dir
@app_dir
end
|
#rails_env ⇒ Object
Returns the value of attribute rails_env.
16
17
18
|
# File 'lib/uc/server.rb', line 16
def rails_env
@rails_env
end
|
#use_pid ⇒ Object
Returns the value of attribute use_pid.
17
18
19
|
# File 'lib/uc/server.rb', line 17
def use_pid
@use_pid
end
|
Instance Method Details
#print_config ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/uc/server.rb', line 70
def print_config
init_once
config.to_h.each do |k,v|
v = %{ "#{v}" } if not v.is_a? Numeric
puts "#{k} #{v}"
end
end
|
#reopen_logs ⇒ Object
78
79
80
81
82
83
|
# File 'lib/uc/server.rb', line 78
def reopen_logs
init_once
return if not server_status.running?
Process.kill(:USR1 , server_status.pid)
puts "reopened logs"
end
|
#restart ⇒ Object
53
54
55
56
|
# File 'lib/uc/server.rb', line 53
def restart
stop
start
end
|
#rolling_restart ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/uc/server.rb', line 58
def rolling_restart
init_once
uconfig.generate_once
if not server_status.running?
start
return
end
event_stream.expect :fin do
Process.kill("USR2", server_status.pid)
end
end
|
#start ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/uc/server.rb', line 25
def start
init_once
if server_status.running?
puts server_status
return
end
ENV["UNICORN_APP_DIR"] = config.app_dir
event_stream.expect_in_background :fin do
cmd %{unicorn -c #{uconfig.path} -D -E #{rails_env} }, return_output: false,
error_msg: "error starting unicorn"
end
end
|
#status ⇒ Object
47
48
49
50
51
|
# File 'lib/uc/server.rb', line 47
def status
paths.validate_required
Dir.chdir app_dir
puts server_status
end
|
#stop ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/uc/server.rb', line 38
def stop
init_once
if server_status.stopped?
logger.info "unicorn not running"
return
end
kill(server_status.pid, 30)
end
|