Class: Falcon::Controller::Virtual
- Inherits:
-
Async::Container::Controller
- Object
- Async::Container::Controller
- Falcon::Controller::Virtual
- Defined in:
- lib/falcon/controller/virtual.rb
Instance Method Summary collapse
- #assume_privileges(path) ⇒ Object
- #falcon_path ⇒ Object
-
#initialize(command, **options) ⇒ Virtual
constructor
A new instance of Virtual.
- #setup(container) ⇒ Object
- #spawn(path, container, **options) ⇒ Object
Constructor Details
#initialize(command, **options) ⇒ Virtual
26 27 28 29 30 31 32 |
# File 'lib/falcon/controller/virtual.rb', line 26 def initialize(command, **) @command = command super(**) trap(SIGHUP, &self.method(:reload)) end |
Instance Method Details
#assume_privileges(path) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/falcon/controller/virtual.rb', line 34 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 |
#falcon_path ⇒ Object
57 58 59 |
# File 'lib/falcon/controller/virtual.rb', line 57 def falcon_path File.("../../../bin/falcon", __dir__) end |
#setup(container) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/falcon/controller/virtual.rb', line 61 def setup(container) if proxy = container[:proxy] proxy.kill(:HUP) end if redirect = container[:redirect] redirect.kill(:HUP) end container.reload do @command.resolved_paths do |path| path = File.(path) root = File.dirname(path) spawn(path, container, chdir: root) end container.spawn(name: "Falcon Redirector", restart: true, key: :redirect) do |instance| instance.exec(falcon_path, "redirect", "--bind", @command.bind_insecure, "--redirect", @command.bind_secure, *@command.paths, ready: false) end container.spawn(name: "Falcon Proxy", restart: true, key: :proxy) do |instance| instance.exec(falcon_path, "proxy", "--bind", @command.bind_secure, *@command.paths, ready: false) end end end |
#spawn(path, container, **options) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/falcon/controller/virtual.rb', line 47 def spawn(path, container, **) container.spawn(name: "Falcon Application", restart: true, key: path) do |instance| env = assume_privileges(path) instance.exec(env, "bundle", "exec", "--keep-file-descriptors", path, ready: false, **) end end |