capistrano-simple-unicorn 1.1.4 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6df79405fad12617cc4b14c958b227fe1457ed8a
4
- data.tar.gz: 34edfca6a9588b0609804d88beb351d1b1b60856
3
+ metadata.gz: '08716c38cf242db16b46c00b7575ce8b39fe1906'
4
+ data.tar.gz: e47a573ac35e442613bb5549c20e7deb790b10d0
5
5
  SHA512:
6
- metadata.gz: e844108038b73cb72a58b48a18e4e826c2a9ea065304a539a91af829e44def83ed43635e95ae97bcf79aea8554a3b47a911300df531762b0462496440c89fd80
7
- data.tar.gz: ce0b05c0f951b9da82c07076cb7b1d237a7052062b7d037b20f13b0bf49b4e36f02323a63f36d7b1eba45ac2a6f45857cda70f9c194b3b12ad891450145aa997
6
+ metadata.gz: fbeca25cf799f0a32261d203fdec7d5251711de7ffc6210afc35f71d7400da15e5f97f12643b9a6023ab9e543b8eaec43df9609eaba1f6f7b9ce87c4b297330d
7
+ data.tar.gz: 7abaae55f9462f0b3f059ba4999c6a2b7fea93b365b382f281c27fe0618b7bebb07429513d917c2fc7268e3f77ae788ed1959eebef236a87a0fb4f2b88c27cff
data/README.md CHANGED
@@ -40,9 +40,9 @@ Default value:
40
40
  ```
41
41
  set :unicorn_service, -> { "unicorn_#{fetch(:application)}" }
42
42
  set :user_home_path, -> { "/home/#{fetch(:user)}" }
43
- set :unicorn_config_path, -> { shared_path.join("config", "unicorn.rb") }
44
- set :unicorn_pid_path, -> { shared_path.join("tmp", "pids", "unicorn.pid") }
45
- set :unicorn_sock_path, -> { shared_path.join("tmp", "unicorn.sock") }
43
+ set :unicorn_config_file, -> { shared_path.join("config", "unicorn.rb") }
44
+ set :unicorn_pid_file, -> { shared_path.join("tmp", "pids", "unicorn.pid") }
45
+ set :unicorn_sock_file, -> { shared_path.join("tmp", "unicorn.sock") }
46
46
  set :unicorn_log_file, -> { shaed_path.join("log", "unicorn.stdout.log") }
47
47
  set :unicorn_error_log_file, -> {shared_path.join("log","unicorn.stderr.log")}
48
48
  set :ruby_version, -> { fetch(:rvm_ruby_version) || fetch(:rbenv_ruby) }
@@ -96,5 +96,5 @@ set :nginx_upstream_file, "/tmp/unicorn.sock"
96
96
  set :nginx_fail_timeout, 0
97
97
  set :nginx_access_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.access.log" } # access log file
98
98
  set :nginx_error_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.error.log" } # error log file
99
- set :nginx_upstream_file, -> { "#{fetch(:unicorn_sock_path)}" } # .sock file path
99
+ set :nginx_upstream_file, -> { "#{fetch(:unicorn_sock_file)}" } # .sock file path
100
100
  ```
@@ -44,15 +44,15 @@ module Capistrano
44
44
  "/etc/init.d/#{fetch(:unicorn_service)}"
45
45
  end
46
46
 
47
- def unicorn_sock_path
47
+ def unicorn_sock_file
48
48
  shared_path.join("tmp", "unicorn.sock")
49
49
  end
50
50
 
51
- def unicorn_config_path
51
+ def unicorn_config_file
52
52
  shared_path.join("config", "unicorn.rb")
53
53
  end
54
54
 
55
- def unicorn_pid_path
55
+ def unicorn_pid_file
56
56
  shared_path.join("tmp", "pids", "unicorn.pid")
57
57
  end
58
58
 
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module SimpleUnicorn
3
- VERSION = '1.1.4'.freeze
3
+ VERSION = '1.1.5'.freeze
4
4
  end
5
5
  end
@@ -10,7 +10,7 @@ namespace :load do
10
10
  set :nginx_fail_timeout, 0
11
11
  set :nginx_access_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.access.log" }
12
12
  set :nginx_error_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.error.log" }
13
- set :nginx_upstream_file, -> { "#{fetch(:unicorn_sock_path)}" }
13
+ set :nginx_upstream_file, -> { "#{fetch(:unicorn_sock_file)}" }
14
14
  end
15
15
  end
16
16
 
@@ -5,15 +5,11 @@ namespace :load do
5
5
  task :defaults do
6
6
  set :unicorn_service, -> { "unicorn_#{fetch(:application)}" }
7
7
  set :user_home_path, -> { "/home/#{fetch(:user)}" }
8
- set :unicorn_config_path, -> { unicorn_config_path }
9
- set :unicorn_pid_path, -> { unicorn_pid_path }
10
- set :unicorn_sock_path, -> { unicorn_sock_path }
11
- set :unicorn_stdout_path, -> { unicorn_log_file }
12
- set :unicorn_stderr_path, -> { unicorn_error_log_file }
13
- set :unicorn_roles, -> { :app }
14
- set :unicorn_restart_sleep_time, 3
15
- set :unicorn_options, -> { '' }
16
- set :unicorn_env, -> { fetch(:rails_env) || 'deployment' }
8
+ set :unicorn_config_file, -> { unicorn_config_file }
9
+ set :unicorn_pid_file, -> { unicorn_pid_file }
10
+ set :unicorn_sock_file, -> { unicorn_sock_file }
11
+ set :unicorn_log_file, -> { unicorn_log_file }
12
+ set :unicorn_error_log_file, -> { unicorn_error_log_file }
17
13
  set :ruby_version, -> { fetch(:rvm_ruby_version) || fetch(:rbenv_ruby) }
18
14
  set :unicorn_worker_processes, 2
19
15
  set :unicorn_timeout, 30
@@ -23,115 +19,52 @@ namespace :load do
23
19
  end
24
20
 
25
21
  namespace :unicorn do
26
- desc "Unicorn generate config file"
27
- task :setup do
28
- on roles(fetch(:unicorn_roles)) do
29
- unless file_exists? fetch(:unicorn_config_path)
30
- execute :mkdir, '-pv', File.dirname(fetch(:unicorn_config_path))
31
- upload! template('unicorn.rb.erb'), fetch(:unicorn_config_path)
22
+ desc 'Unicorn Initializer'
23
+ task :unicorn_init do
24
+ on roles :app do
25
+ sudo_upload! template('unicorn_init.erb'), unicorn_initd_file
26
+ execute :chmod, '+x', unicorn_initd_file
27
+ if os_is_ubuntu?
28
+ sudo 'update-rc.d', '-f', fetch(:unicorn_service), 'defaults'
29
+ else
30
+ sudo 'chkconfig', '--add', fetch(:unicorn_service)
32
31
  end
33
32
  end
34
33
  end
35
34
 
36
- desc "Start Unicorn"
37
- task :start do
38
- on roles(fetch(:unicorn_roles)) do
39
- within current_path do
40
- if test("[ -e #{fetch(:unicorn_pid_path)} ] && kill -0 #{pid}")
41
- info "unicorn is running..."
42
- else
43
- with rails_env: fetch(:rails_env) do
44
- execute :bundle, "exec unicorn", "-c", fetch(:unicorn_config_path), "-E", fetch(:unicorn_env), "-D", fetch(:unicorn_options)
45
- end
46
- end
35
+ desc 'Setup unicorn config'
36
+ task :setup_unicorn_config do
37
+ on roles :app do
38
+ unless file_exists? fetch(:unicorn_config_file)
39
+ execute :mkdir, '-pv', File.dirname(fetch(:unicorn_config_file))
47
40
  end
41
+ upload! template('unicorn.rb.erb'), fetch(:unicorn_config_file)
48
42
  end
49
43
  end
50
44
 
51
- desc "Stop Unicorn (QUIT)"
52
- task :stop do
53
- on roles(fetch(:unicorn_roles)) do
54
- within current_path do
55
- if test("[ -e #{fetch(:unicorn_pid_path)} ]")
56
- if test("kill -0 #{pid}")
57
- info "stopping unicorn..."
58
- execute :kill, "-s QUIT", pid
59
- else
60
- info "cleaning up dead unicorn pid..."
61
- execute :rm, fetch(:unicorn_pid_path)
62
- end
63
- else
64
- info "unicorn is not running..."
65
- end
45
+ %w[start stop restart upgrade].each do |action|
46
+ desc "#{action} unicorn"
47
+ task action do
48
+ on roles :app do
49
+ sudo :service, fetch(:unicorn_service), action
66
50
  end
67
51
  end
68
52
  end
69
53
 
70
- desc "Reload Unicorn (HUP); use this when preload_app: false"
71
- task :reload do
72
- invoke "unicorn:start"
73
- on roles(fetch(:unicorn_roles)) do
74
- within current_path do
75
- info "reloading..."
76
- execute :kill, "-s HUP", pid
54
+ desc 'restart unicorn'
55
+ task 'reload' do
56
+ on roles :app do
57
+ invoke "unicorn:unicorn_init" unless file_exists?(unicorn_initd_file)
58
+ invoke 'unicorn:setup_unicorn_config'
59
+ if test "[ -f #{fetch(:unicorn_pid)} ]"
60
+ sudo 'service', fetch(:unicorn_service), 'restart'
61
+ else
62
+ sudo 'service', fetch(:unicorn_service), 'start'
77
63
  end
78
64
  end
79
65
  end
80
-
81
- desc "Restart Unicorn (USR2); use this when preload_app: true"
82
- task :restart do
83
- invoke "unicorn:start"
84
- on roles(fetch(:unicorn_roles)) do
85
- within current_path do
86
- info "unicorn restarting..."
87
- execute :kill, "-s USR2", pid
88
- end
89
- end
90
- end
91
-
92
- desc "Duplicate Unicorn; alias of unicorn:restart"
93
- task :duplicate do
94
- invoke "unicorn:restart"
95
- end
96
-
97
- desc "Legacy Restart (USR2 + QUIT); use this when preload_app: true and oldbin pid needs cleanup"
98
- task :legacy_restart do
99
- invoke "unicorn:restart"
100
- on roles(fetch(:unicorn_roles)) do
101
- within current_path do
102
- execute :sleep, fetch(:unicorn_restart_sleep_time)
103
- if test("[ -e #{fetch(:unicorn_pid_path)}.oldbin ]")
104
- execute :kill, "-s QUIT", pid_oldbin
105
- end
106
- end
107
- end
108
- end
109
-
110
- desc "Add a worker (TTIN)"
111
- task :add_worker do
112
- on roles(fetch(:unicorn_roles)) do
113
- within current_path do
114
- info "adding worker"
115
- execute :kill, "-s TTIN", pid
116
- end
117
- end
118
- end
119
-
120
- desc "Remove a worker (TTOU)"
121
- task :remove_worker do
122
- on roles(fetch(:unicorn_roles)) do
123
- within current_path do
124
- info "removing worker"
125
- execute :kill, "-s TTOU", pid
126
- end
127
- end
128
- end
129
- end
130
-
131
- def pid
132
- "`cat #{fetch(:unicorn_pid_path)}`"
133
66
  end
134
67
 
135
- def pid_oldbin
136
- "`cat #{fetch(:unicorn_pid_path)}.oldbin`"
68
+ namespace :deploy do
69
+ after :publishing, 'unicorn:reload'
137
70
  end
@@ -1,36 +1,26 @@
1
1
  worker_processes <%= fetch(:unicorn_worker_processes) %>
2
2
  timeout <%= fetch(:unicorn_timeout) %>
3
- app_path = "<%= fetch(:deploy_to) %>"
4
- listen "<%= fetch(:unicorn_sock_path) %>"
5
- pid "<%= fetch(:unicorn_pid_path) %>"
6
3
 
7
- stderr_path "<%= fetch(:unicorn_stderr_path) %>"
8
- stdout_path "<%= fetch(:unicorn_stdout_path %>"
4
+ listen "<%= fetch(:unicorn_sock_file) %>"
5
+ pid "<%= fetch(:unicorn_pid_file) %>"
9
6
 
10
- preload_app true
11
-
12
- # use correct Gemfile on restarts
13
- before_exec do |server|
14
- ENV['BUNDLE_GEMFILE'] = "#{app_path}/current/Gemfile"
15
- end
7
+ stderr_path "<%= fetch(:unicorn_error_log_file) %>"
8
+ stdout_path "<%= fetch(:unicorn_log_file) %>"
16
9
 
17
10
  preload_app true
18
11
 
19
12
  before_fork do |server, worker|
20
- # the following is highly recomended for Rails + "preload_app true"
21
- # as there's no need for the master process to hold a connection
22
- if defined?(ActiveRecord::Base)
23
- ActiveRecord::Base.connection.disconnect!
24
- end
13
+ defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
25
14
 
26
- # Before forking, kill the master process that belongs to the .oldbin PID.
27
- # This enables 0 downtime deploys.
28
- old_pid = "#{server.config[:pid]}.oldbin"
29
- if File.exists?(old_pid) && server.pid != old_pid
15
+ old_pid = "#{ server.config[:pid] }.oldbin"
16
+ unless old_pid == server.pid
30
17
  begin
31
- Process.kill("QUIT", File.read(old_pid).to_i)
18
+ Process.kill :QUIT, File.read(old_pid).to_i
32
19
  rescue Errno::ENOENT, Errno::ESRCH
33
- # someone else did our job for us
34
20
  end
35
21
  end
36
22
  end
23
+
24
+ after_fork do |server, worker|
25
+ defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
26
+ end
@@ -11,11 +11,11 @@
11
11
  set -e
12
12
  HOME=<%= fetch(:user_home_path) %>
13
13
  APP_ROOT=<%= current_path %>
14
- PID=<%= fetch(:unicorn_pid_path) %>
14
+ PID=<%= fetch(:unicorn_pid_file) %>
15
15
  USER=<%= fetch(:user) %>
16
16
  ENV="<%= fetch(:stage) %>"
17
17
  RUBY_VERSION="<%= fetch(:ruby_version) %>"
18
- CONFIG_FILE="<%= fetch(:unicorn_config_path) %>"
18
+ CONFIG_FILE="<%= fetch(:unicorn_config_file) %>"
19
19
  CMD="cd $APP_ROOT && export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION=$RUBY_VERSION; $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c $CONFIG_FILE -E $ENV -D"
20
20
 
21
21
  set -u
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-simple-unicorn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - truongkma