Class: Falcon::Command::Virtual

Inherits:
Samovar::Command
  • Object
show all
Defined in:
lib/falcon/command/virtual.rb

Instance Method Summary collapse

Instance Method Details

#assume_privileges(path) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/falcon/command/virtual.rb', line 50

def assume_privileges(path)
  stat = File.stat(path)
  
  Process::GID.change_privilege(stat.gid)
  Process::UID.change_privilege(stat.uid)
  
  home = Etc.getpwuid(stat.uid).dir
  
  return {
    'HOME' => home,
  }
end

#callObject



91
92
93
94
95
# File 'lib/falcon/command/virtual.rb', line 91

def call
  container = run(parent.verbose?)
  
  container.wait
end

#host_endpoint(hostname, **options) ⇒ Object

An endpoint suitable for connecting to the specified hostname.



106
107
108
109
110
111
112
113
# File 'lib/falcon/command/virtual.rb', line 106

def host_endpoint(hostname, **options)
  endpoint = secure_endpoint(**options)
  
  url = URI.parse(@options[:bind_secure])
  url.hostname = hostname
  
  return Async::HTTP::Endpoint.new(url, hostname: endpoint.hostname)
end

#insecure_endpoint(**options) ⇒ Object



97
98
99
# File 'lib/falcon/command/virtual.rb', line 97

def insecure_endpoint(**options)
  Async::HTTP::Endpoint.parse(@options[:bind_insecure], **options)
end

#run(verbose = false) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/falcon/command/virtual.rb', line 71

def run(verbose = false)
  configuration = Configuration.new(verbose)
  container = Async::Container.new
  
  @paths.each do |path|
    path = File.expand_path(path)
    root = File.dirname(path)
    
    configuration.load_file(path)
    
    spawn(path, container, chdir: root)
  end
  
  hosts = Hosts.new(configuration)
  
  hosts.run(container, **@options)
  
  return container
end

#secure_endpoint(**options) ⇒ Object



101
102
103
# File 'lib/falcon/command/virtual.rb', line 101

def secure_endpoint(**options)
  Async::HTTP::Endpoint.parse(@options[:bind_secure], **options)
end

#spawn(path, container, **options) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/falcon/command/virtual.rb', line 63

def spawn(path, container, **options)
  container.spawn(name: self.name, restart: true) do |instance|
    env = assume_privileges(path)
    
    instance.exec(env, "bundle", "exec", path, **options)
  end
end