eye-patch 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +50 -0
- data/lib/eye/patch.rb +2 -8
- data/lib/eye/patch/overrides.rb +14 -18
- data/lib/eye/patch/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7477e243372a1ca33023899cd22d2f6451d7643
|
4
|
+
data.tar.gz: b5df3de37f9f04d334bb40148d77ddd304cea1c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1eec5cf18ca009aa4044e3cd1ecc63334ad022dd8b1fb5ba4bdd50521ac230faa5c8f0a68a57236ee4e0eeb946a8e4d4c2da03971a68b378825c8db5171aa3b0
|
7
|
+
data.tar.gz: 86ea56d72bdfcbb587240bdfa8c91b6613efc479eeafd3b9ab8f8ed2c031c0b13a8011d3a335334d2a99fa21a5ff3a8232fd8bea99c7ee0e15aceb8f7d6743c0
|
data/README.md
CHANGED
@@ -102,6 +102,56 @@ The above configuration will spin up a number of processes equal to `count`, res
|
|
102
102
|
|
103
103
|
This approach pairs well with the `daemonize: true` option, as `eye` will have control over the creation and management of the enumerated PID files.
|
104
104
|
|
105
|
+
### Monkey-Patching
|
106
|
+
|
107
|
+
`Eye::Patch` can't cover all possible use cases, so instead, it supplies a few hooks to allow you to inject your own behavior into `eye` during initial load.
|
108
|
+
|
109
|
+
#### Defining a Setup File
|
110
|
+
|
111
|
+
For the application specified in your configuration file, you can specify a `setup_file` directive, which will tell `Eye::Patch` to load the specified file (relative to the working directory for the application) immediately after parsing your configuration.
|
112
|
+
|
113
|
+
This can be used to inject any desired behavior or hooks into `eye`. For example:
|
114
|
+
|
115
|
+
`working-dir/config/eye.rb`:
|
116
|
+
|
117
|
+
#!/usr/bin/env/ruby
|
118
|
+
|
119
|
+
Eye::Control.settings[:my_key] = "SOME_KEY"
|
120
|
+
|
121
|
+
Eye::Controller.class_eval do
|
122
|
+
def before_spawn
|
123
|
+
reader, writer = ::IO.pipe.map(&:binmode)
|
124
|
+
reader.close_on_exec = false
|
125
|
+
writer.close_on_exec = true
|
126
|
+
|
127
|
+
ENV["MY_FD"] = reader.to_i.to_s
|
128
|
+
|
129
|
+
writer << Eye::Control.settings[:my_key]
|
130
|
+
writer.flush
|
131
|
+
writer.close
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
`working-dir/config/eye.yml`:
|
136
|
+
|
137
|
+
...
|
138
|
+
application:
|
139
|
+
working_dir: working-dir
|
140
|
+
setup_file: config/eye.rb
|
141
|
+
...
|
142
|
+
|
143
|
+
#### Using a `before_spawn` Hook
|
144
|
+
|
145
|
+
If you need to invoke some code before spawning a process (for example, if you want to make a file descriptor available to your new child process), you can accomplish this by patching `Eye::Controller` with a `#before_spawn` method in your setup file. This method will be invoked prior to `Eye::System` calling `Process.spawn`.
|
146
|
+
|
147
|
+
See above for more instructions on how to define this hook during setup.
|
148
|
+
|
149
|
+
#### Working with File Descriptors
|
150
|
+
|
151
|
+
Note that if you _do_ need to persist file descriptors for a daemonized process, you'll want to set the `preserve_fds: true` option for that particular process in your configuration file. `Process.spawn`'s default behavior closes all non-standard file descriptors; this option will ensure that they remain open.
|
152
|
+
|
153
|
+
Note also that since Ruby 2.0, file descriptors are closed when a process is invoked through `bundle exec`. From versions 1.5 and above, you can pass the `--keep-file-descriptors` flag to `bundle exec` to prevent this behavior.
|
154
|
+
|
105
155
|
### Running Locally
|
106
156
|
|
107
157
|
You can test your configurations locally by running the `eye-patch` binary like so:
|
data/lib/eye/patch.rb
CHANGED
@@ -23,16 +23,10 @@ module Eye::Patch
|
|
23
23
|
config.validate!
|
24
24
|
|
25
25
|
config.applications.values.each do |application|
|
26
|
-
|
27
|
-
|
28
|
-
break
|
29
|
-
end
|
26
|
+
next unless application[:setup_file]
|
27
|
+
require File.join(application[:working_dir], application[:setup_file])
|
30
28
|
end
|
31
29
|
|
32
30
|
config
|
33
31
|
end
|
34
|
-
|
35
|
-
def self.setup_file
|
36
|
-
@setup_file
|
37
|
-
end
|
38
32
|
end
|
data/lib/eye/patch/overrides.rb
CHANGED
@@ -25,20 +25,22 @@ Eye::System.class_eval do
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def spawn_options(config = {})
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
options = {
|
29
|
+
pgroup: true,
|
30
|
+
chdir: config[:working_dir] || '/',
|
31
|
+
close_others: !config[:preserve_fds] }
|
32
|
+
|
33
|
+
options[:out] = [config[:stdout], 'a'] if config[:stdout]
|
34
|
+
options[:err] = [config[:stderr], 'a'] if config[:stderr]
|
35
|
+
options[:in] = config[:stdin] if config[:stdin]
|
36
|
+
options[:umask] = config[:umask] if config[:umask]
|
33
37
|
|
34
38
|
if Eye::Local.root?
|
35
|
-
|
36
|
-
|
39
|
+
options[:uid] = Etc.getpwnam(config[:uid]).uid if config[:uid]
|
40
|
+
options[:gid] = Etc.getpwnam(config[:gid]).gid if config[:gid]
|
37
41
|
end
|
38
42
|
|
39
|
-
|
40
|
-
|
41
|
-
o
|
43
|
+
options
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
@@ -46,6 +48,7 @@ end
|
|
46
48
|
Eye::Controller.class_eval do
|
47
49
|
|
48
50
|
def invoke_spawn_callback
|
51
|
+
debug "Attempting before_spawn hook"
|
49
52
|
if respond_to?(:before_spawn)
|
50
53
|
debug "Invoking before_spawn hook"
|
51
54
|
before_spawn
|
@@ -55,14 +58,7 @@ Eye::Controller.class_eval do
|
|
55
58
|
private
|
56
59
|
|
57
60
|
def parse_config(filename)
|
58
|
-
|
59
|
-
|
60
|
-
if Eye::Patch.setup_file
|
61
|
-
info "Loading setup from: #{Eye::Patch.setup_file}"
|
62
|
-
require Eye::Patch.setup_file
|
63
|
-
end
|
64
|
-
|
65
|
-
config
|
61
|
+
Eye::Patch.parse(filename)
|
66
62
|
end
|
67
63
|
end
|
68
64
|
|
data/lib/eye/patch/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eye-patch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Horner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eye
|