lib/falcon/command/virtual.rb in falcon-0.34.5 vs lib/falcon/command/virtual.rb in falcon-0.35.0
- old
+ new
@@ -16,83 +16,48 @@
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
-require_relative '../server'
-require_relative '../endpoint'
-require_relative '../hosts'
-require_relative '../configuration'
+require_relative '../controller/virtual'
+require_relative 'paths'
-require 'async/container'
-require 'async/container/controller'
-
-require 'async/io/host_endpoint'
-require 'async/io/shared_endpoint'
-require 'async/io/ssl_endpoint'
-
require 'samovar'
-require 'rack/builder'
-require 'rack/server'
-
module Falcon
module Command
class Virtual < Samovar::Command
self.description = "Run one or more virtual hosts with a front-end proxy."
options do
- option '--bind-insecure <address>', "Bind redirection to the given hostname/address", default: "http://[::]"
- option '--bind-secure <address>', "Bind proxy to the given hostname/address", default: "https://[::]"
+ option '--bind-insecure <address>', "Bind redirection to the given hostname/address", default: "http://[::]:8080"
+ option '--bind-secure <address>', "Bind proxy to the given hostname/address", default: "https://[::]:8443"
end
many :paths
- 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,
- }
+ include Paths
+
+ def controller
+ Controller::Virtual.new(self)
end
- 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
+ def bind_secure
+ @options[:bind_secure]
end
- 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
+ def bind_insecure
+ @options[:bind_insecure]
end
def call
- container = run(parent.verbose?)
+ Async.logger.info(self) do |buffer|
+ buffer.puts "Falcon Virtual v#{VERSION} taking flight!"
+ buffer.puts "- To terminate: Ctrl-C or kill #{Process.pid}"
+ buffer.puts "- To reload all sites: kill -HUP #{Process.pid}"
+ end
- container.wait
+ self.controller.run
end
def insecure_endpoint(**options)
Async::HTTP::Endpoint.parse(@options[:bind_insecure], **options)
end