mina-unicorn 0.5.0 → 1.0.1
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 +4 -4
- data/.gitmodules +3 -0
- data/lib/mina/unicorn/tasks.rb +13 -14
- data/lib/mina/unicorn/utility.rb +69 -78
- data/lib/mina/unicorn/version.rb +1 -1
- data/mina-unicorn.gemspec +6 -7
- metadata +4 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3407a88077407fe0e084ead390da97449f021619
|
4
|
+
data.tar.gz: 40072df531552d33ada80e2625eef422ece576d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 509128b20575fc5db0fcb8fd11eef777423d8bd1a1ee138d4359568b5a0436960c2bc765bb70170f47b129df6e9ce27234388af8fafb021d0ea94954b61ae8b4
|
7
|
+
data.tar.gz: ffe8b994f062ed6c782afc9a473210b90c34db33eb2c3ab50d48af1b053a6aed88b3c2cf7049690b5385771e749f14086806785e86b5241b7595e600a6d71b68
|
data/.gitmodules
ADDED
data/lib/mina/unicorn/tasks.rb
CHANGED
@@ -1,36 +1,35 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "mina/bundler"
|
2
|
+
require "mina/rails"
|
3
|
+
require "mina/unicorn/utility"
|
4
4
|
|
5
5
|
namespace :unicorn do
|
6
6
|
include Mina::Unicorn::Utility
|
7
7
|
|
8
8
|
# Following recommendations from http://unicorn.bogomips.org/unicorn_1.html#rack-environment
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
set :unicorn_env, -> { fetch(:rails_env) == "development" ? "development" : "deployment" }
|
10
|
+
set :unicorn_config, -> { "#{fetch(:current_path)}/config/unicorn.rb" }
|
11
|
+
set :unicorn_pid, -> { "#{fetch(:current_path)}/tmp/pids/unicorn.pid" }
|
12
|
+
set :unicorn_cmd, -> { "#{fetch(:bundle_prefix)} unicorn" }
|
13
|
+
set :unicorn_restart_sleep_time, -> { 2 }
|
14
|
+
set :bundle_gemfile, -> { "#{fetch(:current_path)}/Gemfile" }
|
15
15
|
|
16
16
|
desc "Start Unicorn master process"
|
17
17
|
task start: :environment do
|
18
|
-
|
18
|
+
command start_unicorn
|
19
19
|
end
|
20
20
|
|
21
21
|
desc "Stop Unicorn"
|
22
22
|
task stop: :environment do
|
23
|
-
|
23
|
+
command kill_unicorn("QUIT")
|
24
24
|
end
|
25
25
|
|
26
26
|
desc "Immediately shutdown Unicorn"
|
27
27
|
task shutdown: :environment do
|
28
|
-
|
28
|
+
command kill_unicorn("TERM")
|
29
29
|
end
|
30
30
|
|
31
31
|
desc "Restart unicorn service"
|
32
32
|
task restart: :environment do
|
33
|
-
|
33
|
+
command restart_unicorn
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
data/lib/mina/unicorn/utility.rb
CHANGED
@@ -3,114 +3,105 @@
|
|
3
3
|
module Mina
|
4
4
|
module Unicorn
|
5
5
|
module Utility
|
6
|
+
def start_unicorn
|
7
|
+
%{
|
8
|
+
if [ -e "#{unicorn_pid}" ]; then
|
9
|
+
if #{unicorn_user} kill -0 `cat #{unicorn_pid}` > /dev/null 2>&1; then
|
10
|
+
echo "-----> Unicorn is already running!";
|
11
|
+
exit 0;
|
12
|
+
fi;
|
6
13
|
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
def try_unicorn_user
|
11
|
-
"sudo -u #{unicorn_user}" if unicorn_user.kind_of?(String)
|
12
|
-
end
|
14
|
+
#{unicorn_user} rm #{unicorn_pid};
|
15
|
+
fi;
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
"[ -e #{pid_file} ] && #{try_unicorn_user} kill -0 `cat #{pid_file}` > /dev/null 2>&1"
|
17
|
+
echo "-----> Starting Unicorn...";
|
18
|
+
cd #{fetch(:current_path)} && #{unicorn_user} BUNDLE_GEMFILE=#{fetch(:bundle_gemfile)} #{fetch(:unicorn_cmd)} -c #{fetch(:unicorn_config)} -E #{fetch(:unicorn_env)} -D
|
19
|
+
}
|
18
20
|
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
def kill_unicorn(signal)
|
23
|
+
%{
|
24
|
+
if #{unicorn_is_running?}; then
|
25
|
+
echo "-----> Stopping Unicorn...";
|
26
|
+
#{unicorn_send_signal(signal)};
|
27
|
+
else
|
28
|
+
echo "-----> Unicorn is not running.";
|
29
|
+
fi
|
30
|
+
}
|
24
31
|
end
|
25
32
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
remote_process_exists?(unicorn_pid)
|
30
|
-
end
|
33
|
+
def restart_unicorn
|
34
|
+
%{
|
35
|
+
#{duplicate_unicorn}
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
37
|
+
sleep #{fetch(:unicorn_restart_sleep_time)}; # in order to wait for the (old) pidfile to show up
|
38
|
+
|
39
|
+
if #{old_unicorn_is_running?}; then
|
40
|
+
#{unicorn_send_signal("QUIT", get_old_unicorn_pid)};
|
41
|
+
fi
|
42
|
+
}
|
36
43
|
end
|
37
44
|
|
38
|
-
#
|
39
|
-
|
40
|
-
|
41
|
-
"`cat #{pid_file}`"
|
45
|
+
# Send a signal to a unicorn master processes
|
46
|
+
def unicorn_send_signal(signal, pid=get_unicorn_pid)
|
47
|
+
"#{unicorn_user} kill -s #{signal} #{pid}"
|
42
48
|
end
|
43
49
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
50
|
+
private
|
51
|
+
|
52
|
+
# Run a command as the :unicorn_user user if :unicorn_user is set
|
53
|
+
# Otherwise run without sudo
|
54
|
+
def unicorn_user
|
55
|
+
"sudo -u #{fetch(:unicorn_user)}" if set?(:unicorn_user)
|
48
56
|
end
|
49
57
|
|
50
|
-
#
|
58
|
+
# Check if a remote process exists using its pid file
|
51
59
|
#
|
52
|
-
def
|
53
|
-
"#{
|
60
|
+
def remote_process_exists?(pid_file)
|
61
|
+
"[ -e #{pid_file} ] && #{unicorn_user} kill -0 `cat #{pid_file}` > /dev/null 2>&1"
|
54
62
|
end
|
55
63
|
|
56
|
-
|
57
|
-
|
58
|
-
def kill_unicorn(signal)
|
59
|
-
script = <<-END
|
64
|
+
def duplicate_unicorn
|
65
|
+
%{
|
60
66
|
if #{unicorn_is_running?}; then
|
61
|
-
echo "----->
|
62
|
-
#{unicorn_send_signal(
|
67
|
+
echo "-----> Duplicating Unicorn...";
|
68
|
+
#{unicorn_send_signal("USR2")};
|
63
69
|
else
|
64
|
-
|
65
|
-
fi
|
66
|
-
|
67
|
-
|
68
|
-
script
|
70
|
+
#{start_unicorn}
|
71
|
+
fi
|
72
|
+
}
|
69
73
|
end
|
70
74
|
|
71
|
-
#
|
75
|
+
# Command to check if Unicorn is running
|
72
76
|
#
|
73
|
-
def
|
74
|
-
|
75
|
-
if [ -e "#{unicorn_pid}" ]; then
|
76
|
-
if #{try_unicorn_user} kill -0 `cat #{unicorn_pid}` > /dev/null 2>&1; then
|
77
|
-
echo "-----> Unicorn is already running!";
|
78
|
-
exit 0;
|
79
|
-
fi;
|
80
|
-
|
81
|
-
#{try_unicorn_user} rm #{unicorn_pid};
|
82
|
-
fi;
|
83
|
-
|
84
|
-
echo "-----> Starting Unicorn...";
|
85
|
-
cd #{deploy_to}/#{current_path} && #{try_unicorn_user} BUNDLE_GEMFILE=#{bundle_gemfile} #{unicorn_cmd} -c #{unicorn_config} -E #{unicorn_env} -D;
|
86
|
-
%
|
77
|
+
def unicorn_is_running?
|
78
|
+
remote_process_exists?(unicorn_pid)
|
87
79
|
end
|
88
80
|
|
89
|
-
#
|
81
|
+
# Command to check if stale Unicorn is running
|
90
82
|
#
|
91
|
-
def
|
92
|
-
|
93
|
-
|
83
|
+
def old_unicorn_is_running?
|
84
|
+
remote_process_exists?(old_unicorn_pid)
|
85
|
+
end
|
94
86
|
|
95
|
-
|
87
|
+
def unicorn_pid
|
88
|
+
fetch(:unicorn_pid)
|
89
|
+
end
|
96
90
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
%
|
91
|
+
# Stale Unicorn process pid file
|
92
|
+
def old_unicorn_pid
|
93
|
+
"#{unicorn_pid}.oldbin"
|
101
94
|
end
|
102
95
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
echo "-----> Duplicating Unicorn...";
|
107
|
-
#{unicorn_send_signal('USR2')};
|
108
|
-
else
|
109
|
-
#{start_unicorn}
|
110
|
-
fi;
|
111
|
-
%
|
96
|
+
# Get unicorn master (old) process PID
|
97
|
+
def get_old_unicorn_pid
|
98
|
+
get_unicorn_pid(old_unicorn_pid)
|
112
99
|
end
|
113
100
|
|
101
|
+
# Get unicorn master process PID (using the shell)
|
102
|
+
def get_unicorn_pid(pid_file=unicorn_pid)
|
103
|
+
"`cat #{pid_file}`"
|
104
|
+
end
|
114
105
|
end
|
115
106
|
end
|
116
107
|
end
|
data/lib/mina/unicorn/version.rb
CHANGED
data/mina-unicorn.gemspec
CHANGED
@@ -1,24 +1,23 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
|
3
|
+
|
4
|
+
require "mina/unicorn/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "mina-unicorn"
|
8
8
|
spec.version = Mina::Unicorn::VERSION
|
9
9
|
spec.authors = ["tab", "Andrew Volozhanin"]
|
10
|
-
spec.email = ["
|
10
|
+
spec.email = ["scarfacedeb@gmail.com"]
|
11
11
|
spec.summary = %q{Unicorn tasks for Mina}
|
12
12
|
spec.description = %q{Unicorn tasks for Mina}
|
13
13
|
spec.homepage = "https://github.com/scarfacedeb/mina-unicorn"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.test_files = []
|
19
18
|
spec.require_paths = ["lib"]
|
20
19
|
|
21
|
-
spec.add_dependency "mina", "~>
|
20
|
+
spec.add_dependency "mina", "~> 1.0"
|
22
21
|
|
23
22
|
spec.add_development_dependency "bundler"
|
24
23
|
spec.add_development_dependency "rake"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mina-unicorn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tab
|
@@ -9,16 +9,13 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mina
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '0.3'
|
21
|
-
- - "<"
|
22
19
|
- !ruby/object:Gem::Version
|
23
20
|
version: '1.0'
|
24
21
|
type: :runtime
|
@@ -26,9 +23,6 @@ dependencies:
|
|
26
23
|
version_requirements: !ruby/object:Gem::Requirement
|
27
24
|
requirements:
|
28
25
|
- - "~>"
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
version: '0.3'
|
31
|
-
- - "<"
|
32
26
|
- !ruby/object:Gem::Version
|
33
27
|
version: '1.0'
|
34
28
|
- !ruby/object:Gem::Dependency
|
@@ -61,12 +55,13 @@ dependencies:
|
|
61
55
|
version: '0'
|
62
56
|
description: Unicorn tasks for Mina
|
63
57
|
email:
|
64
|
-
-
|
58
|
+
- scarfacedeb@gmail.com
|
65
59
|
executables: []
|
66
60
|
extensions: []
|
67
61
|
extra_rdoc_files: []
|
68
62
|
files:
|
69
63
|
- ".gitignore"
|
64
|
+
- ".gitmodules"
|
70
65
|
- Gemfile
|
71
66
|
- LICENSE.txt
|
72
67
|
- README.md
|