/
unicorn_recipe.rb
43 lines (39 loc) · 1.33 KB
/
unicorn_recipe.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Godhead
#
# Unicorn monitoring recipe
#
# inspired by http://railscasts.com/episodes/130-monitoring-with-god
class UnicornRecipe < GodRecipe
DEFAULT_OPTIONS = {
:max_cpu_usage => 10.percent,
:max_mem_usage => 50.megabytes,
:uid => nil, # probably want to set this
#
:root_dir => nil, # required to set this
:runner_path => 'unicorn',
:runner_conf => 'unicorn-conf.rb',
:runner_env => 'production',
}
def self.default_options() super.deep_merge(DEFAULT_OPTIONS) ; end
def start_command
[
"cd #{options[:root_dir]} && #{options[:runner_path]}",
"-c #{options[:runner_conf]}", # config file
"-E #{options[:runner_env]}", # environment
"-D", # daemonize
].flatten.compact.join(" ")
end
def pid_file
options[:pid_file] || options[:root_dir]+'/tmp/unicorn.pid'
end
# send QUIT signal: gracefully shuts down workers
def stop_command
"kill -QUIT `cat #{pid_file}`"
end
# # USR2 causes the master to re-create itself and spawn a new worker pool
def restart_command
old_pid_file = pid_file
"old_pid=`cat #{old_pid_file}`; kill -USR2 $old_pid ; sleep 4 ; kill -QUIT $old_pid"
end
end
end