mina-unicorn 0.0.1 → 0.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b80c4fc1b8579624b751d05cd67ed75bdb1681a1
4
- data.tar.gz: a8cc846739c023060b9bf09b1e3257c4f41450cf
3
+ metadata.gz: 3953720784f4afa682c908bd63633eae2f5ddf36
4
+ data.tar.gz: e0763a88ccdd4f25f49cec03b743a420042836b1
5
5
  SHA512:
6
- metadata.gz: 075d88071b5674b7f21c2a2fb2f918e289974bcc8f411a6ce42b8005e000a9beb9f0d9624ae919357e373c092cd520e6509438cf0d1bc289d0bcf07d48398f29
7
- data.tar.gz: 55d1d1cdf7d408711ba4d5b53a7712b54b4b79c41bcc29548cc09267ebde51b2183ecebb91cda4626d1a258e3946e1fd8e9224eed1806da85aad950906210d3b
6
+ metadata.gz: 6fdf3143af1deb7aef4b77593f0ffcdd557ff37b55c9c675a1e6e9ffcf161975ef73a2e0252740361896111190284e78e91df7212a87654e3b86f0a859a2a7d9
7
+ data.tar.gz: 193a1fd2522318594abb6a788abb98e1ba14c85df580f2d187e502348d687f0c119d717972f72ec93a92824f7c2b3fb3465f038197f8f66ba2a31ab30219b2c1
data/README.md CHANGED
@@ -54,7 +54,7 @@ $ mina unicorn:start
54
54
 
55
55
  ## Contributing
56
56
 
57
- 1. Fork it ( http://github.com/<my-github-username>/mina-unicorn/fork )
57
+ 1. Fork it ( http://github.com/openteam/mina-unicorn/fork )
58
58
  2. Create your feature branch (`git checkout -b my-new-feature`)
59
59
  3. Commit your changes (`git commit -am 'Add some feature'`)
60
60
  4. Push to the branch (`git push origin my-new-feature`)
@@ -1,35 +1,35 @@
1
1
  require 'mina/bundler'
2
2
  require 'mina/rails'
3
+ require 'mina/unicorn/utility'
3
4
 
4
5
  namespace :unicorn do
6
+ include Mina::Unicorn::Utility
7
+
5
8
  set_default :unicorn_role, -> { user }
6
9
  set_default :unicorn_env, -> { fetch(:rails_env, 'production') }
7
10
  set_default :unicorn_config, -> { "#{deploy_to}/#{current_path}/config/unicorn.rb" }
8
11
  set_default :unicorn_pid, -> { "#{deploy_to}/#{current_path}/tmp/pids/unicorn.pid" }
9
12
  set_default :unicorn_cmd, -> { "#{bundle_prefix} unicorn" }
13
+ set_default :unicorn_restart_sleep_time, -> { 2 }
14
+
15
+ desc "Start Unicorn master process"
16
+ task start: :environment do
17
+ queue start_unicorn
18
+ end
10
19
 
11
- desc "Start unicorn service"
12
- task :start => :environment do
13
- queue %{
14
- echo "-----> Starting unicorn service"
15
- #{echo_cmd %[cd #{deploy_to}/#{current_path}; #{unicorn_cmd} -c #{unicorn_config} -D -E #{unicorn_env}]}
16
- }
20
+ desc "Stop Unicorn"
21
+ task stop: :environment do
22
+ queue kill_unicorn('QUIT')
17
23
  end
18
24
 
19
- desc "Stop unicorn service"
20
- task :stop => :environment do
21
- queue %{
22
- echo "-----> Stoping unicorn service"
23
- #{echo_cmd %[kill -s QUIT `cat #{unicorn_pid}`]}
24
- }
25
+ desc "Immediately shutdown Unicorn"
26
+ task shutdown: :environment do
27
+ queue kill_unicorn('TERM')
25
28
  end
26
29
 
27
30
  desc "Restart unicorn service"
28
- task :restart => :environment do
29
- queue %{
30
- echo "-----> Restart unicorn service"
31
- #{echo_cmd %[kill -s USR2 `cat #{unicorn_pid}`]}
32
- }
31
+ task restart: :environment do
32
+ queue restart_unicorn
33
33
  end
34
34
  end
35
35
 
@@ -0,0 +1,109 @@
1
+ # Ported from: https://github.com/sosedoff/capistrano-unicorn/blob/master/lib/capistrano-unicorn/utility.rb
2
+
3
+ module Mina
4
+ module Unicorn
5
+ module Utility
6
+
7
+ # Check if a remote process exists using its pid file
8
+ #
9
+ def remote_process_exists?(pid_file)
10
+ "[ -e #{pid_file} ] && kill -0 `cat #{pid_file}` > /dev/null 2>&1"
11
+ end
12
+
13
+ # Stale Unicorn process pid file
14
+ #
15
+ def old_unicorn_pid
16
+ "#{unicorn_pid}.oldbin"
17
+ end
18
+
19
+ # Command to check if Unicorn is running
20
+ #
21
+ def unicorn_is_running?
22
+ remote_process_exists?(unicorn_pid)
23
+ end
24
+
25
+ # Command to check if stale Unicorn is running
26
+ #
27
+ def old_unicorn_is_running?
28
+ remote_process_exists?(old_unicorn_pid)
29
+ end
30
+
31
+ # Get unicorn master process PID (using the shell)
32
+ #
33
+ def get_unicorn_pid(pid_file=unicorn_pid)
34
+ "`cat #{pid_file}`"
35
+ end
36
+
37
+ # Get unicorn master (old) process PID
38
+ #
39
+ def get_old_unicorn_pid
40
+ get_unicorn_pid(old_unicorn_pid)
41
+ end
42
+
43
+ # Send a signal to a unicorn master processes
44
+ #
45
+ def unicorn_send_signal(signal, pid=get_unicorn_pid)
46
+ "kill -s #{signal} #{pid}"
47
+ end
48
+
49
+ # Kill Unicorns in multiple ways O_O
50
+ #
51
+ def kill_unicorn(signal)
52
+ script = <<-END
53
+ if #{unicorn_is_running?}; then
54
+ echo "Stopping Unicorn...";
55
+ #{unicorn_send_signal(signal)};
56
+ else
57
+ echo "Unicorn is not running.";
58
+ fi;
59
+ END
60
+
61
+ script
62
+ end
63
+
64
+ # Start the Unicorn server
65
+ #
66
+ def start_unicorn
67
+ %Q%
68
+ if [ -e "#{unicorn_pid}" ]; then
69
+ if kill -0 `cat #{unicorn_pid}` > /dev/null 2>&1; then
70
+ echo "Unicorn is already running!";
71
+ exit 0;
72
+ fi;
73
+
74
+ rm #{unicorn_pid};
75
+ fi;
76
+
77
+ echo "Starting Unicorn...";
78
+ cd #{deploy_to}/#{current_path} && BUNDLE_GEMFILE=#{bundle_gemfile} #{unicorn_cmd} -c #{unicorn_config} -E #{unicorn_env} -D;
79
+ %
80
+ end
81
+
82
+ # Restart the Unicorn server
83
+ #
84
+ def restart_unicorn
85
+ %Q%
86
+ #{duplicate_unicorn}
87
+
88
+ sleep #{unicorn_restart_sleep_time}; # in order to wait for the (old) pidfile to show up
89
+
90
+ if #{old_unicorn_is_running?}; then
91
+ #{unicorn_send_signal('QUIT', get_old_unicorn_pid)};
92
+ fi;
93
+ %
94
+ end
95
+
96
+ def duplicate_unicorn
97
+ %Q%
98
+ if #{unicorn_is_running?}; then
99
+ echo "Duplicating Unicorn...";
100
+ #{unicorn_send_signal('USR2')};
101
+ else
102
+ #{start_unicorn}
103
+ fi;
104
+ %
105
+ end
106
+
107
+ end
108
+ end
109
+ end
@@ -1,5 +1,5 @@
1
1
  module Mina
2
2
  module Unicorn
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
data/mina-unicorn.gemspec CHANGED
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "mina", "~> 0.3"
23
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mina-unicorn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - tab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-23 00:00:00.000000000 Z
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mina
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.3'
41
55
  description: Unicorn tasks for Mina
42
56
  email:
43
57
  - tab@openteam.ru
@@ -52,6 +66,7 @@ files:
52
66
  - Rakefile
53
67
  - lib/mina/unicorn.rb
54
68
  - lib/mina/unicorn/tasks.rb
69
+ - lib/mina/unicorn/utility.rb
55
70
  - lib/mina/unicorn/version.rb
56
71
  - mina-unicorn.gemspec
57
72
  homepage: https://github.com/openteam/mina-unicorn