capobvious 0.1.2 → 0.1.3
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.
- data/bin/unicorn.rb +43 -0
- data/lib/capistrano/ext/capobvious.rb +80 -32
- data/lib/capobvious/version.rb +1 -1
- metadata +12 -5
data/bin/unicorn.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
APP_PATH = File.expand_path(File.dirname(File.dirname(__FILE__)))
|
3
|
+
SHARED_PATH = File.expand_path(APP_PATH+"/../shared")
|
4
|
+
|
5
|
+
working_directory APP_PATH
|
6
|
+
|
7
|
+
pid_file = SHARED_PATH + "/pids/unicorn.pid"
|
8
|
+
socket_file= SHARED_PATH + "/pids/unicorn.sock"
|
9
|
+
log_file = APP_PATH + "/log/unicorn.log"
|
10
|
+
err_log = APP_PATH + "/log/unicorn.stderr.log"
|
11
|
+
old_pid = pid_file + '.oldbin'
|
12
|
+
|
13
|
+
|
14
|
+
timeout 30
|
15
|
+
worker_processes 4
|
16
|
+
preload_app true
|
17
|
+
listen socket_file, :backlog => 1024
|
18
|
+
pid pid_file
|
19
|
+
stderr_path err_log
|
20
|
+
stdout_path log_file
|
21
|
+
|
22
|
+
GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=)
|
23
|
+
|
24
|
+
|
25
|
+
before_exec do |server|
|
26
|
+
ENV["BUNDLE_GEMFILE"] = "#{APP_PATH}/Gemfile"
|
27
|
+
end
|
28
|
+
|
29
|
+
before_fork do |server, worker|
|
30
|
+
defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect!
|
31
|
+
|
32
|
+
if File.exists?(old_pid) && server.pid != old_pid
|
33
|
+
begin
|
34
|
+
#sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
|
35
|
+
Process.kill("QUIT", File.read(old_pid).to_i)
|
36
|
+
rescue Errno::ENOENT, Errno::ESRCH
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
after_fork do |server, worker|
|
42
|
+
defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection
|
43
|
+
end
|
@@ -54,16 +54,51 @@ Capistrano::Configuration.instance.load do
|
|
54
54
|
|
55
55
|
|
56
56
|
#after "deploy:symlink", "auto:run"
|
57
|
-
before "deploy:restart", "auto:run"
|
58
57
|
#after "deploy:setup", "db:create", "nginx:conf", "install:p7zip"
|
59
58
|
|
60
|
-
#load 'deploy/assets'
|
59
|
+
# load 'deploy/assets'
|
60
|
+
|
61
|
+
after 'deploy:update_code', 'bundle:install', 'assets:precompile'
|
62
|
+
before 'deploy:finalize_update', 'assets:symlink'
|
63
|
+
before "deploy:restart", "auto:run"
|
64
|
+
|
65
|
+
namespace :assets do
|
66
|
+
desc "Local Assets precompile"
|
67
|
+
task :local_precompile do
|
68
|
+
system("bundle exec rake assets:precompile && cd public && tar czf assets.tar.gz assets/")
|
69
|
+
upload("public/assets.tar.gz","#{current_path}/public/assets.tar.gz")
|
70
|
+
system("rm public/assets.tar.gz && rm -rf tmp/assets && mv public/assets tmp/assets")
|
71
|
+
run("cd #{current_path}/public && rm -rf assets/ && tar xzf assets.tar.gz && rm assets.tar.gz")
|
72
|
+
end
|
73
|
+
desc "Assets precompile"
|
74
|
+
task :precompile, :roles => :web, :except => { :no_release => true } do
|
75
|
+
run("cd #{latest_release} && bundle exec rake RAILS_ENV=#{rails_env} RAILS_GROUPS=assets assets:precompile")
|
76
|
+
end
|
77
|
+
task :symlink, :roles => :web, :except => { :no_release => true } do
|
78
|
+
run <<-CMD
|
79
|
+
rm -rf #{latest_release}/public/assets &&
|
80
|
+
mkdir -p #{latest_release}/public &&
|
81
|
+
mkdir -p #{shared_path}/assets &&
|
82
|
+
ln -s #{shared_path}/assets #{latest_release}/public/assets
|
83
|
+
CMD
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
namespace :bundle do
|
88
|
+
desc "Run bundle install"
|
89
|
+
task :install do
|
90
|
+
deployment = "--deployment --quiet"
|
91
|
+
without = ['development','test','production']-[rails_env]
|
92
|
+
run "cd #{latest_release} && bundle install --without #{without.join(" ")}"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
61
96
|
namespace :auto do
|
62
97
|
task :run do
|
63
|
-
bundle.install
|
64
|
-
if exists?(:assets) && fetch(:assets) == true
|
65
|
-
assets.precompile
|
66
|
-
end
|
98
|
+
# bundle.install
|
99
|
+
# if exists?(:assets) && fetch(:assets) == true
|
100
|
+
# assets.precompile
|
101
|
+
# end
|
67
102
|
create.files
|
68
103
|
if exists?(:sphinx) && fetch(:sphinx) == true
|
69
104
|
sphinx.symlink
|
@@ -215,19 +250,6 @@ Capistrano::Configuration.instance.load do
|
|
215
250
|
before "deploy:update", "backup:sys"
|
216
251
|
end
|
217
252
|
|
218
|
-
namespace :assets do
|
219
|
-
desc "Local Assets precompile"
|
220
|
-
task :precompile do
|
221
|
-
system("bundle exec rake assets:precompile && cd public && tar czf assets.tar.gz assets/")
|
222
|
-
upload("public/assets.tar.gz","#{current_path}/public/assets.tar.gz")
|
223
|
-
system("rm public/assets.tar.gz && rm -rf tmp/assets && mv public/assets tmp/assets")
|
224
|
-
run("cd #{current_path}/public && rm -rf assets/ && tar xzf assets.tar.gz && rm assets.tar.gz")
|
225
|
-
end
|
226
|
-
desc "Assets precompile"
|
227
|
-
task :remote_precompile, :roles => :web, :except => { :no_release => true } do
|
228
|
-
run("cd #{current_path} && bundle exec rake RAILS_ENV=#{rails_env} assets:precompile")
|
229
|
-
end
|
230
|
-
end
|
231
253
|
|
232
254
|
namespace :nginx do
|
233
255
|
[:stop, :start, :restart, :reload].each do |action|
|
@@ -306,14 +328,6 @@ Capistrano::Configuration.instance.load do
|
|
306
328
|
after "nginx:delconf", "nginx:reload"
|
307
329
|
|
308
330
|
|
309
|
-
namespace :bundle do
|
310
|
-
desc "Run bundle install"
|
311
|
-
task :install do
|
312
|
-
deployment = "--deployment --quiet"
|
313
|
-
without = ['development','test','production']-[rails_env]
|
314
|
-
run "cd #{current_path} && bundle install --without #{without.join(" ")}"
|
315
|
-
end
|
316
|
-
end
|
317
331
|
|
318
332
|
namespace :log do
|
319
333
|
desc "tail -f production.log"
|
@@ -378,25 +392,59 @@ Capistrano::Configuration.instance.load do
|
|
378
392
|
|
379
393
|
|
380
394
|
|
381
|
-
|
395
|
+
# Check if remote file exists
|
396
|
+
#
|
397
|
+
def remote_file_exists?(full_path)
|
398
|
+
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
|
399
|
+
end
|
400
|
+
|
401
|
+
# Check if process is running
|
402
|
+
#
|
403
|
+
def remote_process_exists?(pid_file)
|
404
|
+
capture("ps -p $(cat #{pid_file}) ; true").strip.split("\n").size == 2
|
405
|
+
end
|
382
406
|
|
383
407
|
set :unicorn_conf, "#{current_path}/config/unicorn.rb"
|
384
408
|
set :unicorn_pid, "#{shared_path}/pids/unicorn.pid"
|
385
409
|
namespace :unicorn do
|
386
410
|
desc "start unicorn"
|
387
411
|
task :start do
|
412
|
+
if remote_file_exists?(unicorn_pid)
|
413
|
+
if remote_process_exists?(unicorn_pid)
|
414
|
+
logger.important("Unicorn is already running!", "Unicorn")
|
415
|
+
next
|
416
|
+
else
|
417
|
+
run "rm #{unicorn_pid}"
|
418
|
+
end
|
419
|
+
end
|
420
|
+
logger.important("Starting...", "Unicorn")
|
388
421
|
run "cd #{current_path} && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D"
|
389
422
|
end
|
390
423
|
desc "stop unicorn"
|
391
424
|
#task :stop, :roles => :app, :except => {:no_release => true} do
|
392
425
|
task :stop do
|
393
|
-
|
426
|
+
if remote_file_exists?(unicorn_pid)
|
427
|
+
if remote_process_exists?(unicorn_pid)
|
428
|
+
logger.important("Stopping...", "Unicorn")
|
429
|
+
run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
|
430
|
+
else
|
431
|
+
run "rm #{unicorn_pid}"
|
432
|
+
logger.important("Unicorn is not running.", "Unicorn")
|
433
|
+
end
|
434
|
+
else
|
435
|
+
logger.important("No PIDs found. Check if unicorn is running.", "Unicorn")
|
436
|
+
end
|
394
437
|
end
|
395
438
|
desc "restart unicorn"
|
396
439
|
task :restart do
|
397
|
-
|
398
|
-
|
399
|
-
|
440
|
+
remote_file_exists = capture("ps -p $(cat #{unicorn_pid}) ; true").strip.split("\n").size == 2
|
441
|
+
if remote_file_exists
|
442
|
+
logger.important("Stopping...", "Unicorn")
|
443
|
+
run "#{try_sudo} kill -s USR2 `cat #{unicorn_pid}`"
|
444
|
+
else
|
445
|
+
logger.important("No PIDs found. Starting Unicorn server...", "Unicorn")
|
446
|
+
run "cd #{current_path} && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D"
|
447
|
+
end
|
400
448
|
end
|
401
449
|
end
|
402
450
|
|
data/lib/capobvious/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capobvious
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,12 +21,18 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
description: Capfile that we use every day
|
26
31
|
email:
|
27
32
|
- donotsendhere@gmail.com
|
28
33
|
executables:
|
29
34
|
- capobvious
|
35
|
+
- unicorn.rb
|
30
36
|
extensions: []
|
31
37
|
extra_rdoc_files: []
|
32
38
|
files:
|
@@ -35,6 +41,7 @@ files:
|
|
35
41
|
- README.markdown
|
36
42
|
- Rakefile
|
37
43
|
- bin/capobvious
|
44
|
+
- bin/unicorn.rb
|
38
45
|
- capobvious.gemspec
|
39
46
|
- lib/capistrano/ext/capobvious.rb
|
40
47
|
- lib/capobvious/version.rb
|
@@ -58,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
65
|
version: '0'
|
59
66
|
requirements: []
|
60
67
|
rubyforge_project: capobvious
|
61
|
-
rubygems_version: 1.8.
|
68
|
+
rubygems_version: 1.8.19
|
62
69
|
signing_key:
|
63
70
|
specification_version: 3
|
64
71
|
summary: Cap recipes
|