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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6fe880304443f6319045f213fae4dff90102305
4
- data.tar.gz: 3c788e78209e89217951694f584d5fc85d85da3f
3
+ metadata.gz: 3407a88077407fe0e084ead390da97449f021619
4
+ data.tar.gz: 40072df531552d33ada80e2625eef422ece576d8
5
5
  SHA512:
6
- metadata.gz: 00288438c7599ef0d5be29778e9314bc6146330ee0b0623cb092c293372b7c2179451e04cc461a8cf57cdc90b053ae5334ce5360430c52ee46eaa453dff12f25
7
- data.tar.gz: 05eb27ce841e26b606742f49c2da2d27a3661af0ba702b7bca0eb11bce8f8ac83e63a0015e552ae03fcbad7b36b09de4d13d7dc2349b96d51d6112eebab609bf
6
+ metadata.gz: 509128b20575fc5db0fcb8fd11eef777423d8bd1a1ee138d4359568b5a0436960c2bc765bb70170f47b129df6e9ce27234388af8fafb021d0ea94954b61ae8b4
7
+ data.tar.gz: ffe8b994f062ed6c782afc9a473210b90c34db33eb2c3ab50d48af1b053a6aed88b3c2cf7049690b5385771e749f14086806785e86b5241b7595e600a6d71b68
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "test/unicorn_test"]
2
+ path = test/unicorn_test
3
+ url = git@github.com:scarfacedeb/mina-unicorn-test.git
@@ -1,36 +1,35 @@
1
- require 'mina/bundler'
2
- require 'mina/rails'
3
- require 'mina/unicorn/utility'
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
- set_default :unicorn_env, -> { fetch(:rails_env) == 'development' ? 'development' : 'deployment' }
10
- set_default :unicorn_config, -> { "#{deploy_to}/#{current_path}/config/unicorn.rb" }
11
- set_default :unicorn_pid, -> { "#{deploy_to}/#{current_path}/tmp/pids/unicorn.pid" }
12
- set_default :unicorn_cmd, -> { "#{bundle_prefix} unicorn" }
13
- set_default :unicorn_restart_sleep_time, -> { 2 }
14
- set_default :bundle_gemfile, -> { "#{deploy_to}/#{current_path}/Gemfile" }
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
- queue start_unicorn
18
+ command start_unicorn
19
19
  end
20
20
 
21
21
  desc "Stop Unicorn"
22
22
  task stop: :environment do
23
- queue kill_unicorn('QUIT')
23
+ command kill_unicorn("QUIT")
24
24
  end
25
25
 
26
26
  desc "Immediately shutdown Unicorn"
27
27
  task shutdown: :environment do
28
- queue kill_unicorn('TERM')
28
+ command kill_unicorn("TERM")
29
29
  end
30
30
 
31
31
  desc "Restart unicorn service"
32
32
  task restart: :environment do
33
- queue restart_unicorn
33
+ command restart_unicorn
34
34
  end
35
35
  end
36
-
@@ -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
- # Run a command as the :unicorn_user user if :unicorn_user is a string.
8
- # Otherwise run as default (:user) user.
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
- # Check if a remote process exists using its pid file
15
- #
16
- def remote_process_exists?(pid_file)
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
- # Stale Unicorn process pid file
21
- #
22
- def old_unicorn_pid
23
- "#{unicorn_pid}.oldbin"
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
- # Command to check if Unicorn is running
27
- #
28
- def unicorn_is_running?
29
- remote_process_exists?(unicorn_pid)
30
- end
33
+ def restart_unicorn
34
+ %{
35
+ #{duplicate_unicorn}
31
36
 
32
- # Command to check if stale Unicorn is running
33
- #
34
- def old_unicorn_is_running?
35
- remote_process_exists?(old_unicorn_pid)
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
- # Get unicorn master process PID (using the shell)
39
- #
40
- def get_unicorn_pid(pid_file=unicorn_pid)
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
- # Get unicorn master (old) process PID
45
- #
46
- def get_old_unicorn_pid
47
- get_unicorn_pid(old_unicorn_pid)
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
- # Send a signal to a unicorn master processes
58
+ # Check if a remote process exists using its pid file
51
59
  #
52
- def unicorn_send_signal(signal, pid=get_unicorn_pid)
53
- "#{try_unicorn_user} kill -s #{signal} #{pid}"
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
- # Kill Unicorns in multiple ways O_O
57
- #
58
- def kill_unicorn(signal)
59
- script = <<-END
64
+ def duplicate_unicorn
65
+ %{
60
66
  if #{unicorn_is_running?}; then
61
- echo "-----> Stopping Unicorn...";
62
- #{unicorn_send_signal(signal)};
67
+ echo "-----> Duplicating Unicorn...";
68
+ #{unicorn_send_signal("USR2")};
63
69
  else
64
- echo "-----> Unicorn is not running.";
65
- fi;
66
- END
67
-
68
- script
70
+ #{start_unicorn}
71
+ fi
72
+ }
69
73
  end
70
74
 
71
- # Start the Unicorn server
75
+ # Command to check if Unicorn is running
72
76
  #
73
- def start_unicorn
74
- %Q%
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
- # Restart the Unicorn server
81
+ # Command to check if stale Unicorn is running
90
82
  #
91
- def restart_unicorn
92
- %Q%
93
- #{duplicate_unicorn}
83
+ def old_unicorn_is_running?
84
+ remote_process_exists?(old_unicorn_pid)
85
+ end
94
86
 
95
- sleep #{unicorn_restart_sleep_time}; # in order to wait for the (old) pidfile to show up
87
+ def unicorn_pid
88
+ fetch(:unicorn_pid)
89
+ end
96
90
 
97
- if #{old_unicorn_is_running?}; then
98
- #{unicorn_send_signal('QUIT', get_old_unicorn_pid)};
99
- fi;
100
- %
91
+ # Stale Unicorn process pid file
92
+ def old_unicorn_pid
93
+ "#{unicorn_pid}.oldbin"
101
94
  end
102
95
 
103
- def duplicate_unicorn
104
- %Q%
105
- if #{unicorn_is_running?}; then
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
@@ -1,5 +1,5 @@
1
1
  module Mina
2
2
  module Unicorn
3
- VERSION = "0.5.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
data/mina-unicorn.gemspec CHANGED
@@ -1,24 +1,23 @@
1
- # coding: utf-8
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
- require 'mina/unicorn/version'
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 = ["linuxheadrus@gmail.com"]
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.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
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", "~> 0.3", "< 1.0"
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.5.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-10-22 00:00:00.000000000 Z
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
- - linuxheadrus@gmail.com
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