sepastian-capistrano3-unicorn 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56d1dc0e6289b917bcbae1648d1fedcaff467238
4
- data.tar.gz: 0f5282cc61626dcdfa6b7378ae07b2f1ee84d361
3
+ metadata.gz: 612300b16394dba9a55347ffec57f3866bdf8438
4
+ data.tar.gz: 1d843ca1beb43f3b49602f42d3b4c7242ee0b4af
5
5
  SHA512:
6
- metadata.gz: 3ca58dac9f898fc86b6e62ac1b821c7cd4fa0810396847bc62a4c0fbfa412979740997758148e4152044a703a9dd332f5938356b79bac4a21549383c03a3c4f5
7
- data.tar.gz: e40915fbde9a38cd9b9d513aebfd79220d762b210a3e26703b426719f4db091f08782522c46d0af83fe73905b56489b4f7ad782a991738b1e29c2a914d3d37c1
6
+ metadata.gz: a42ca5a33d585ba405ef28086ba9bf8e40ace62662b211b1033d75b80f154906c5441ce6609a5af5408ecde831dca2ac8b8a9365ab6c934ff149bf3a254c83ba
7
+ data.tar.gz: dff1cf6dbaa474f5e49078958c1bd404184e921c7489c79eb6cc60d9528805fd47542d01127f2d2a0a65e2d8cec3dc4a76552c8dfcc77fa9c8132a39abb46b86
data/README.md CHANGED
@@ -25,7 +25,7 @@ group :development do
25
25
  end
26
26
  ```
27
27
 
28
- And load it into your deployment script `config/deploy.rb`:
28
+ And require it in your `Capfile`:
29
29
 
30
30
  ```ruby
31
31
  require 'capistrano/unicorn'
@@ -1,4 +1,3 @@
1
- require 'capistrano'
2
1
  require 'capistrano/unicorn/utility'
3
2
 
4
3
  include CapistranoUnicorn::Utility
@@ -12,21 +11,21 @@ namespace :load do
12
11
  set :unicorn_env , Proc.new{ fetch(:rails_env, 'production') }
13
12
  # Following recommendations from http://unicorn.bogomips.org/unicorn_1.html
14
13
  set :unicorn_rack_env, Proc.new{ fetch(:rails_env) == 'development' ? 'development' : 'deployment' }
15
-
14
+
16
15
  # Execution
17
16
  set :unicorn_user , nil
18
17
  set :unicorn_bundle , Proc.new{ fetch(:bundle_cmd, "bundle") }
19
18
  set :unicorn_bin , "unicorn"
20
19
  set :unicorn_options , ''
21
20
  set :unicorn_restart_sleep_time, 2
22
-
21
+
23
22
  # Relative paths
24
23
  set :app_subdir , ''
25
24
  set :unicorn_config_rel_path , "config"
26
25
  set :unicorn_config_filename , "unicorn.rb"
27
26
  set :unicorn_config_rel_file_path , Proc.new{ File.join(fetch(:unicorn_config_rel_path), fetch(:unicorn_config_filename)) }
28
27
  set :unicorn_config_stage_rel_file_path, Proc.new{ File.join(fetch(:unicorn_config_rel_path), 'unicorn', "#{fetch(:unicorn_env)}.rb") }
29
-
28
+
30
29
  # Absolute paths
31
30
  # If you find the following confusing, try running 'cap unicorn:show_vars' -
32
31
  # it might help :-)
@@ -86,84 +85,70 @@ namespace :unicorn do
86
85
 
87
86
  desc 'Start Unicorn master process'
88
87
  task :start do
89
- on roles unicorn_roles, :except => {:no_release => true} do
90
-
88
+ on roles unicorn_roles, reject: lambda { |h| h.properties.no_release } do
91
89
  execute start_unicorn
92
90
  end
93
91
  end
94
-
92
+
95
93
  desc 'Stop Unicorn'
96
94
  task :stop do
97
- on roles unicorn_roles, :except => {:no_release => true} do
95
+ on roles unicorn_roles, reject: lambda { |h| h.properties.no_release } do
98
96
  execute kill_unicorn('QUIT')
99
97
  end
100
98
  end
101
-
99
+
102
100
  desc 'Immediately shutdown Unicorn'
103
101
  task :shutdown do
104
- on roles unicorn_roles, :except => {:no_release => true} do
102
+ on roles unicorn_roles, reject: lambda { |h| h.properties.no_release } do
105
103
  execute kill_unicorn('TERM')
106
104
  end
107
105
  end
108
-
106
+
109
107
  desc 'Restart Unicorn'
110
108
  task :restart do
111
- on roles unicorn_roles, :except => {:no_release => true} do
112
- execute duplicate_unicorn
109
+ on roles unicorn_roles, reject: lambda { |h| h.properties.no_release } do
110
+ duplicate_unicorn
113
111
  execute :sleep, fetch(:unicorn_restart_sleep_time)
114
- execute "if #{old_unicorn_is_running?}; then #{unicorn_send_signal('QUIT', get_old_unicorn_pid)}; fi;"
112
+
113
+ if old_unicorn_is_running?
114
+ unicorn_send_signal('QUIT', get_old_unicorn_pid)
115
+ end
115
116
  end
116
117
  end
117
118
 
118
119
  desc 'Duplicate Unicorn'
119
120
  task :duplicate do
120
- on roles unicorn_roles, :except => {:no_release => true} do
121
- execute duplicate_unicorn()
121
+ on roles unicorn_roles, reject: lambda { |h| h.properties.no_release } do
122
+ duplicate_unicorn
122
123
  end
123
124
  end
124
-
125
+
125
126
  desc 'Reload Unicorn'
126
127
  task :reload do
127
- on roles unicorn_roles, :except => {:no_release => true} do
128
- execute "if #{unicorn_is_running?}; then #{unicorn_send_signal('HUP')}; else #{start_unicorn} fi;"
129
- # run <<-END
130
- # if #{unicorn_is_running?}; then
131
- # echo "Reloading Unicorn...";
132
- # #{unicorn_send_signal('HUP')};
133
- # else
134
- # #{start_unicorn}
135
- # fi;
136
- # END
128
+ on roles unicorn_roles, reject: lambda { |h| h.properties.no_release } do
129
+ if unicorn_is_running?
130
+ unicorn_send_signal('HUP')
131
+ else
132
+ start_unicorn
133
+ end
137
134
  end
138
135
  end
139
136
 
140
137
  desc 'Add a new worker'
141
138
  task :add_worker do
142
- on roles unicorn_roles, :except => {:no_release => true} do
143
- execute "if #{unicorn_is_running?}; then #{unicorn_send_signal('TTIN')}; fi;"
144
- # run <<-END
145
- # if #{unicorn_is_running?}; then
146
- # echo "Adding a new Unicorn worker...";
147
- # #{unicorn_send_signal('TTIN')};
148
- # else
149
- # echo "Unicorn is not running.";
150
- # fi;
151
- # END
139
+ on roles unicorn_roles, reject: lambda { |h| h.properties.no_release } do
140
+ if unicorn_is_running?
141
+ unicorn_send_signal('TTIN')
142
+ end
152
143
  end
153
144
  end
154
145
 
155
146
  desc 'Remove amount of workers'
156
147
  task :remove_worker do
157
- on roles unicorn_roles, :except => {:no_release => true} do
158
- execute "if #{unicorn_is_running?}; then #{unicorn_send_signal('TTOU')}; fi;"
159
- # run <<-END
160
- # if #{unicorn_is_running?}; then
161
- # echo "Removing a Unicorn worker...";
162
- # #{unicorn_send_signal('TTOU')};
163
- # else
164
- # echo "Unicorn is not running.";
165
- # fi;
166
- # END
148
+ on roles unicorn_roles, reject: lambda { |h| h.properties.no_release } do
149
+ if unicorn_is_running?
150
+ unicorn_send_signal('TTOU')
151
+ end
167
152
  end
168
153
  end
169
154
  end
@@ -3,21 +3,6 @@ require 'tempfile'
3
3
  module CapistranoUnicorn
4
4
  module Utility
5
5
  # In Capistrano 3, shell scripts must be invoked with SSHKit's execute, instead of run.
6
- # SSHKit will "sanitize" all multi-line commands (here docs), replacing "\n" with ";".
7
- # Sanitizing renders some shell scripts illegal, for instance:
8
- #
9
- # if [ -e FILE ]; then
10
- # echo "Found."
11
- # fi
12
- #
13
- # This would become
14
- #
15
- # if [ -e FILE ]; then; echo "Found."; fi;
16
- #
17
- # which is illegal because of the ';' after 'then'.
18
- #
19
- # To avoid errors, replace all "\n" with " " in shell scripts,
20
- # before SSHKit gets a chance to replace "\n" with ";"
21
6
  def local_unicorn_config
22
7
  if File.exist? fetch(:unicorn_config_rel_file_path)
23
8
  fetch(:unicorn_config_rel_file_path)
@@ -55,7 +40,7 @@ module CapistranoUnicorn
55
40
  # Check if a remote process exists using its pid file
56
41
  #
57
42
  def remote_process_exists?(pid_file)
58
- "[ -e #{pid_file} ] && #{unicorn_send_signal(0, get_unicorn_pid(pid_file))} > /dev/null 2>&1"
43
+ test("[ -e #{pid_file} ]") && execute("#{try_unicorn_user} kill -0 `cat #{pid_file}` > /dev/null 2>&1")
59
44
  end
60
45
 
61
46
  # Stale Unicorn process pid file
@@ -67,7 +52,7 @@ module CapistranoUnicorn
67
52
  # Command to check if Unicorn is running
68
53
  #
69
54
  def unicorn_is_running?
70
- remote_process_exists?(fetch :unicorn_pid)
55
+ remote_process_exists?(fetch(:unicorn_pid))
71
56
  end
72
57
 
73
58
  # Command to check if stale Unicorn is running
@@ -79,7 +64,7 @@ module CapistranoUnicorn
79
64
  # Get unicorn master process PID (using the shell)
80
65
  #
81
66
  def get_unicorn_pid(pid_file=fetch(:unicorn_pid))
82
- "`cat #{pid_file}`"
67
+ capture "cat #{pid_file}"
83
68
  end
84
69
 
85
70
  # Get unicorn master (old) process PID
@@ -92,76 +77,70 @@ module CapistranoUnicorn
92
77
  #
93
78
  def unicorn_send_signal(signal, pid=get_unicorn_pid)
94
79
  sig_prefix = Integer === signal ? '-' : '-s '
95
- "#{try_unicorn_user} kill #{sig_prefix}#{signal} #{pid}"
80
+ execute try_unicorn_user, 'kill', sig_prefix, signal, pid
96
81
  end
97
82
 
98
83
  # Run a command as the :unicorn_user user if :unicorn_user is a string.
99
84
  # Otherwise run as default (:user) user.
100
85
  #
101
86
  def try_unicorn_user
102
- "#{sudo :as => fetch(:unicorn_user).to_s}" if fetch(:unicorn_user).kind_of?(String)
87
+ if unicorn_user = fetch(:unicorn_user)
88
+ "sudo -u #{unicorn_user}"
89
+ else
90
+ ''
91
+ end
103
92
  end
104
93
 
105
94
  # Kill Unicorns in multiple ways O_O
106
95
  #
107
96
  def kill_unicorn(signal)
108
- script = <<-END
109
- if #{unicorn_is_running?}; then
110
- echo "Stopping Unicorn...";
111
- #{unicorn_send_signal(signal)};
112
- else
113
- echo "Unicorn is not running.";
114
- fi;
115
- END
116
- script.split.join(' ')
97
+ if unicorn_is_running?
98
+ puts 'Stopping unicorn...'
99
+ unicorn_send_signal(signal)
100
+ else
101
+ puts 'Unicorn is not running'
102
+ end
117
103
  end
118
104
 
119
105
  # Start the Unicorn server
120
106
  #
121
107
  def start_unicorn
122
- %Q%
123
- if [ -e "#{fetch :unicorn_config_file_path}" ]; then
124
- UNICORN_CONFIG_PATH=#{fetch :unicorn_config_file_path};
108
+ if test("[ -e #{fetch(:unicorn_config_file_path)} ]")
109
+ unicorn_config_file_path = fetch(:unicorn_config_file_path)
110
+ elsif test("[ -e #{fetch(:unicorn_config_stage_file_path)} ]")
111
+ unicorn_config_file_path = fetch(:unicorn_config_stage_file_path)
112
+ else
113
+ fail "Config file for \"#{fetch(:unicorn_env)}\" environment was not found at either \"#{fetch(:unicorn_config_file_path)}\" or \"#{fetch(:unicorn_config_stage_file_path)}\""
114
+ end
115
+
116
+ if test("[ -e #{fetch(:unicorn_pid)} ]")
117
+ if unicorn_is_running?
118
+ puts 'Unicorn is already running!'
119
+ return
125
120
  else
126
- if [ -e "#{fetch :unicorn_config_stage_file_path}" ]; then
127
- UNICORN_CONFIG_PATH=#{fetch :unicorn_config_stage_file_path};
128
- else
129
- echo "Config file for "#{fetch :unicorn_env}" environment was not found at either "#{fetch :unicorn_config_file_path}" or "#{fetch :unicorn_config_stage_file_path}"";
130
- exit 1;
131
- fi;
132
- fi;
133
-
134
- if [ -e "#{fetch :unicorn_pid}" ]; then
135
- if #{try_unicorn_user} kill -0 `cat #{fetch :unicorn_pid}` > /dev/null 2>&1; then
136
- echo "Unicorn is already running!";
137
- exit 0;
138
- fi;
139
-
140
- #{try_unicorn_user} rm #{fetch :unicorn_pid};
141
- fi;
142
-
143
- echo "Starting Unicorn...";
144
- cd #{fetch :app_path} && #{try_unicorn_user} RAILS_ENV=#{fetch :rails_env} BUNDLE_GEMFILE=#{fetch :bundle_gemfile} #{fetch :unicorn_bundle} exec #{fetch :unicorn_bin} -c $UNICORN_CONFIG_PATH -E #{fetch :unicorn_rack_env} -D #{fetch :unicorn_options};
145
- %.split.join(' ')
121
+ execute :rm, fetch(:unicorn_pid)
122
+ end
123
+ end
124
+
125
+ puts 'Starting unicorn...'
126
+
127
+ within fetch(:app_path) do
128
+ with rails_env: fetch(:rails_env), bundle_gemfile: fetch(:bundle_gemfile) do
129
+ execute :bundle, 'exec', fetch(:unicorn_bin), '-c', unicorn_config_file_path, '-E', fetch(:unicorn_rack_env), '-D', fetch(:unicorn_options)
130
+ end
131
+ end
146
132
  end
147
133
 
148
134
  def duplicate_unicorn
149
- script = <<-END
150
- if #{unicorn_is_running?}; then
151
- echo "Duplicating Unicorn...";
152
- #{unicorn_send_signal('USR2')};
153
- else
154
- #{start_unicorn}
155
- fi;
156
- END
157
- script.split.join(' ')
135
+ if unicorn_is_running?
136
+ unicorn_send_signal('USR2')
137
+ else
138
+ start_unicorn
139
+ end
158
140
  end
159
141
 
160
142
  def unicorn_roles
161
- # TODO proc necessary here?
162
- Proc.new{ fetch(:unicorn_roles, :app) }.call
163
- #defer{ fetch(:unicorn_roles, :app) }
143
+ fetch(:unicorn_roles, :app)
164
144
  end
165
-
166
145
  end
167
146
  end
@@ -1,6 +1,6 @@
1
1
  module CapistranoUnicorn
2
2
  MAJOR = 0
3
- MINOR = 4
3
+ MINOR = 5
4
4
  PATCH = 0
5
5
  VERSION = [ MAJOR, MINOR, PATCH ].join('.').freeze
6
6
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sepastian-capistrano3-unicorn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Gassner, Dan Sosedoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-11 00:00:00.000000000 Z
11
+ date: 2014-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: unicorn
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: capistrano
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  description: Capistrano 3.x plugin that integrates Unicorn server tasks.
@@ -58,9 +58,9 @@ executables: []
58
58
  extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
- - ".gitignore"
62
- - ".rspec"
63
- - ".travis.yml"
61
+ - .gitignore
62
+ - .rspec
63
+ - .travis.yml
64
64
  - Gemfile
65
65
  - LICENSE
66
66
  - NEWS.md
@@ -87,19 +87,18 @@ require_paths:
87
87
  - lib
88
88
  required_ruby_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
- - - ">="
90
+ - - '>='
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - ">="
95
+ - - '>='
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  requirements: []
99
99
  rubyforge_project:
100
- rubygems_version: 2.2.1
100
+ rubygems_version: 2.2.2
101
101
  signing_key:
102
102
  specification_version: 4
103
103
  summary: Unicorn integration for Capistrano 3.x
104
104
  test_files: []
105
- has_rdoc: