guard-unicorn 0.0.3 → 0.0.4
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/lib/guard/unicorn/version.rb +1 -1
- data/lib/guard/unicorn.rb +56 -49
- metadata +12 -12
data/lib/guard/unicorn.rb
CHANGED
@@ -6,6 +6,10 @@ require 'guard/unicorn/version'
|
|
6
6
|
module Guard
|
7
7
|
class Unicorn < Guard
|
8
8
|
|
9
|
+
# Sensible defaults for Rails projects
|
10
|
+
DEFAULT_PID_PATH = File.join("tmp", "pids", "unicorn.pid")
|
11
|
+
DEFAULT_CONFIG_PATH = File.join("config", "unicorn.rb")
|
12
|
+
|
9
13
|
# Initialize a Guard.
|
10
14
|
# @param [Array<Guard::Watcher>] watchers the Guard file watchers
|
11
15
|
# @param [Hash] options the custom Guard options
|
@@ -15,10 +19,10 @@ module Guard
|
|
15
19
|
watchers << Watcher.new( /^lib\/.+\.rb$/ )
|
16
20
|
end
|
17
21
|
|
18
|
-
@run_as_daemon
|
19
|
-
|
20
|
-
@
|
21
|
-
@
|
22
|
+
@run_as_daemon = options.fetch(:daemonize, false)
|
23
|
+
@enable_bundler = options.fetch(:bundler, true)
|
24
|
+
@pid_file = options.fetch(:pid_file, DEFAULT_PID_PATH)
|
25
|
+
@config_file = options.fetch(:config_file, DEFAULT_CONFIG_PATH)
|
22
26
|
|
23
27
|
super
|
24
28
|
end
|
@@ -26,23 +30,47 @@ module Guard
|
|
26
30
|
# Call once when Guard starts. Please override initialize method to init stuff.
|
27
31
|
# @raise [:task_has_failed] when start has failed
|
28
32
|
def start
|
29
|
-
|
30
|
-
|
33
|
+
# Make sure unicorn is stopped
|
34
|
+
stop
|
35
|
+
|
36
|
+
cmd = []
|
37
|
+
cmd << "bundle exec" if @enable_bundler
|
38
|
+
cmd << "unicorn_rails"
|
39
|
+
cmd << "-c #{@config_file}"
|
40
|
+
cmd << "-D" if @run_as_daemon
|
41
|
+
|
42
|
+
@pid = Process.fork do
|
43
|
+
system "#{cmd.join " "}"
|
44
|
+
end
|
45
|
+
|
46
|
+
success "Unicorn started."
|
31
47
|
end
|
32
48
|
|
33
49
|
# Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
|
34
50
|
# @raise [:task_has_failed] when stop has failed
|
35
51
|
def stop
|
36
|
-
|
37
|
-
|
52
|
+
return unless pid
|
53
|
+
|
54
|
+
begin
|
55
|
+
Process.kill("QUIT", pid) if Process.getpgid(pid)
|
56
|
+
|
57
|
+
# Unicorn won't always shut down right away, so we're waiting for
|
58
|
+
# the getpgid method to raise an Errno::ESRCH that will tell us
|
59
|
+
# the process is not longer active.
|
60
|
+
sleep 1 while Process.getpgid(pid)
|
61
|
+
success "Unicorn stopped."
|
62
|
+
rescue Errno::ESRCH
|
63
|
+
# Don't do anything, the process does not exist
|
64
|
+
end
|
38
65
|
end
|
39
66
|
|
40
67
|
# Called when `reload|r|z + enter` is pressed.
|
41
68
|
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
|
42
69
|
# @raise [:task_has_failed] when reload has failed
|
43
70
|
def reload
|
44
|
-
|
45
|
-
|
71
|
+
Process.kill "HUP", pid
|
72
|
+
|
73
|
+
success "Unicorn reloaded"
|
46
74
|
end
|
47
75
|
|
48
76
|
# Called when just `enter` is pressed
|
@@ -55,55 +83,22 @@ module Guard
|
|
55
83
|
# @param [Array<String>] paths the changes files or paths
|
56
84
|
# @raise [:task_has_failed] when run_on_change has failed
|
57
85
|
def run_on_change(paths)
|
58
|
-
|
86
|
+
reload
|
59
87
|
end
|
60
88
|
|
61
89
|
# Called on file(s) deletions that the Guard watches.
|
62
90
|
# @param [Array<String>] paths the deleted files or paths
|
63
91
|
# @raise [:task_has_failed] when run_on_change has failed
|
64
92
|
def run_on_deletion(paths)
|
93
|
+
reload
|
65
94
|
end
|
66
95
|
|
67
96
|
private
|
68
|
-
def start_unicorn
|
69
|
-
# Make sure unicorn is stopped
|
70
|
-
stop_unicorn
|
71
|
-
|
72
|
-
cmd = []
|
73
|
-
cmd << "unicorn_rails"
|
74
|
-
cmd << "-c #{@config_path}"
|
75
|
-
cmd << "-D" if daemonize?
|
76
|
-
|
77
|
-
@pid = Process.fork do
|
78
|
-
system "#{cmd.join " "}"
|
79
|
-
info "Unicorn started."
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def restart_unicorn
|
84
|
-
Process.kill "HUP", pid
|
85
|
-
end
|
86
|
-
|
87
|
-
def stop_unicorn
|
88
|
-
return unless pid
|
89
|
-
|
90
|
-
begin
|
91
|
-
Process.kill("QUIT", pid) if Process.getpgid(pid)
|
92
|
-
|
93
|
-
# Unicorn won't always shut down right away, so we're waiting for
|
94
|
-
# the getpgid method to raise an Errno::ESRCH that will tell us
|
95
|
-
# the process is not longer active.
|
96
|
-
sleep 1 while Process.getpgid(pid)
|
97
|
-
rescue Errno::ESRCH
|
98
|
-
# Don't do anything, the process does not exist
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
97
|
def pid
|
103
98
|
# Favor the pid in the pidfile, since some processes
|
104
99
|
# might daemonize properly and fork twice.
|
105
|
-
if File.exists?(@
|
106
|
-
@pid = File.open(@
|
100
|
+
if File.exists?(@pid_file)
|
101
|
+
@pid = File.open(@pid_file) { |f| f.gets.to_i }
|
107
102
|
end
|
108
103
|
|
109
104
|
@pid
|
@@ -113,8 +108,20 @@ module Guard
|
|
113
108
|
UI.info(msg)
|
114
109
|
end
|
115
110
|
|
116
|
-
def
|
117
|
-
|
111
|
+
def pending message
|
112
|
+
notify message, :image => :pending
|
113
|
+
end
|
114
|
+
|
115
|
+
def success message
|
116
|
+
notify message, :image => :success
|
117
|
+
end
|
118
|
+
|
119
|
+
def failed message
|
120
|
+
notify message, :image => :failed
|
121
|
+
end
|
122
|
+
|
123
|
+
def notify(message, options = {})
|
124
|
+
Notifier.notify(message, options)
|
118
125
|
end
|
119
126
|
end
|
120
127
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-unicorn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
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-03-
|
12
|
+
date: 2012-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: guard
|
16
|
-
requirement: &
|
16
|
+
requirement: &70274208930740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70274208930740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70274208930260 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70274208930260
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70274208929700 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70274208929700
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: minitest
|
49
|
-
requirement: &
|
49
|
+
requirement: &70274208929180 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70274208929180
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: guard
|
60
|
-
requirement: &
|
60
|
+
requirement: &70274208928640 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70274208928640
|
69
69
|
description: Guard plug-in that allows you to restart Unicorn
|
70
70
|
email:
|
71
71
|
- andrei@andreimaxim.ro
|