Class: PhusionPassenger::AdminTools::ControlProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/phusion_passenger/admin_tools/control_process.rb

Defined Under Namespace

Classes: Instance

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ControlProcess

Returns a new instance of ControlProcess.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/phusion_passenger/admin_tools/control_process.rb', line 64

def initialize(path)
	@path = path
	if File.exist?("#{path}/control_process.pid")
		data = File.read("#{path}/control_process.pid").strip
		if data.empty?
			raise ArgumentError, "'#{path}' is not a valid control process directory."
		else
			@pid = data.to_i
		end
	else
		path =~ /passenger.(\d+)\Z/
		@pid = $1.to_i
	end
	if !AdminTools.process_is_alive?(@pid)
		raise ArgumentError, "There is no control process with PID #{@pid}."
	end
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



39
40
41
# File 'lib/phusion_passenger/admin_tools/control_process.rb', line 39

def path
  @path
end

#pidObject

Returns the value of attribute pid.



40
41
42
# File 'lib/phusion_passenger/admin_tools/control_process.rb', line 40

def pid
  @pid
end

Class Method Details

.for_pid(pid) ⇒ Object



60
61
62
# File 'lib/phusion_passenger/admin_tools/control_process.rb', line 60

def self.for_pid(pid)
	return list(false).find { |c| c.pid == pid }
end

.list(clean_stale = true) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/phusion_passenger/admin_tools/control_process.rb', line 42

def self.list(clean_stale = true)
	results = []
	Dir["#{AdminTools.tmpdir}/passenger.*"].each do |dir|
		next if dir !~ /passenger.(\d+)\Z/
		begin
			results << ControlProcess.new(dir)
		rescue ArgumentError
			# Stale Passenger temp folder. Clean it up if instructed.
			if clean_stale
				puts "*** Cleaning stale folder #{dir}"
				FileUtils.chmod_R(0700, dir) rescue nil
				FileUtils.rm_rf(dir)
			end
		end
	end
	return results
end

Instance Method Details

#backtracesObject



89
90
91
92
93
94
# File 'lib/phusion_passenger/admin_tools/control_process.rb', line 89

def backtraces
	connect do |channel|
		channel.write("backtraces")
		return channel.read_scalar
	end
end

#domainsObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/phusion_passenger/admin_tools/control_process.rb', line 103

def domains
	doc = REXML::Document.new(xml)
	
	domains = []
	doc.elements.each("info/domains/domain") do |domain|
		instances = []
		d = {
			:name => domain.elements["name"].text,
			:instances => instances
		}
		domain.elements.each("instances/instance") do |instance|
			i = Instance.new
			instance.elements.each do |element|
				if i.respond_to?("#{element.name}=")
					if Instance::INT_PROPERTIES.include?(element.name.to_sym)
						value = element.text.to_i
					else
						value = element.text
					end
					i.send("#{element.name}=", value)
				end
			end
			instances << i
		end
		domains << d
	end
	return domains
end

#instancesObject



132
133
134
135
136
# File 'lib/phusion_passenger/admin_tools/control_process.rb', line 132

def instances
	return domains.map do |domain|
		domain[:instances]
	end.flatten
end

#statusObject



82
83
84
85
86
87
# File 'lib/phusion_passenger/admin_tools/control_process.rb', line 82

def status
	connect do |channel|
		channel.write("status")
		return channel.read_scalar
	end
end

#xmlObject



96
97
98
99
100
101
# File 'lib/phusion_passenger/admin_tools/control_process.rb', line 96

def xml
	connect do |channel|
		channel.write("status_xml")
		return channel.read_scalar
	end
end