bluepill 0.0.26 → 0.0.27

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.26
1
+ 0.0.27
data/bin/bluepill CHANGED
@@ -36,10 +36,10 @@ OptionParser.new do |opts|
36
36
  puts "Commands:"
37
37
  puts " load CONFIG_FILE\t\tLoads new instance of bluepill using the specified config file"
38
38
  puts " status\t\t\tLists the status of the proceses for the specified app"
39
- puts " start TARGET\t\tIssues the start command for the target process or group"
40
- puts " stop TARGET\t\t\tIssues the stop command for the target process or group"
41
- puts " restart TARGET\t\tIssues the restart command for the target process or group"
42
- puts " unmonitor TARGET\t\tStop monitoring target process or group"
39
+ puts " start [TARGET]\t\tIssues the start command for the target process or group, defaults to all processes"
40
+ puts " stop [TARGET]\t\tIssues the stop command for the target process or group, defaults to all processes"
41
+ puts " restart [TARGET]\t\tIssues the restart command for the target process or group, defaults to all processes"
42
+ puts " unmonitor [TARGET]\t\tStop monitoring target process or group, defaults to all processes"
43
43
  puts " log [TARGET]\t\tShow the log for the specified process or group, defaults to all for app"
44
44
  puts " quit\t\t\tStop bluepill"
45
45
  puts
data/bluepill.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bluepill}
8
- s.version = "0.0.26"
8
+ s.version = "0.0.27"
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"]
12
- s.date = %q{2009-12-02}
12
+ s.date = %q{2009-12-05}
13
13
  s.default_executable = %q{bluepill}
14
14
  s.description = %q{Bluepill keeps your daemons up while taking up as little resources as possible. After all you probably want the resources of your server to be used by whatever daemons you are running rather than the thing that's supposed to make sure they are brought back up, should they die or misbehave.}
15
15
  s.email = %q{entombedvirus@gmail.com}
@@ -78,7 +78,7 @@ module Bluepill
78
78
 
79
79
  PROCESS_COMMANDS.each do |command|
80
80
  class_eval <<-END
81
- def #{command}(group_name, process_name = nil)
81
+ def #{command}(group_name = nil, process_name = nil)
82
82
  self.send_to_process_or_group(:#{command}, group_name, process_name)
83
83
  end
84
84
  END
@@ -90,10 +90,18 @@ module Bluepill
90
90
  self.groups[group_name] ||= Group.new(group_name, :logger => self.logger.prefix_with(group_name))
91
91
  self.groups[group_name].add_process(process)
92
92
  end
93
+
94
+ def version
95
+ Bluepill::VERSION
96
+ end
93
97
 
94
98
  protected
95
99
  def send_to_process_or_group(method, group_name, process_name)
96
- if self.groups.key?(group_name)
100
+ if group_name.nil? && process_name.nil?
101
+ self.groups.values.collect do |group|
102
+ group.send(method)
103
+ end.flatten
104
+ elsif self.groups.key?(group_name)
97
105
  self.groups[group_name].send(method, process_name)
98
106
  elsif process_name.nil?
99
107
  # they must be targeting just by process name
@@ -109,17 +117,18 @@ module Bluepill
109
117
  def start_listener
110
118
  @listener_thread.kill if @listener_thread
111
119
  @listener_thread = Thread.new do
112
- begin
113
- loop do
120
+ loop do
121
+ begin
114
122
  client = self.socket.accept
115
123
  command, *args = client.readline.strip.split(":")
116
124
  response = self.send(command, *args)
117
125
  client.write(Marshal.dump(response))
126
+ rescue StandardError => e
127
+ logger.err("Got exception in cmd listener: %s `%s`" % [e.class.name, e.message])
128
+ e.backtrace.each {|l| logger.err(l)}
129
+ ensure
118
130
  client.close
119
131
  end
120
- rescue StandardError => e
121
- logger.err("Got exception in cmd listener: %s `%s`" % [e.class.name, e.message])
122
- e.backtrace.each {|l| logger.err(l)}
123
132
  end
124
133
  end
125
134
  end
@@ -21,10 +21,6 @@ module Bluepill
21
21
  def handle_command(application, command, *args)
22
22
  case command.to_sym
23
23
  when *Application::PROCESS_COMMANDS
24
- if args.compact.empty?
25
- $stderr.puts "You must specify a target process or group for the #{command} command."
26
- exit(8)
27
- end
28
24
  # these need to be sent to the daemon and the results printed out
29
25
  affected = self.send_to_daemon(application, command, *args)
30
26
  if affected.empty?
@@ -61,9 +57,9 @@ module Bluepill
61
57
  end
62
58
 
63
59
  def send_to_daemon(application, command, *args)
64
-
65
60
  begin
66
61
  Timeout::timeout(Socket::TIMEOUT) do
62
+ verify_version!(application)
67
63
  buffer = ""
68
64
  socket = Socket.client(base_dir, application) # Something that should be interrupted if it takes too much time...
69
65
  socket.puts(([command] + args).join(":"))
@@ -107,5 +103,22 @@ module Bluepill
107
103
  FileUtils.mkdir_p(dir) unless File.exists?(dir)
108
104
  end
109
105
  end
106
+
107
+ def verify_version!(application)
108
+ begin
109
+ socket = Socket.client(self.base_dir, application)
110
+ socket.puts("version")
111
+ buffer = ""
112
+ while line = socket.gets
113
+ buffer << line
114
+ end
115
+ version = Marshal.load(buffer)
116
+ if version != Bluepill::VERSION
117
+ abort("The running version of your daemon seems to be out of date.\nDaemon Version: #{version}, CLI Version: #{Bluepill::VERSION}")
118
+ end
119
+ rescue ArgumentError
120
+ abort("The running version of your daemon seems to be out of date.")
121
+ end
122
+ end
110
123
  end
111
124
  end
@@ -1,3 +1,3 @@
1
1
  module Bluepill
2
- VERSION = "0.0.26"
2
+ VERSION = "0.0.27"
3
3
  end
data/lib/example.rb CHANGED
@@ -1,18 +1,12 @@
1
- module Bluepill
2
- module ProcessConditions
3
- class ProcMemUsage < MemUsage
4
- def run(pid)
5
- rand(1000)
6
- end
7
- end
8
- end
9
- end
1
+ require 'rubygems'
2
+ require 'bluepill'
3
+ require 'logger'
10
4
 
11
5
  ROOT_DIR = "/tmp/bp"
12
6
 
13
7
  # Watch with
14
8
  # watch -n0.2 'ps axu | egrep "(CPU|forking|bluepill|sleep)" | grep -v grep | sort'
15
- Bluepill.application(:sample_app, :log_file => "/Users/arya/Desktop/bp.log") do |app|
9
+ Bluepill.application(:sample_app) do |app|
16
10
  0.times do |i|
17
11
  app.process("process_#{i}") do |process|
18
12
  process.pid_file = "#{ROOT_DIR}/pids/process_#{i}.pid"
@@ -67,7 +61,7 @@ Bluepill.application(:sample_app, :log_file => "/Users/arya/Desktop/bp.log") do
67
61
  end
68
62
  end
69
63
 
70
- 2.times do |i|
64
+ 1.times do |i|
71
65
  app.process("group_process_#{i}") do |process|
72
66
  process.uid = "arya"
73
67
  process.gid = "wheel"
@@ -77,26 +71,11 @@ Bluepill.application(:sample_app, :log_file => "/Users/arya/Desktop/bp.log") do
77
71
 
78
72
 
79
73
  process.group = "grouped"
80
- process.start_command = %Q{ruby -e '$stderr.puts("hello stderr");$stdout.puts("hello stdout"); $stdout.flush; $stderr.flush; sleep 10'}
74
+ process.start_command = %Q{cd /tmp && ruby -e '$stderr.puts("hello stderr");$stdout.puts("hello stdout"); $stdout.flush; $stderr.flush; sleep 10'}
81
75
  process.daemonize = true
82
- # process.pid_file = "/tmp/p_#{process.group}#{i}_.pid"
76
+ process.pid_file = "/tmp/p_#{process.group}_#{i}.pid"
83
77
 
84
78
  # process.checks :always_true, :every => 5
85
- process.checks :cpu_usage,
86
- :every => 10,
87
- :below => 0.5,
88
- :times => [5, 5]
89
-
90
- process.checks :mem_usage,
91
- :every => 3,
92
- :below => 600.megabytes,
93
- :times => [3, 5],
94
- :fires => [:stop]
95
-
96
- process.checks :proc_mem_usage,
97
- :every => 3,
98
- :below => 600.megabytes,
99
- :times => [3, 5]
100
79
  end
101
80
  end
102
81
  end
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.26
4
+ version: 0.0.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arya Asemanfar
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-12-02 00:00:00 -08:00
14
+ date: 2009-12-05 00:00:00 -08:00
15
15
  default_executable: bluepill
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency