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



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

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

#insecure_endpointObject



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

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

#run(verbose = false) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# 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_endpointObject



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

def secure_endpoint
  Async::HTTP::Endpoint.parse(@options[:bind_secure])
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