Class: Locd::Agent::Site
- Inherits:
-
Locd::Agent
- Object
- Locd::Agent
- Locd::Agent::Site
- Defined in:
- lib/locd/agent/site.rb
Overview
An site is a Locd::Agent that the proxy can route HTTP requests to.
If you send an HTTP request to the proxy with the site's label as the host, the proxy will start the site if it isn't running and route the request to it's #port.
Combined with DNSMasq pointing the site's label to the proxy (and using the port the proxy is running on) this allows you to open the site's #url in the browser (or make a request to it from anything that resolves DNS properly through DNSMasq... should work fine for APIs and other HTTP services) and get through to the agent.
Constant Summary collapse
- BIND =
Address we expect servers to bind to so we can reach them. Provided during command rendering as
{bind}so it can be used when running service commands.For the moment at least this seems to need to be
127.0.0.1'cause I think ProxyMachine had trouble connecting tolocalhost, so services need to bind to it or be reachable at it. '127.0.0.1'.freeze
- TO_H_NAMES =
Attribute / method names that Locd::Agent#to_h uses.
Locd::Agent::TO_H_NAMES.union [:port, :url]
Instance Attribute Summary
Attributes inherited from Locd::Agent
Querying collapse
-
.ports ⇒ Hamster::SortedSet<Fixnum>
Sorted set of all ports configured for installed Site.
Creating Servers collapse
-
.create_plist_data(cmd_template:, label:, workdir:, log_path: nil, keep_alive: false, run_at_load: false, port: nil, bind: , open_path: '/') ⇒ Hash<String, Object>
Create the
launchdproperty list data for a new Site, which has an additionalport:keyword versus create_plist_data.
Instance Methods: Attribute Readers collapse
- #open_path ⇒ Object
-
#port ⇒ Fixnum
Port service runs on.
-
#url ⇒ String
The URL the agent can be reached at through the proxy.
Class Method Summary collapse
-
.plist?(plist) ⇒ Boolean
See if a parsed plist looks like a site.
Methods inherited from Locd::Agent
#<=>, add, add_or_update, all, class_for, #cmd_template, #config, default_log_path, #default_log_path?, #err_path, exists?, find_all, find_all!, find_only!, from_path, get, #initialize, #label, labels, #last_exit_code, #load, #log_paths, #out_path, #pid, plist_abs_path, plists, #reload, #remove, render_cmd, resolve_log_path, #restart, #running?, #start, #status, #stop, #stopped?, #to_h, #to_json, #to_yaml, #unload, #update, user_plist_abs_dir, #workdir
Constructor Details
This class inherits a constructor from Locd::Agent
Class Method Details
.create_plist_data(cmd_template:, label:, workdir:, log_path: nil, keep_alive: false, run_at_load: false, port: nil, bind: , open_path: '/') ⇒ Hash<String, Object>
Create the launchd property list data for a new Locd::Agent::Site, which
has an additional port: keyword versus Locd::Agent.create_plist_data.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/locd/agent/site.rb', line 122 def self.create_plist_data cmd_template:, label:, workdir:, log_path: nil, keep_alive: false, run_at_load: false, port: nil, bind: Locd.config[:site, :bind], open_path: '/' # Allocate a port if one was not provided port = if port.nil? Locd::Proxy.allocate_port else # or just normalize to {Fixnum} port.to_i end open_path = "/#{ path }" unless open_path.start_with? '/' super cmd_template: cmd_template, label: label, workdir: workdir, log_path: log_path, keep_alive: keep_alive, run_at_load: run_at_load, # Extras specific to {Locd::Agent::Site}: port: port, bind: bind, open_path: open_path end |
.plist?(plist) ⇒ Boolean
See if a parsed plist looks like a site.
78 79 80 |
# File 'lib/locd/agent/site.rb', line 78 def self.plist? plist !! plist.dig( Locd.config[:agent, :config_key], 'port' ) end |
.ports ⇒ Hamster::SortedSet<Fixnum>
Sorted set of all ports configured for installed Locd::Agent::Site.
Used to determine available ports to allocate when creating new services.
93 94 95 |
# File 'lib/locd/agent/site.rb', line 93 def self.ports Hamster::SortedSet.new all.values.map( &:port ) end |
Instance Method Details
#open_path ⇒ Object
170 171 172 |
# File 'lib/locd/agent/site.rb', line 170 def open_path config['open_path'] || '/' end |
#port ⇒ Fixnum
Returns Port service runs on.
165 166 167 |
# File 'lib/locd/agent/site.rb', line 165 def port config['port'] end |
#url ⇒ String
Returns The URL the agent can be reached at through the proxy.
177 178 179 |
# File 'lib/locd/agent/site.rb', line 177 def url "http://#{ label }:#{ Locd::Proxy.port }#{ open_path }" end |