bluepill 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -120,6 +120,31 @@ And lastly, to monitor child processes:
120
120
 
121
121
  Note {{PID}} will be substituted for the pid of process in both the stop and restart commands.
122
122
 
123
+ ### A Note About Output Redirection
124
+
125
+ While you can specify shell tricks like the following in the start_command of a process:
126
+
127
+ Bluepill.application("app_name") do |app|
128
+ app.process("process_name") do |process|
129
+ process.start_command = "cd /tmp/some_dir && SOME_VAR=1 /usr/bin/some_start_command > /tmp/server.log 2>&1"
130
+ process.pid_file = "/tmp/some_pid_file.pid"
131
+ end
132
+ end
133
+
134
+ We recommend that you not do that and instead use the DSL to capture output from your daemons. Like so:
135
+
136
+ Bluepill.application("app_name") do |app|
137
+ app.process("process_name") do |process|
138
+ process.start_command = "/usr/bin/env SOME_VAR=1 /usr/bin/some_start_command"
139
+
140
+ process.working_dir = "/tmp/some_dir"
141
+ process.stdout = process.stderr = "/tmp/server.log"
142
+
143
+ process.pid_file = "/tmp/some_pid_file.pid"
144
+ end
145
+ end
146
+
147
+
123
148
  ### CLI
124
149
  To start a bluepill process and load a config:
125
150
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.20
1
+ 0.0.21
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.20"
8
+ s.version = "0.0.21"
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-11-15}
12
+ s.date = %q{2009-11-16}
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}
@@ -8,6 +8,10 @@ module Bluepill
8
8
  :stop_command,
9
9
  :restart_command,
10
10
 
11
+ :stdout,
12
+ :stderr,
13
+ :stdin,
14
+
11
15
  :daemonize,
12
16
  :pid_file,
13
17
  :working_dir,
@@ -385,7 +389,10 @@ module Bluepill
385
389
  :gid => self.gid,
386
390
  :working_dir => self.working_dir,
387
391
  :pid_file => self.pid_file,
388
- :logger => self.logger
392
+ :logger => self.logger,
393
+ :stdin => self.stdin,
394
+ :stdout => self.stdout,
395
+ :stderr => self.stderr
389
396
  }
390
397
  end
391
398
 
@@ -68,25 +68,14 @@ module Bluepill
68
68
  # Setting end PWD env emulates bash behavior when dealing with symlinks
69
69
  Dir.chdir(ENV["PWD"] = options[:working_dir]) if options[:working_dir]
70
70
 
71
- # Forcing execution through bash to make output redirection and shell exapansion in commands work and still have
72
- # bluepill monitor the correct process
73
- args = ["/bin/sh", "-c", "--", cmd]
71
+ redirect_io(*options.values_at(:stdin, :stdout, :stderr))
74
72
 
75
- ::Kernel.exec(*args)
73
+ ::Kernel.exec(cmd)
76
74
  exit
77
75
  end
78
76
 
79
77
  daemon_id = Daemonize.call_as_daemon(to_daemonize, nil, cmd)
80
-
81
- # Kludge. In order to make bluepill monitor the correct process while given start_commands of the form
82
- # "cd /some/dir && ./some/server > /tmp/server.log 2>&1"
83
- # we inspect the children of the "sh -c" process and pick it's single child.
84
- # There are many cases where this could break. If Bluepill is not monitoring the correct process, try
85
- # simplyfying the start_command by moving all the bash scripting to a separate file and specifying that
86
- # as the start_command. That said, this should work for 99% use cases.
87
- spawned_children = get_children(daemon_id)
88
- daemon_id = spawned_children.first if spawned_children.length == 1
89
-
78
+
90
79
  File.open(options[:pid_file], "w") {|f| f.write(daemon_id)}
91
80
 
92
81
  wr.write daemon_id
@@ -218,5 +207,18 @@ module Bluepill
218
207
  e.backtrace.each {|l| logger.warning l}
219
208
  return false
220
209
  end
210
+
211
+ def redirect_io(io_in, io_out, io_err)
212
+ $stdin.reopen(streams[io_in]) if io_in
213
+
214
+ if !io_out.nil? && !io_err.nil? && io_out == io_err
215
+ $stdout.reopen(io_out)
216
+ $stderr.reopen($stdout)
217
+
218
+ else
219
+ $stdout.reopen(io_out) if io_out
220
+ $stderr.reopen(io_err) if io_err
221
+ end
222
+ end
221
223
  end
222
224
  end
data/lib/example.rb CHANGED
@@ -65,10 +65,14 @@ Bluepill.application(:sample_app) do |app|
65
65
  app.process("group_process_#{i}") do |process|
66
66
  process.uid = "rohith"
67
67
  process.gid = "wheel"
68
+
69
+ process.stderr = "/tmp/err.log"
70
+ process.stdout = "/tmp/err.log"
71
+
68
72
 
69
73
  process.group = "grouped"
70
- process.start_command = %Q{cd /tmp && ruby -e '$stderr.puts("hello stderr");$stdout.puts("hello stdout"); sleep 10' 1>> /tmp/err.log 2>&1 }
71
- process.daemonize = false
74
+ process.start_command = %Q{cd /tmp && ruby -e '$stderr.puts("hello stderr");$stdout.puts("hello stdout"); $stdout.flush; $stderr.flush; sleep 10'}
75
+ process.daemonize = true
72
76
  process.pid_file = "/tmp/noperm/p_#{process.group}_#{i}.pid"
73
77
 
74
78
  # process.checks :always_true, :every => 5
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.20
4
+ version: 0.0.21
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-11-15 00:00:00 -08:00
14
+ date: 2009-11-16 00:00:00 -08:00
15
15
  default_executable: bluepill
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency