luban 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f634550b34b8380b8a9bb38189ab450e3c50a34
4
- data.tar.gz: d507cdf9924ca36905c4e8a8585a7835071e1168
3
+ metadata.gz: a5795337e52a2753d22609fc84702c7b7efc71e2
4
+ data.tar.gz: 09109191101bc31336b281f2909904d94a5cc78d
5
5
  SHA512:
6
- metadata.gz: 75e17a9e3a96df84cea850e4313060c5cb2a4ca09c2e4274ff75d09704b6deb55a49f6f1e8656c471e7ed51aa883d3a77b179c3a7bdb39a7d1d42b315ceb948b
7
- data.tar.gz: 246833cd50c99ef0d7d0d847a2a3aa44efec01ef0832df7868ff89ce06f94a7c829fd240a4252c2c22bc458384567d4f8e4967c1366c5f66630fb3542a161b9e
6
+ metadata.gz: ccce4793c55524d64f73ffea182d7c6336305876b15b7e1cbd5e3c43f4661a5457f36e9a69ddf554f93ded4380bc32c826637929dd60ff8c2280eb8df52e5327
7
+ data.tar.gz: f5b260f3f809787821928d385184dbb2febdb914785f48ed958e47a74a04df0987959c6a476727cc3ed24e523ff1bd4b14ab9a0e959f74a38a806bd35db00b4b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Change log
2
2
 
3
+ ## Version 0.4.3 (Jun 16, 2016)
4
+
5
+ Minor enhancements:
6
+ * Changed #default_executable to #define_executable with a better general approach
7
+ * Refactored start/stop/monitor/unmonitor into corresponding commands for better reusability
8
+ * Added convenient methods, #default_pending_seconds and # default_pending_interval
9
+ * These two methods provided a better way to customize timging for process status check
10
+ * Refactored header information into a generic header template for all erb template files
11
+
12
+ Bug fixes:
13
+ * Fixed monitor/unmonitor timing for start/stop operations
14
+ * Checked process status before killing process
15
+
3
16
  ## Version 0.4.2 (Jun 07, 2016)
4
17
 
5
18
  Minor enhancements:
@@ -13,9 +13,15 @@ module Luban
13
13
  Luban::Deployment::Package::Base.worker_class(worker, **opts)
14
14
  end
15
15
 
16
- def default_executable(name)
17
- define_method("#{name}_executable") do
18
- @default_executable ||= bin_path.join(name)
16
+ def define_executable(*names)
17
+ names.each do |name|
18
+ define_method("#{name}_executable") do
19
+ if instance_variable_defined?("@#{__method__}")
20
+ instance_variable_get("@#{__method__}")
21
+ else
22
+ instance_variable_set("@#{__method__}", bin_path.join(name))
23
+ end
24
+ end
19
25
  end
20
26
  end
21
27
  end
@@ -26,8 +26,23 @@ module Luban
26
26
  file?(pid_file_path, "-s") # file is NOT zero size
27
27
  end
28
28
 
29
- def process_pattern
30
- raise NotImplementedError, "#{self.class.name}##{__method__} is an abstract method."
29
+ %i(process_pattern start_command stop_command).each do |m|
30
+ define_method(m) do
31
+ raise NotImplementedError, "#{self.class.name}##{__method__} is an abstract method."
32
+ end
33
+ end
34
+
35
+ def monitor_executable
36
+ @monitor_executable ||= env_path.join("#{stage}.#{process_monitor[:env]}").
37
+ join('bin').join(process_monitor[:name])
38
+ end
39
+
40
+ def monitor_command
41
+ @monitor_command ||= "#{monitor_executable} monitor #{service_entry}"
42
+ end
43
+
44
+ def unmonitor_command
45
+ @unmonitor_command ||= "#{monitor_executable} unmonitor #{service_entry}"
31
46
  end
32
47
 
33
48
  def start_process
@@ -38,8 +53,8 @@ module Luban
38
53
 
39
54
  output = start_process!
40
55
  if check_until { process_started? }
41
- monitor_process
42
56
  update_result "Start #{package_full_name}: [OK] #{output}"
57
+ monitor_process
43
58
  else
44
59
  remove_orphaned_pid_file
45
60
  update_result "Start #{package_full_name}: [FAILED] #{output}",
@@ -53,9 +68,9 @@ module Luban
53
68
  return
54
69
  end
55
70
 
71
+ unmonitor_process
56
72
  output = stop_process! || 'OK'
57
73
  if check_until { process_stopped? }
58
- unmonitor_process
59
74
  update_result "Stop #{package_full_name}: [OK] #{output}"
60
75
  else
61
76
  remove_orphaned_pid_file
@@ -66,10 +81,10 @@ module Luban
66
81
 
67
82
  def restart_process
68
83
  if process_started?
84
+ unmonitor_process
69
85
  output = stop_process!
70
86
  if check_until { process_stopped? }
71
87
  info "Stop #{package_full_name}: [OK] #{output}"
72
- unmonitor_process
73
88
  else
74
89
  remove_orphaned_pid_file
75
90
  update_result "Stop #{package_full_name}: [FAILED] #{output}",
@@ -94,9 +109,14 @@ module Luban
94
109
  end
95
110
 
96
111
  def kill_process
112
+ if process_stopped?
113
+ update_result "Skipped! Already stopped #{package_full_name}", status: :skipped
114
+ return
115
+ end
116
+
117
+ unmonitor_process
97
118
  output = kill_process!
98
119
  if check_until { process_stopped? }
99
- unmonitor_process
100
120
  remove_orphaned_pid_file
101
121
  update_result "Kill #{package_full_name}: [OK] #{output}"
102
122
  else
@@ -128,23 +148,29 @@ module Luban
128
148
  end
129
149
  end
130
150
 
131
- protected
151
+ def default_pending_seconds; 30; end
152
+ def default_pending_interval; 1; end
132
153
 
133
- %i(start_process! stop_process!).each do |m|
134
- define_method(m) do
135
- raise NotImplementedError, "#{self.class.name}##{__method__} is an abstract method."
136
- end
137
- end
154
+ protected
138
155
 
139
- def check_until(pending_seconds = 30)
156
+ def check_until(pending_seconds: default_pending_seconds,
157
+ pending_interval: default_pending_interval)
140
158
  succeeded = false
141
- pending_seconds.times do
142
- sleep 1
159
+ (pending_seconds/pending_interval).times do
160
+ sleep pending_interval
143
161
  break if (succeeded = yield)
144
162
  end
145
163
  succeeded
146
164
  end
147
165
 
166
+ def start_process!
167
+ capture("#{start_command} 2>&1")
168
+ end
169
+
170
+ def stop_process!
171
+ capture("#{stop_command} 2>&1")
172
+ end
173
+
148
174
  def check_process!
149
175
  if pid_file_missing?
150
176
  "#{package_full_name}: started but PID file does NOT exist - #{pid_file_path}"
@@ -174,24 +200,11 @@ module Luban
174
200
  end
175
201
 
176
202
  def monitor_process!
177
- test(process_monitor_command)
203
+ test("#{monitor_command} 2>&1")
178
204
  end
179
205
 
180
206
  def unmonitor_process!
181
- test(process_unmonitor_command)
182
- end
183
-
184
- def process_monitor_executable
185
- @process_monitor_executable ||= env_path.join("#{stage}.#{process_monitor[:env]}").
186
- join('bin').join(process_monitor[:name])
187
- end
188
-
189
- def process_monitor_command
190
- @process_monitor_command ||= "#{process_monitor_executable} monitor #{service_entry}"
191
- end
192
-
193
- def process_unmonitor_command
194
- @process_unmonitor_command ||= "#{process_monitor_executable} unmonitor #{service_entry}"
207
+ test("#{unmonitor_command} 2>&1")
195
208
  end
196
209
  end
197
210
  end
@@ -118,14 +118,21 @@ module Luban
118
118
  # capture("curl -s -L -I -o /dev/null -w '%{http_code}' #{url}") == '200'
119
119
  end
120
120
 
121
- def upload_by_template(file_to_upload:, template_file:, auto_revision: false, **opts)
121
+ def upload_by_template(file_to_upload:, template_file:,
122
+ header_file: find_template_file('header.erb'),
123
+ auto_revision: false, **opts)
124
+ content = render_template(template_file, context: binding)
125
+
126
+ revision = ''
122
127
  if auto_revision
123
128
  require 'digest/md5'
124
- revision = Digest::MD5.file(template_file).hexdigest
129
+ revision = Digest::MD5.hexdigest(content)
125
130
  return if revision_match?(file_to_upload, revision)
126
131
  end
127
132
 
128
- upload!(StringIO.new(render_template(template_file, context: binding)), file_to_upload)
133
+ header = render_template(header_file, context: binding)
134
+
135
+ upload!(StringIO.new(header + content), file_to_upload)
129
136
  yield file_to_upload if block_given?
130
137
  end
131
138
 
@@ -22,7 +22,7 @@ module Luban
22
22
  parent.install_path
23
23
  end
24
24
 
25
- default_executable 'bundler'
25
+ define_executable 'bundler'
26
26
 
27
27
  def gem_executable
28
28
  parent.gem_executable
@@ -16,7 +16,7 @@ module Luban
16
16
  end
17
17
 
18
18
  class Installer < Luban::Deployment::Package::Installer
19
- default_executable 'git'
19
+ define_executable 'git'
20
20
 
21
21
  def source_repo
22
22
  @source_repo ||= "https://www.kernel.org"
@@ -13,7 +13,7 @@ module Luban
13
13
 
14
14
  end
15
15
 
16
- default_executable 'openssl'
16
+ define_executable 'openssl'
17
17
 
18
18
  def source_repo
19
19
  @source_repo ||= "ftp://ftp.openssl.org"
@@ -74,7 +74,7 @@ module Luban
74
74
  task.opts.install_doc
75
75
  end
76
76
 
77
- default_executable 'ruby'
77
+ define_executable 'ruby'
78
78
 
79
79
  def gem_executable
80
80
  @gem_executable ||= bin_path.join('gem')
@@ -121,4 +121,4 @@ module Luban
121
121
  end
122
122
  end
123
123
  end
124
- end
124
+ end
@@ -22,7 +22,7 @@ module Luban
22
22
  parent.install_path
23
23
  end
24
24
 
25
- default_executable 'gem'
25
+ define_executable 'gem'
26
26
 
27
27
  def ruby_executable
28
28
  parent.ruby_executable
@@ -1,7 +1,4 @@
1
1
  # Luban environment activation resource file
2
- # Environment: <%= env_name %>
3
- # Revision: <%= revision %>
4
- # Created at <%= now %>
5
2
 
6
3
  echo_line() {
7
4
  if [ "$PS1" ]; then
@@ -0,0 +1,4 @@
1
+ # Environment: <%= env_name %>
2
+ # Revision: <%= revision %>
3
+ # Created at <%= now %>
4
+
@@ -1,7 +1,4 @@
1
1
  # Environment de-activation resource file
2
- # Environment: <%= env_name %>
3
- # Revision: <%= revision %>
4
- # Created at <%= now %>
5
2
 
6
3
  echo_line() {
7
4
  if [ "$PS1" ]; then
@@ -1,5 +1,5 @@
1
1
  module Luban
2
2
  module Deployment
3
- VERSION = "0.4.2"
3
+ VERSION = "0.4.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luban
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rubyist Lei
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-07 00:00:00.000000000 Z
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: luban-cli
@@ -144,6 +144,7 @@ files:
144
144
  - lib/luban/deployment/parameters.rb
145
145
  - lib/luban/deployment/runner.rb
146
146
  - lib/luban/deployment/templates/envrc.erb
147
+ - lib/luban/deployment/templates/header.erb
147
148
  - lib/luban/deployment/templates/unset_envrc.erb
148
149
  - lib/luban/deployment/version.rb
149
150
  - lib/luban/deployment/worker.rb