deploy.rb
2.27 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require "awesome_print"
# config valid only for current version of Capistrano
lock '3.4.0'
set :application, 'nuozheng'
set :repo_url, 'git@git.ebookchain.net:sdtailor/nuozheng.git'
set :branch, "master"
set :deploy_to, '/home/web/nuozheng'
set :scm, :git
set :pty, false
set :keep_releases, 3
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn_nuozheng.pid"
namespace :deploy do
task :start do
on roles(:web) do
within current_path do
with rails_env: 'production' do
execute :bundle, "exec unicorn_rails -c #{fetch(:unicorn_config)} -D"
end
end
end
end
task :stop do
on roles(:web) do
execute "if [ -f #{fetch(:unicorn_pid)} ]; then kill -QUIT `cat #{fetch(:unicorn_pid)}`; fi"
end
end
task :restart do
on roles(:web) do
# within current_path do
# 用USR2信号来实现无缝部署重启
execute "if [ -f #{fetch(:unicorn_pid)} ]; then kill -s USR2 `cat #{fetch(:unicorn_pid)}`; fi"
# end
end
end
task :mkdir_shared do
on roles(:web) do
execute "mkdir -p #{shared_path}/uploads"
execute "mkdir -p #{shared_path}/log"
execute "mkdir -p #{shared_path}/assets"
execute "mkdir -p #{shared_path}/tmp/pids"
execute "mkdir -p #{shared_path}/tmp/cache"
end
end
task :link_shared do
on roles(:web) do
execute "ln -sf #{shared_path}/log #{current_path}/log"
execute "ln -sf #{shared_path}/assets #{current_path}/public/assets"
execute "ln -sf #{shared_path}/tmp #{current_path}/tmp"
execute "ln -sf #{shared_path}/uploads #{current_path}/public/uploads"
end
end
task :db_migrate do
on roles(:web) do
within current_path do
with rails_env: 'production' do
execute :bundle, :exec, :rake, 'db:migrate'
end
end
end
end
task :bundle_install do
on roles(:web) do
within current_path do
with rails_env: 'production' do
execute :bundle, 'install'
end
end
end
end
before :starting, :mkdir_shared
after :publishing, :link_shared
after :publishing, :bundle_install
after :publishing, :db_migrate
after :publishing, :restart # 第一次部署会有找不到unicron.pid的bug
end