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
Returns a new instance of Virtual.
28 29 30 31 32 33 34 |
# File 'lib/falcon/controller/virtual.rb', line 28 def initialize(command, **) @command = command super(**) trap(SIGHUP, &self.method(:reload)) end |
Instance Method Details
#assume_privileges(path) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/falcon/controller/virtual.rb', line 36 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
59 60 61 |
# File 'lib/falcon/controller/virtual.rb', line 59 def falcon_path File.("../../../bin/falcon", __dir__) end |
#setup(container) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/falcon/controller/virtual.rb', line 63 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
49 50 51 52 53 54 55 56 57 |
# File 'lib/falcon/controller/virtual.rb', line 49 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 |