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.
Defined Under Namespace
Classes: Status
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 ⇒ Integer
Port service runs on.
-
#url ⇒ String
The URL the agent can be reached at through the proxy.
`launchctl` Interface Instance Methods collapse
-
#status(refresh: false) ⇒ Status
The site agent's status from parsing
launchctl list.
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, #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.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/locd/agent/site.rb', line 138 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.
94 95 96 |
# File 'lib/locd/agent/site.rb', line 94 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.
109 110 111 |
# File 'lib/locd/agent/site.rb', line 109 def self.ports Hamster::SortedSet.new all.values.map( &:port ) end |
Instance Method Details
#open_path ⇒ Object
186 187 188 |
# File 'lib/locd/agent/site.rb', line 186 def open_path config['open_path'] || '/' end |
#port ⇒ Integer
Returns Port service runs on.
181 182 183 |
# File 'lib/locd/agent/site.rb', line 181 def port config['port'] end |