summaryrefslogtreecommitdiffstats
path: root/lib/blink/objects/process.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-04-13 15:24:36 +0000
committerLuke Kanies <luke@madstop.com>2005-04-13 15:24:36 +0000
commit6ee8b4e7a9731f969347e317456e8d9712fe2641 (patch)
tree0e2aa758bb523b4a2f1c752a625bd2d95462edf4 /lib/blink/objects/process.rb
parent5416017c05e44fc635ad14ffdf1ac1163a4cc6e5 (diff)
reorganizing
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@96 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/blink/objects/process.rb')
-rwxr-xr-xlib/blink/objects/process.rb86
1 files changed, 86 insertions, 0 deletions
diff --git a/lib/blink/objects/process.rb b/lib/blink/objects/process.rb
new file mode 100755
index 000000000..182667d7c
--- /dev/null
+++ b/lib/blink/objects/process.rb
@@ -0,0 +1,86 @@
+#!/usr/local/bin/ruby -w
+
+require 'blink/operation'
+require 'blink/operation/processes'
+
+# DISABLED
+# I'm only working on services, not processes, right now
+
+module Blink
+ class Objects
+ class BProcess < Objects
+ attr_reader :stat, :path
+ @params = [:start, :stop, :user, :pattern, :binary, :arguments] # class instance variable
+
+ @objects = Hash.new
+ @namevar = :pattern
+
+ Blink::Relation.new(self, Blink::Operation::Start, {
+ :user => :user,
+ :pattern => :pattern,
+ :binary => :binary,
+ :arguments => :arguments
+ })
+
+ Blink::Relation.new(self, Blink::Operation::Stop, {
+ :user => :user,
+ :pattern => :pattern
+ })
+
+ end # Blink::Objects::BProcess
+ end # Blink::Objects
+
+ class Attribute
+ class ProcessRunning < Attribute
+ def retrieve
+ running = 0
+ regex = Regexp.new(@params[:pattern])
+ begin
+ # this ps is only tested on Solaris
+ # XXX yeah, this definitely needs to be fixed...
+ %x{ps -ef -U #{@params[:user]}}.split("\n").each { |process|
+ if regex.match(process)
+ running += 1
+ end
+ }
+ rescue
+ # this isn't correct, but what the hell
+ Blink::Message.new(
+ :level => :error,
+ :source => self.object,
+ :message => "Failed to run ps"
+ )
+ end
+
+ self.state = running
+ Blink.debug "there are #{running} #{self.object} processes for start"
+ end
+
+ def <=>(other)
+ self.state < 1
+ end
+
+ def fix
+ require 'etc'
+ # ruby is really cool
+ uid = 0
+ if @params[:user].is_a? Integer
+ uid = @params[:user]
+ else
+ uid = Etc.getpwnam(@params[:user]).uid
+ end
+ Kernel.fork {
+ Process.uid = uid
+ Process.euid = uid
+ string = @params[:binary] + (@params[:arguments] || "")
+ Blink::Message.new(
+ :level => :notice,
+ :source => self.object,
+ :message => "starting"
+ )
+ Kernel.exec(string)
+ }
+ end
+ end
+ end
+end