procodile 1.0.0 → 1.0.1

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: b644b27235abc8fcae9bfd9d7ca9bbd87cd1c0d8
4
- data.tar.gz: 82428a6110171a2b783f0a249b8bf6661e02c6e4
3
+ metadata.gz: af875e102a349ee27e1ae2e73f91b4f49c7e6c04
4
+ data.tar.gz: 478f4a32e80be0176df34a1365dd27713aa6a417
5
5
  SHA512:
6
- metadata.gz: b4cbe1b3445fbb4fab8afd3cab8e1a90aa03b0e4c24de0daddd9823cdc756831ee096647d5a424e363e36808fb43709c73d5be763b09de5d6f805d7869275e26
7
- data.tar.gz: 6363da66bd85396ffbd5bde9ad4ff64464535fd73f1f5b9c29b1a3d32b42ed4d2bf2f0343743d005438db85c730081c0a2827a9b5cc8a216ab9dd5d57a4880a6
6
+ metadata.gz: 609190d1c60c6eac36ffc008d9f8c12fe61164a1820db57e70b60de520e7e10cbb0a730799677227f47f2ecfaafba601a9f360131b327e04491c0ab4130ca3b7
7
+ data.tar.gz: 2d11514410c07c3f0bc59ccc79a0547692b4914bd189d030fa54ef0296b2d73b4298702440087af4d5431169154c0b8e6e3b0cc500310fabbd39549ce4a146f9
data/lib/procodile/cli.rb CHANGED
@@ -122,12 +122,22 @@ module Procodile
122
122
  puts "||".color(process['log_color']) + " Command " + process['command']
123
123
  puts "||".color(process['log_color']) + " Respawning " + "#{process['max_respawns']} every #{process['respawn_window']} seconds"
124
124
  puts "||".color(process['log_color']) + " Restart mode " + process['restart_mode']
125
- stats['instances'][process['name']].each do |instance|
126
- print "|| ".color(process['log_color']) + instance['description'].to_s.ljust(20, ' ').color(process['log_color'])
127
- print "pid " + instance['pid'].to_s.ljust(12, ' ')
128
- print (instance['running'] ? 'Running' : 'Stopped').to_s.ljust(15, ' ')
129
- print instance['respawns'].to_s + " respawns"
130
- puts
125
+ puts "||".color(process['log_color']) + " Log path " + (process['log_path'] || "none specified")
126
+ instances = stats['instances'][process['name']]
127
+ if instances.empty?
128
+ puts "||".color(process['log_color']) + " No processes running."
129
+ else
130
+ instances.each do |instance|
131
+ print "|| ".color(process['log_color']) + instance['description'].to_s.ljust(20, ' ').color(process['log_color'])
132
+ if instance['running']
133
+ print ' Running '.color("42;37")
134
+ else
135
+ print ' Stopped '.color("41;37")
136
+ end
137
+ print " pid " + instance['pid'].to_s.ljust(12, ' ')
138
+ print instance['respawns'].to_s + " respawns"
139
+ puts
140
+ end
131
141
  end
132
142
  end
133
143
  else
@@ -24,15 +24,19 @@ module Procodile
24
24
 
25
25
  def run(command, options = {})
26
26
  @socket.puts("#{command} #{options.to_json}")
27
- code, reply = @socket.gets.strip.split(/\s+/, 2)
28
- if code.to_i == 200
29
- if reply && reply.length > 0
30
- JSON.parse(reply)
27
+ if data = @socket.gets
28
+ code, reply = data.strip.split(/\s+/, 2)
29
+ if code.to_i == 200
30
+ if reply && reply.length > 0
31
+ JSON.parse(reply)
32
+ else
33
+ true
34
+ end
31
35
  else
32
- true
36
+ raise Error, "Error from control server: #{code} (#{reply.inspect})"
33
37
  end
34
38
  else
35
- raise Error, "Error from control server: #{code} (#{reply.inspect})"
39
+ raise Error ,"Control server disconnected."
36
40
  end
37
41
  end
38
42
 
@@ -108,8 +108,8 @@ module Procodile
108
108
  @stopping = true
109
109
  update_pid
110
110
  if self.running?
111
- Procodile.log(@process.log_color, description, "Sending TERM to #{@pid}")
112
- ::Process.kill('TERM', pid)
111
+ Procodile.log(@process.log_color, description, "Sending #{@process.term_signal} to #{@pid}")
112
+ ::Process.kill(@process.term_signal, pid)
113
113
  else
114
114
  Procodile.log(@process.log_color, description, "Process already stopped")
115
115
  end
@@ -151,8 +151,8 @@ module Procodile
151
151
  when 'start-term'
152
152
  old_process_pid = @pid
153
153
  start
154
- Procodile.log(@process.log_color, description, "Sent TERM signal to old PID #{old_process_pid} (forgetting now)")
155
- ::Process.kill('TERM', old_process_pid)
154
+ Procodile.log(@process.log_color, description, "Sent #{@process.term_signal} signal to old PID #{old_process_pid} (forgetting now)")
155
+ ::Process.kill(@process.term_signal, old_process_pid)
156
156
  when 'term-start'
157
157
  stop
158
158
  Thread.new do
@@ -202,7 +202,7 @@ module Procodile
202
202
  add_respawn
203
203
  elsif respawns >= @process.max_respawns
204
204
  Procodile.log(@process.log_color, description, "\e[41;37mWarning:\e[0m\e[31m this process has been respawned #{respawns} times and keeps dying.\e[0m")
205
- Procodile.log(@process.log_color, description, "It will not be respawned automatically any longer and will no longer be managed.").color(31)
205
+ Procodile.log(@process.log_color, description, "It will not be respawned automatically any longer and will no longer be managed.".color(31))
206
206
  tidy
207
207
  unmonitor
208
208
  end
@@ -46,6 +46,13 @@ module Procodile
46
46
  @options['log_path'] ? File.expand_path(@options['log_path'], @config.root) : nil
47
47
  end
48
48
 
49
+ #
50
+ # Return the signal to send to terminate the process
51
+ #
52
+ def term_signal
53
+ @options['term_signal'] || 'TERM'
54
+ end
55
+
49
56
  #
50
57
  # Defines how this process should be restarted
51
58
  #
@@ -37,7 +37,7 @@ module Procodile
37
37
  Array.new.tap do |instances_started|
38
38
  @config.processes.each do |name, process|
39
39
  next if types && !types.include?(name.to_s) # Not a process we want
40
- next if @processes.keys.include?(process) # Process type already running
40
+ next if @processes[process] && !@processes[process].empty? # Process type already running
41
41
  instances = start_instances(process.generate_instances)
42
42
  instances_started.push(*instances)
43
43
  end
@@ -117,7 +117,7 @@ module Procodile
117
117
  end
118
118
 
119
119
  # If the processes go away, we can stop the supervisor now
120
- if @processes.size == 0
120
+ if @processes.all? { |_,instances| instances.size == 0 }
121
121
  Procodile.log nil, "system", "All processes have stopped"
122
122
  stop_supervisor
123
123
  end
@@ -185,7 +185,7 @@ module Procodile
185
185
  def remove_unmonitored_instances
186
186
  @processes.each do |_, instances|
187
187
  instances.reject!(&:unmonitored?)
188
- end.reject! { |_, instances| instances.empty? }
188
+ end
189
189
  end
190
190
 
191
191
  def remove_stopped_instances
@@ -198,7 +198,7 @@ module Procodile
198
198
  false
199
199
  end
200
200
  end
201
- end.reject! { |_, instances| instances.empty? }
201
+ end
202
202
  end
203
203
 
204
204
  def process_names_to_instances(names)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: procodile
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke