Class: Falcon::Command::Virtual
- Inherits:
-
Samovar::Command
- Object
- Samovar::Command
- Falcon::Command::Virtual
- Defined in:
- lib/falcon/command/virtual.rb
Instance Method Summary collapse
- #assume_privileges(path) ⇒ Object
- #call ⇒ Object
-
#host_endpoint(hostname, **options) ⇒ Object
An endpoint suitable for connecting to the specified hostname.
- #insecure_endpoint(**options) ⇒ Object
- #run(verbose = false) ⇒ Object
- #secure_endpoint(**options) ⇒ Object
- #spawn(path, container, **options) ⇒ Object
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 |
#call ⇒ Object
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, **) endpoint = secure_endpoint(**) 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(**) 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 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.(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(**) 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, **) container.spawn(name: self.name, restart: true) do |instance| env = assume_privileges(path) instance.exec(env, "bundle", "exec", path, **) end end |