-
Notifications
You must be signed in to change notification settings - Fork 18
/
unicorn.rb
39 lines (35 loc) · 1.18 KB
/
unicorn.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
set_default(:unicorn_user) { user }
set_default(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
set_default(:unicorn_config) { "#{shared_path}/config/unicorn.rb" }
set_default(:unicorn_log) { "#{shared_path}/log/unicorn.log" }
set_default(:unicorn_workers, 2)
namespace :unicorn do
desc "Setup Unicorn initializer and app configuration"
task :setup, roles: :app do
run "mkdir -p #{shared_path}/config"
template "unicorn.rb.erb", unicorn_config
template "unicorn_init.erb", "/tmp/unicorn_init"
run "chmod +x /tmp/unicorn_init"
run "#{sudo} mv /tmp/unicorn_init /etc/init.d/unicorn_#{application}"
run "#{sudo} update-rc.d -f unicorn_#{application} defaults"
end
after "deploy:setup", "unicorn:setup"
%w[start stop].each do |command|
desc "#{command} unicorn"
task command, roles: :app do
run "service unicorn_#{application} #{command}"
end
after "deploy:#{command}", "unicorn:#{command}"
end
desc "Restart unicorn"
task :restart, roles: :app do
stop
sleep 4
start
end
after "deploy:restart", "unicorn:restart"
desc "Get ouput of unicorn log file"
task :tail do
stream "tail -n 300 -f #{unicorn_log}"
end
end