Class: Falcon::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/falcon/hosts.rb

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ Host

Returns a new instance of Host.



32
33
34
35
# File 'lib/falcon/hosts.rb', line 32

def initialize(environment)
	@environment = environment.flatten
	@evaluator = @environment.evaluator
end

Instance Method Details

#assume_privileges(path) ⇒ Object



65
66
67
68
69
70
# File 'lib/falcon/hosts.rb', line 65

def assume_privileges(path)
	stat = File.stat(path)
	
	Process::GID.change_privilege(stat.gid)
	Process::UID.change_privilege(stat.uid)
end

#authorityObject



41
42
43
# File 'lib/falcon/hosts.rb', line 41

def authority
	@evaluator.authority
end

#bound_endpointObject



57
58
59
# File 'lib/falcon/hosts.rb', line 57

def bound_endpoint
	@evaluator.bound_endpoint
end

#endpointObject



45
46
47
# File 'lib/falcon/hosts.rb', line 45

def endpoint
	@evaluator.endpoint
end

#nameObject



37
38
39
# File 'lib/falcon/hosts.rb', line 37

def name
	"Falcon Host for #{self.authority}"
end

#rootObject



53
54
55
# File 'lib/falcon/hosts.rb', line 53

def root
	@evaluator.root
end

#run(container) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/falcon/hosts.rb', line 72

def run(container)
	if @environment.include?(:server)
		bound_endpoint = self.bound_endpoint
		
		container.run(count: 1, name: self.name) do |task, instance|
			Async.logger.info(self) {"Starting application server..."}
			
			if root = self.root
				Dir.chdir(root)
			end
			
			server = @evaluator.server
			
			# Drop root privileges:
			assume_privileges(root)
			
			server.run
			
			task.children.each(&:wait)
		end
	end
end

#ssl_contextObject



49
50
51
# File 'lib/falcon/hosts.rb', line 49

def ssl_context
	@evaluator.ssl_context
end

#to_sObject



61
62
63
# File 'lib/falcon/hosts.rb', line 61

def to_s
	"\#<#{self.class} #{@evaluator.authority}>"
end