From 6ee8b4e7a9731f969347e317456e8d9712fe2641 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 13 Apr 2005 15:24:36 +0000 Subject: reorganizing git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@96 980ebf18-57e1-0310-9a29-db15c13687c0 --- lib/blink/objects/process.rb | 86 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 lib/blink/objects/process.rb (limited to 'lib/blink/objects/process.rb') 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 -- cgit