bluepill 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.14
1
+ 0.0.15
data/bin/bluepill CHANGED
@@ -62,5 +62,5 @@ when *ALLOWED_COMMANDS
62
62
  puts controller.send_cmd(options[:application], options[:command], process_or_group_name)
63
63
 
64
64
  else
65
- puts "Unknown command `%s`" % options[:command]
65
+ puts "Unknown command `%s` (or application `%s` has not been loaded yet)" % [options[:command], options[:command]]
66
66
  end
data/bluepill.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bluepill}
8
- s.version = "0.0.14"
8
+ s.version = "0.0.15"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Arya Asemanfar", "Gary Tsang", "Rohith Ravi"]
@@ -32,7 +32,6 @@ Gem::Specification.new do |s|
32
32
  "lib/bluepill/application.rb",
33
33
  "lib/bluepill/application/client.rb",
34
34
  "lib/bluepill/application/server.rb",
35
- "lib/bluepill/comm.rb",
36
35
  "lib/bluepill/condition_watch.rb",
37
36
  "lib/bluepill/controller.rb",
38
37
  "lib/bluepill/dsl.rb",
@@ -1,18 +1,19 @@
1
1
  module Bluepill
2
2
  class Application
3
3
  attr_accessor :name, :logger, :base_dir, :socket, :pid_file
4
- attr_accessor :groups, :work_queue
4
+ attr_accessor :groups, :work_queue, :socket_timeout
5
5
 
6
6
  def initialize(name, options = {})
7
7
  self.name = name
8
8
  self.base_dir = options[:base_dir] ||= '/var/bluepill'
9
+ self.socket_timeout = options[:socket_timeout] ||= 10
9
10
 
10
11
  self.logger = Bluepill::Logger.new.prefix_with(self.name)
11
12
 
12
13
  self.groups = Hash.new
13
14
 
14
15
  self.pid_file = File.join(self.base_dir, 'pids', self.name + ".pid")
15
-
16
+
16
17
  @server = false
17
18
  end
18
19
 
@@ -123,11 +124,19 @@ module Bluepill
123
124
  end
124
125
 
125
126
  def send_to_server(method)
126
- self.socket = Bluepill::Socket.new(name, base_dir).client
127
- socket.write(method + "\n")
128
- buffer = ""
129
- while(line = socket.gets)
130
- buffer << line
127
+ begin
128
+ status = Timeout::timeout(self.socket_timeout) do
129
+ self.socket = Bluepill::Socket.new(name, base_dir).client # Something that should be interrupted if it takes too much time...
130
+ socket.write(method + "\n")
131
+ buffer = ""
132
+ while(line = socket.gets)
133
+ buffer << line
134
+ end
135
+ end
136
+ rescue Timeout::Error
137
+ abort("Socket Timeout: Server may not be responding")
138
+ rescue Errno::ECONNREFUSED
139
+ abort("Connection Refused: Server is not running")
131
140
  end
132
141
  return buffer
133
142
  end
@@ -138,13 +147,9 @@ private
138
147
  Thread.new(self) do |app|
139
148
  begin
140
149
  loop do
141
- # logger.info("Server | Command loop started:")
142
150
  client = socket.accept
143
- # logger.info("Server: Handling Request")
144
151
  cmd = client.readline.strip
145
- # logger.info("Server: #{cmd}")
146
152
  response = app.send(*cmd.split(":"))
147
- # logger.info("Server: Sending Response")
148
153
  client.write(response)
149
154
  client.close
150
155
  end
@@ -159,15 +164,12 @@ private
159
164
  Thread.new(self) do |app|
160
165
  loop do
161
166
  begin
162
- # app.logger.info("Server | worker loop started:")
163
167
  job = app.work_queue.pop
164
168
  send_to_process_or_group(job[0], job[1], false)
165
-
166
169
  rescue StandardError => e
167
170
  logger.err("Error while trying to execute %s from work_queue" % job.inspect)
168
171
  logger.err("%s: `%s`" % [e.class.name, e.message])
169
172
  end
170
- # app.logger.info("Server | worker job processed:")
171
173
  end
172
174
  end
173
175
  end
@@ -181,7 +183,6 @@ private
181
183
  ::Process.kill(2, previous_pid)
182
184
  rescue Exception => e
183
185
  exit unless e.is_a?(Errno::ESRCH)
184
- # it was probably already dead
185
186
  else
186
187
  sleep 1 # wait for it to die
187
188
  end
data/lib/bluepill.rb CHANGED
@@ -3,6 +3,7 @@ require 'rubygems'
3
3
  require 'thread'
4
4
  require 'monitor'
5
5
  require 'syslog'
6
+ require 'timeout'
6
7
 
7
8
  require 'active_support/inflector'
8
9
  require 'active_support/core_ext/hash'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bluepill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arya Asemanfar
@@ -87,7 +87,6 @@ files:
87
87
  - lib/bluepill/application.rb
88
88
  - lib/bluepill/application/client.rb
89
89
  - lib/bluepill/application/server.rb
90
- - lib/bluepill/comm.rb
91
90
  - lib/bluepill/condition_watch.rb
92
91
  - lib/bluepill/controller.rb
93
92
  - lib/bluepill/dsl.rb
data/lib/bluepill/comm.rb DELETED
@@ -1,5 +0,0 @@
1
- module Bluepill
2
- class Comm
3
-
4
- end
5
- end