locd 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +108 -0
- data/.gitmodules +9 -0
- data/.qb-options.yml +4 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/.yardopts +7 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +72 -0
- data/Rakefile +6 -0
- data/VERSION +1 -0
- data/config/default.yml +24 -0
- data/doc/files/design/domains_and_labels.md +117 -0
- data/doc/files/topics/agents.md +16 -0
- data/doc/files/topics/launchd.md +15 -0
- data/doc/files/topics/plists.md +39 -0
- data/doc/include/plist.md +3 -0
- data/exe/locd +24 -0
- data/lib/locd.rb +75 -0
- data/lib/locd/agent.rb +1186 -0
- data/lib/locd/agent/job.rb +142 -0
- data/lib/locd/agent/proxy.rb +111 -0
- data/lib/locd/agent/rotate_logs.rb +82 -0
- data/lib/locd/agent/site.rb +174 -0
- data/lib/locd/agent/system.rb +270 -0
- data/lib/locd/cli.rb +4 -0
- data/lib/locd/cli/command.rb +9 -0
- data/lib/locd/cli/command/agent.rb +310 -0
- data/lib/locd/cli/command/base.rb +243 -0
- data/lib/locd/cli/command/job.rb +110 -0
- data/lib/locd/cli/command/main.rb +201 -0
- data/lib/locd/cli/command/proxy.rb +177 -0
- data/lib/locd/cli/command/rotate_logs.rb +152 -0
- data/lib/locd/cli/command/site.rb +47 -0
- data/lib/locd/cli/table.rb +157 -0
- data/lib/locd/config.rb +237 -0
- data/lib/locd/config/base.rb +93 -0
- data/lib/locd/errors.rb +65 -0
- data/lib/locd/label.rb +61 -0
- data/lib/locd/launchctl.rb +209 -0
- data/lib/locd/logging.rb +360 -0
- data/lib/locd/newsyslog.rb +402 -0
- data/lib/locd/pattern.rb +193 -0
- data/lib/locd/proxy.rb +272 -0
- data/lib/locd/proxymachine.rb +34 -0
- data/lib/locd/util.rb +49 -0
- data/lib/locd/version.rb +26 -0
- data/locd.gemspec +66 -0
- metadata +262 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eb0dc7c5d3b58d3a71a6f37ca805ad663a503d47
|
4
|
+
data.tar.gz: 0c4c9fe5124b32cdc7774b956bc44b95e80891c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 51ec7cb0807e43bebe247e25854e8a2037f524d542b7d55bd6f40433704e3c354c4859335b5c48b72a908dca41fec8f56ccad955bd65a844a6d9e13269ff886b
|
7
|
+
data.tar.gz: e9e9309a808d16576fc38826a73b6f9034ce870be0b34871f57c360d398d736e61a9508ac2fb46a68f8e6c07925d38e8af334303f8c3e942b6ae4521ba992d7e
|
data/.gitignore
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# BEGIN Ruby.gitingore
|
3
|
+
#
|
4
|
+
# General Git ignore file for Ruby, including support for:
|
5
|
+
#
|
6
|
+
# - Bundler
|
7
|
+
# - RDoc and Yard
|
8
|
+
# - RBEnv and RVM
|
9
|
+
# - DotEnv (optional)
|
10
|
+
#
|
11
|
+
# Additional support is available in separate ignore files:
|
12
|
+
#
|
13
|
+
# - Gem.gitignore (for gem source directories)
|
14
|
+
# - Rails.gitignore
|
15
|
+
# - RubyMotion.gitignore
|
16
|
+
#
|
17
|
+
|
18
|
+
/*.gem
|
19
|
+
*.rbc
|
20
|
+
/.config
|
21
|
+
/coverage/
|
22
|
+
/InstalledFiles
|
23
|
+
/pkg/
|
24
|
+
/spec/reports/
|
25
|
+
/spec/examples.txt
|
26
|
+
/test/tmp/
|
27
|
+
/test/version_tmp/
|
28
|
+
/tmp/
|
29
|
+
|
30
|
+
# Used by dotenv library to load environment variables.
|
31
|
+
# .env
|
32
|
+
|
33
|
+
## Documentation cache and generated files:
|
34
|
+
/.yardoc/
|
35
|
+
/_yardoc/
|
36
|
+
/doc/
|
37
|
+
/rdoc/
|
38
|
+
|
39
|
+
## Environment normalization:
|
40
|
+
.bundle/
|
41
|
+
/vendor/bundle
|
42
|
+
/lib/bundler/man/
|
43
|
+
|
44
|
+
# for a library or gem, add `Gem.gitignore`
|
45
|
+
|
46
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
47
|
+
.rvmrc
|
48
|
+
#
|
49
|
+
# END Ruby.gitingore
|
50
|
+
##############################################################################
|
51
|
+
##############################################################################
|
52
|
+
# BEGIN Gem.gitingore
|
53
|
+
#
|
54
|
+
/Gemfile.lock
|
55
|
+
/.ruby-version
|
56
|
+
/.ruby-gemset
|
57
|
+
#
|
58
|
+
# END Gem.gitingore
|
59
|
+
##############################################################################
|
60
|
+
##############################################################################
|
61
|
+
# BEGIN Global/macOS.gitingore
|
62
|
+
#
|
63
|
+
# General
|
64
|
+
.DS_Store
|
65
|
+
.AppleDouble
|
66
|
+
.LSOverride
|
67
|
+
|
68
|
+
# Icon must end with two \r
|
69
|
+
Icon
|
70
|
+
|
71
|
+
|
72
|
+
# Thumbnails
|
73
|
+
._*
|
74
|
+
|
75
|
+
# Files that might appear in the root of a volume
|
76
|
+
.DocumentRevisions-V100
|
77
|
+
.fseventsd
|
78
|
+
.Spotlight-V100
|
79
|
+
.TemporaryItems
|
80
|
+
.Trashes
|
81
|
+
.VolumeIcon.icns
|
82
|
+
.com.apple.timemachine.donotpresent
|
83
|
+
|
84
|
+
# Directories potentially created on remote AFP share
|
85
|
+
.AppleDB
|
86
|
+
.AppleDesktop
|
87
|
+
Network Trash Folder
|
88
|
+
Temporary Items
|
89
|
+
.apdisk
|
90
|
+
#
|
91
|
+
# END Global/macOS.gitingore
|
92
|
+
##############################################################################
|
93
|
+
##############################################################################
|
94
|
+
# BEGIN QB.gitingore
|
95
|
+
#
|
96
|
+
# generated qb playbooks
|
97
|
+
.qb-playbook.yml
|
98
|
+
|
99
|
+
# ansible retry files
|
100
|
+
.qb-playbook.retry
|
101
|
+
|
102
|
+
# error logs
|
103
|
+
ansible-error.log
|
104
|
+
#
|
105
|
+
# END QB.gitingore
|
106
|
+
##############################################################################
|
107
|
+
!/doc/
|
108
|
+
/doc/site/
|
data/.gitmodules
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
[submodule "dev/packages/gems/nrser"]
|
2
|
+
path = dev/packages/gems/nrser
|
3
|
+
url = git@github.com:nrser/nrser.rb
|
4
|
+
[submodule "dev/packages/gems/cmds"]
|
5
|
+
path = dev/packages/gems/cmds
|
6
|
+
url = git@github.com:nrser/cmds.git
|
7
|
+
[submodule "dev/packages/gems/atli"]
|
8
|
+
path = dev/packages/gems/atli
|
9
|
+
url = git@github.com:nrser/atli.git
|
data/.qb-options.yml
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
# gem 'nrser', path: './dev/packages/gems/nrser'
|
6
|
+
# gem 'cmds', path: './dev/packages/gems/cmds'
|
7
|
+
# gem 'atli', path: './dev/packages/gems/atli'
|
8
|
+
|
9
|
+
# Specify your gem's dependencies in locd.gemspec
|
10
|
+
gemspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 nrser
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
Loc'd
|
2
|
+
==============================================================================
|
3
|
+
|
4
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/locd`. To experiment with that code, run `bin/console` for an interactive prompt.
|
5
|
+
|
6
|
+
TODO: Delete this and the text above, and describe your gem
|
7
|
+
|
8
|
+
|
9
|
+
-----------------------------------------------------------------------------
|
10
|
+
Prerequisites
|
11
|
+
-----------------------------------------------------------------------------
|
12
|
+
|
13
|
+
1. Homebrew
|
14
|
+
|
15
|
+
2. DNSMasq
|
16
|
+
|
17
|
+
1. Install DNSMasq
|
18
|
+
|
19
|
+
brew install dnsmasq
|
20
|
+
|
21
|
+
2. Create resolver file for `test` domain
|
22
|
+
|
23
|
+
sudo mkdir /etc/resolver/
|
24
|
+
sudo echo "nameserver 127.0.0.1" > /etc/resolver/test
|
25
|
+
|
26
|
+
3. Edit `/usr/local/etc/dnsmasq.conf` to contain the lines:
|
27
|
+
|
28
|
+
strict-order
|
29
|
+
address=/.test/127.0.0.1
|
30
|
+
listen-address=127.0.0.1
|
31
|
+
|
32
|
+
4. Edit your network settings to put `127.0.0.1` first in DNS list
|
33
|
+
|
34
|
+
5. Start DNSMasq service
|
35
|
+
|
36
|
+
sudo brew services start dnsmasq
|
37
|
+
|
38
|
+
Ref: https://gist.github.com/ogrrd/5831371
|
39
|
+
|
40
|
+
## Installation
|
41
|
+
|
42
|
+
Add this line to your application's Gemfile:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
gem 'locd'
|
46
|
+
```
|
47
|
+
|
48
|
+
And then execute:
|
49
|
+
|
50
|
+
$ bundle
|
51
|
+
|
52
|
+
Or install it yourself as:
|
53
|
+
|
54
|
+
$ gem install locd
|
55
|
+
|
56
|
+
## Usage
|
57
|
+
|
58
|
+
TODO: Write usage instructions here
|
59
|
+
|
60
|
+
## Development
|
61
|
+
|
62
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
63
|
+
|
64
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/locd.
|
69
|
+
|
70
|
+
## License
|
71
|
+
|
72
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.3
|
data/config/default.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
locd:
|
2
|
+
home: ~/.locd
|
3
|
+
bin: locd
|
4
|
+
|
5
|
+
namespace:
|
6
|
+
label: com.nrser.locd
|
7
|
+
env: LOCD
|
8
|
+
|
9
|
+
proxy:
|
10
|
+
port: 8888
|
11
|
+
bind: 127.0.0.1
|
12
|
+
|
13
|
+
rotate_logs:
|
14
|
+
start_interval:
|
15
|
+
minute: 0
|
16
|
+
|
17
|
+
agent:
|
18
|
+
config_key: locd_config
|
19
|
+
|
20
|
+
site:
|
21
|
+
bind: 127.0.0.1
|
22
|
+
ports:
|
23
|
+
start: 55000
|
24
|
+
end: 56000
|
@@ -0,0 +1,117 @@
|
|
1
|
+
Domains & Labels Design Notes
|
2
|
+
==============================================================================
|
3
|
+
|
4
|
+
Loc'd basically does "virtual-host" HTTP routing of local requests servers running on various local ports. Those servers are run as *agents* though LaunchD (LaunchD calls it's user-space daemons *agents*). Loc'd has facilities to create these agents, assign them ports, and start them on-demand when it receives a request for them.
|
5
|
+
|
6
|
+
Loc'd relies on DNSMasq to point local DNS queries at it for one or more "fake" top-level domains (TLDs), then uses the HTTP `Host` header to figure out what agent to send it to. Right now we're using `test` as the default TLD, and I'll use it in these examples.
|
7
|
+
|
8
|
+
So, the Loc'd proxy receives a request that is supposed to go to an agent `A` that looks like
|
9
|
+
|
10
|
+
<subdomian>.test/<path>
|
11
|
+
|
12
|
+
I've been using a
|
13
|
+
|
14
|
+
<service_name>.<project_name>[.<project_owner>].test
|
15
|
+
|
16
|
+
format, such as
|
17
|
+
|
18
|
+
yard.www-rails.beiarea.test
|
19
|
+
|
20
|
+
# implied owner = me
|
21
|
+
yard.qb.test
|
22
|
+
|
23
|
+
but I'd pretty much like to allow the subdomain to be structured however users want, and switch the TLD or use multiple, though that doesn't really matter for what we're talking about here... all that matters is it has a valid unique `subdomain`.
|
24
|
+
|
25
|
+
Ok, so *agents* are identified by a `label`, which is usually structured as a Java-namespace-style "reverse subdomain", like
|
26
|
+
|
27
|
+
com.github.facebook.watchman
|
28
|
+
com.dropbox.DropboxMacUpdate.agent
|
29
|
+
keybase.kbfs
|
30
|
+
homebrew.mxcl.postgresql
|
31
|
+
|
32
|
+
and are suffixed with `.plist` for their LaunchD property list file. I'm not sure if the domain-ish format is required or enforced by LaunchD at some point, but it fits well with our subdomain identifiers, which is great.
|
33
|
+
|
34
|
+
As you can see, people have taken slightly different approaches:
|
35
|
+
|
36
|
+
# Ex 1. <project_host>.<project_owner>.<project_name>
|
37
|
+
com.github.facebook.watchman
|
38
|
+
|
39
|
+
# Ex 2. <owner_domain>.<service_name>.agent
|
40
|
+
com.dropbox.DropboxMacUpdate.agent
|
41
|
+
|
42
|
+
# Ex 3. <product_name>.<service_name>
|
43
|
+
keybase.kbfs
|
44
|
+
|
45
|
+
# Ex 4. <project_name>.<project_owner>.<service_name>
|
46
|
+
homebrew.mxcl.postgresql
|
47
|
+
|
48
|
+
Some options I've thought of:
|
49
|
+
|
50
|
+
**Opt 1** Project-host-spaced like (Ex 1)
|
51
|
+
|
52
|
+
<project_host>.<project_owner>.<project_name>.<reversed_subdomain...>
|
53
|
+
com.github.nrser.locd.qb.yard
|
54
|
+
|
55
|
+
Ugh, way too long. 不要.
|
56
|
+
|
57
|
+
**Opt 2** Can make it shorter by using my domain like (Ex 2)
|
58
|
+
|
59
|
+
<owner_domain>.<project_name>.<reversed_subdomain...>
|
60
|
+
com.nrser.locd.qb.yard
|
61
|
+
|
62
|
+
- Plus
|
63
|
+
1. Not too long
|
64
|
+
2. Totally unique
|
65
|
+
- Minus
|
66
|
+
1. Still kinda long
|
67
|
+
2. May also need a part do differentiate user agents and Loc'd system agents? So that would extend it...
|
68
|
+
|
69
|
+
**Opt 3** Project name-only like (Ex 3)
|
70
|
+
|
71
|
+
<project_name>.<reversed_subdomain...>
|
72
|
+
locd.qb.yard
|
73
|
+
|
74
|
+
- Plus
|
75
|
+
1. Nice and short
|
76
|
+
- Minus
|
77
|
+
2. Not really "fully qualified", but doesn't seem like a big issues
|
78
|
+
|
79
|
+
**Opt 4.1** Full reversed domain
|
80
|
+
|
81
|
+
<TLD>.<reversed_subdomain...> (really, just the reversed domain)
|
82
|
+
test.qb.yard
|
83
|
+
|
84
|
+
- Plus
|
85
|
+
1. Really strait-forward and simple:
|
86
|
+
1. Receive request to domain `D`
|
87
|
+
|
88
|
+
2. For reverse domain `D_r` see if `<D_r>.plist` exists
|
89
|
+
|
90
|
+
2. Gives direct and complete control to the user
|
91
|
+
|
92
|
+
- Minus
|
93
|
+
1. Prevents (or at least makes much more awkward) to serve on multiple TLDs
|
94
|
+
|
95
|
+
2. Need to read the `.plist` files when figuring out if a `.plist` is associated with Loc'd or not since there's no guaranteed indication in the label.
|
96
|
+
|
97
|
+
3. Annoying that the label and domain are reversed, have to remember which you're using and reverse in your head when typing.
|
98
|
+
|
99
|
+
This is probably my biggest issue with this one.
|
100
|
+
|
101
|
+
**Opt 4.2** Full domain (not reversed)
|
102
|
+
|
103
|
+
<subdomain...>.<TLD> (really, just the domain)
|
104
|
+
yard.qb.test
|
105
|
+
yard.qb.localhost
|
106
|
+
|
107
|
+
- Plus
|
108
|
+
1. Everything from (Opt 4.1)
|
109
|
+
2. Has the same order as the URL
|
110
|
+
|
111
|
+
- Minus
|
112
|
+
1. Differs from the convention
|
113
|
+
2. Doesn't sort naturally
|
114
|
+
|
115
|
+
**I think (Opt 4.2) is the winner**
|
116
|
+
|
117
|
+
Simplicity and power. No extra explaining or translating of anything.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
launchd Agents
|
2
|
+
==============================================================================
|
3
|
+
|
4
|
+
"Agents" are what {file:doc/topics/launchd.md launchd} calls user (as opposed to system/root) jobs and services.
|
5
|
+
|
6
|
+
Agents are defined in {file:doc/topics/plists.md} XML files in
|
7
|
+
|
8
|
+
1. `~/Library/LaunchAgents`
|
9
|
+
- User-specific agents. They run as that user.
|
10
|
+
- This is where Loc'd reads and writes its agents.
|
11
|
+
|
12
|
+
2. `/Library/LaunchAgents`
|
13
|
+
- Agents that still run as the current user but are shared by all users.
|
14
|
+
- Loc'd ignores these at the moment - it doesn't read or write them. Maybe in the future if the need arises.
|
15
|
+
|
16
|
+
Loc'd represents agents through the {Locd::Agent} class and it's subclasses.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
launchd & launchctl
|
2
|
+
==============================================================================
|
3
|
+
|
4
|
+
[launchd][] is the macOS service and job manager (as well as the init system, and probably a few other things as well... but we care about daemons and jobs).
|
5
|
+
|
6
|
+
launchd calls jobs, services, etc. that run as the current user {file:doc/topics/agents.md}.
|
7
|
+
|
8
|
+
Loc'd uses launchd agents to manage it's jobs and services, and interacts with launchd through the [launchctl][] command line interface, which is Ruby-wrapped by the {Locd::Launchctl} module.
|
9
|
+
|
10
|
+
|
11
|
+
<!-- References & Further Reading: -->
|
12
|
+
|
13
|
+
[launchd]: https://en.wikipedia.org/wiki/Launchd
|
14
|
+
|
15
|
+
[launchctl]: https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/launchctl.1.html
|