process_controller 0.2.5 → 0.2.6

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: 17c0fdaba921a31141fc660a1999ad02bca254c4
4
- data.tar.gz: 52ce088b4ae7143835788a5b4e30a922725701ba
3
+ metadata.gz: 03944c105460bf09eebb44beb003ca715e647b3a
4
+ data.tar.gz: 4c8435e788c94c2a8600b981a90a1d8204d58ab3
5
5
  SHA512:
6
- metadata.gz: cb40d357cd17f1c49dee43deabdefa563dee4ee0551da9be2a227bccc64eec34ec7d1d3a4f8db8933b5c10984718a814a8d66eae86cb39b4f0a3a574946140e9
7
- data.tar.gz: df426ecc2d5b4dfe55954edbf1f927ea49949e4b2e53722f778189b5d84dafbecef5186e90304e6341804c4ac7466405dd9907a3229e22f7a170b00c5a51330b
6
+ metadata.gz: 0be8d8349b415d9afc46d5a658f53a24f9029c8506ed79f40bbbbe8178e53655aaeecdc575e06594e9bc35d5098ba0fd4e8b969135198ff991f5aa5dc1ef740a
7
+ data.tar.gz: 3d8d22ffa58538c57a0236d3983739373c04d41ae9949a5b80017ab48514086a35569bb63a809b8dbc24e59063471f86c8f9073abe8cd692f355b7d98f68e950
@@ -1,3 +1,3 @@
1
1
  module Control
2
- VERSION = '0.2.5'
2
+ VERSION = '0.2.6'
3
3
  end
@@ -7,12 +7,12 @@ module ControlHelper
7
7
  if pid_filename
8
8
  get_pid_from_file(pid_filename)
9
9
  else
10
- search_by_string = retreive_search_string(options)
10
+ search_by_string = retrieve_search_string(options)
11
11
  find_pid_with_ps(search_by_string)
12
12
  end
13
13
  end
14
14
 
15
- def retreive_search_string(options)
15
+ def retrieve_search_string(options)
16
16
  attributes = Control_P::OPTIONS_ATTRIBUTES
17
17
  find_by = options.fetch(attributes[:find_pid_by], Control_P::FIND_BY_OPTIONS[:app_filename])
18
18
  #TODO validate find_by is in Control_P::FIND_BY_OPTIONS
@@ -31,8 +31,8 @@ module ControlHelper
31
31
 
32
32
 
33
33
  def find_pid_with_ps(search_by_string)
34
- pid = nil
35
34
  search_string = "ps aux | grep #{search_by_string} | grep -v grep"
35
+ pid = nil
36
36
  p "searching by #{search_string}"
37
37
  procs = `#{search_string}` # todo add grep
38
38
 
@@ -48,6 +48,16 @@ module ControlHelper
48
48
  pid
49
49
  end
50
50
 
51
+
52
+ def is_pid_alive?(process_id)
53
+ search_string = "ps -p #{process_id} -o comm="
54
+ p "searching by #{search_string}"
55
+ procs = `#{search_string}` # todo add grep
56
+ p "found procs #{procs}"
57
+
58
+ procs == ''
59
+ end
60
+
51
61
  def exit_if_not_running!(options)
52
62
  old_pid = find_app_pid(options)
53
63
  unless app_running?(old_pid)
@@ -127,14 +137,15 @@ module ControlHelper
127
137
  end
128
138
 
129
139
  def make_sure_pid_is_real!(pid, pid_filename)
130
- find_pid = find_pid_with_ps(pid)
131
- if find_pid.nil?
140
+ # TODO - fix this . don't validate by name but by pid (ps -p 'pid' -o comm=)
141
+ # http://superuser.com/questions/632979/if-i-know-the-pid-number-of-a-process-how-can-i-get-its-name
142
+ if is_pid_alive?(pid)
143
+ pid
144
+ else
132
145
  p "didn't really find pid running, deleting the file #{pid_filename}"
133
146
  delete_file(pid_filename)
134
- return nil
147
+ nil
135
148
  end
136
-
137
- find_pid
138
149
  end
139
150
 
140
151
  def delete_file(file_name)
@@ -168,7 +179,7 @@ module ControlHelper
168
179
  if pid
169
180
  p "#{prefix} Ok, Restarted. new pid #{pid}"
170
181
  if http_server?(options) && !skip_workers_message?(options)
171
- if Dir[Control_P::WORKERS_STARTED_EXTENTION].length < 1
182
+ if Dir[Control_P::WORKERS_STARTED_EXTENSION].length < 1
172
183
  p 'no workers has seemed to be started, check it out.'
173
184
  exit(1)
174
185
  end
@@ -183,17 +194,17 @@ module ControlHelper
183
194
 
184
195
  #TODO add option to overwrite the file names
185
196
  def print_workers_started_and_stopped(options)
186
- print_workers_and_delete_files!('workers started', Control_P::WORKERS_STARTED_EXTENTION)
187
- print_workers_and_delete_files!('workers closed', Control_P::WORKERS_CLOSED_EXTENTION)
197
+ print_workers_and_delete_files!('workers started', Control_P::WORKERS_STARTED_EXTENSION)
198
+ print_workers_and_delete_files!('workers closed', Control_P::WORKERS_CLOSED_EXTENSION)
188
199
  end
189
200
 
190
201
  def skip_workers_message?(options)
191
202
  options.fetch(Control_P::OPTIONS_ATTRIBUTES[:skip_workers_message], false)
192
203
  end
193
204
 
194
- def print_workers_and_delete_files!(type, extention)
195
- p "#{Dir[extention].length.to_s} #{type}"
196
- Dir.glob(extention).each { |f| File.delete(f) }
205
+ def print_workers_and_delete_files!(type, extension)
206
+ p "#{Dir[extension].length.to_s} #{type}"
207
+ Dir.glob(extension).each { |f| File.delete(f) }
197
208
  end
198
209
 
199
210
  def http_server?(options)
@@ -10,8 +10,8 @@ class Control_P
10
10
  start_command: 'start_command', skip_workers_message: 'skip_workers_message'}.with_indifferent_access
11
11
 
12
12
  FIND_BY_OPTIONS = {app_filename: 'app_filename', port_num: 'port_num', app_name: 'app_name', pid_file: 'pid_file'}.with_indifferent_access
13
- WORKERS_STARTED_EXTENTION = '*.started'
14
- WORKERS_CLOSED_EXTENTION = '*.closed'
13
+ WORKERS_STARTED_EXTENSION = '*.started'
14
+ WORKERS_CLOSED_EXTENSION = '*.closed'
15
15
 
16
16
  HOSTNAME = Socket.gethostname
17
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: process_controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ohad partuck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-02 00:00:00.000000000 Z
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport