thin-attach_socket 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +49 -0
- data/lib/thin/attach_socket.rb +64 -0
- data/thin-attach_socket.gemspec +14 -0
- metadata +80 -0
data/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Provides `Thin::Backends::AttachSocket` for booting a thin server on an already open
|
|
2
|
+
Socket.
|
|
3
|
+
|
|
4
|
+
This is useful when running thin inside [einhorn](https://github.com/stripe/einhorn), and
|
|
5
|
+
it requires [eventmachine-le](https://github.com/ibc/EventMachine-LE).
|
|
6
|
+
|
|
7
|
+
Installation
|
|
8
|
+
============
|
|
9
|
+
|
|
10
|
+
Either `gem install thin-attach_socket`, or add `gem 'thin-attach_socket'` to your
|
|
11
|
+
`Gemfile` and run `bundle`.
|
|
12
|
+
|
|
13
|
+
Usage
|
|
14
|
+
=====
|
|
15
|
+
|
|
16
|
+
Thin allows you to configure the backend dynamically, so using thin-attach-socket is as
|
|
17
|
+
simple as:
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
require 'thin/attach_socket'
|
|
21
|
+
Thin::Server.new(MyApp,
|
|
22
|
+
backend: Thin::Backends::AttachSocket,
|
|
23
|
+
socket: IO.for_fd(6))
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
By default thin will stop the EventMachine reactor when you stop the server, and this is
|
|
27
|
+
usually what you want. If you're running other servers on the reactor however, you should
|
|
28
|
+
pass `preserve_reactor: true` when constructing a new server, and this will not happen.
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
require 'thin/attach_socket'
|
|
32
|
+
Thin::Server.new(MyApp,
|
|
33
|
+
backend: Thin::Backends::AttachSocket,
|
|
34
|
+
socket: IO.for_fd(6),
|
|
35
|
+
signals: false,
|
|
36
|
+
preserve_reactor: true)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
If you do this, you need to make sure to stop the thin server before stopping the EM
|
|
40
|
+
reactor.
|
|
41
|
+
|
|
42
|
+
Meta-foo
|
|
43
|
+
========
|
|
44
|
+
|
|
45
|
+
thin-attach_socket is released under the Ruby License, http://www.ruby-lang.org/en/LICENSE.txt.
|
|
46
|
+
|
|
47
|
+
It was heavily based on the [work](https://github.com/stripe/thin/commit/42e29ba23a136a30dc11a1c9dff1fe1187dc9eee) of
|
|
48
|
+
Patrick Collison at Stripe.
|
|
49
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Based on Patrick Collison's commit to stripe/thin:
|
|
2
|
+
# https://github.com/stripe/thin/commit/42e29ba23a136a30dc11a1c9dff1fe1187dc9eee
|
|
3
|
+
#
|
|
4
|
+
module Thin
|
|
5
|
+
module Backends
|
|
6
|
+
# Backend to act as a TCP server using an already opened file
|
|
7
|
+
# descriptor. Currently requires a patched EventMachine like
|
|
8
|
+
# https://github.com/ibc/EventMachine-LE
|
|
9
|
+
#
|
|
10
|
+
# @example
|
|
11
|
+
#
|
|
12
|
+
# Thin::Server.new(MyApp,
|
|
13
|
+
# backend: Thin::Backends::AttachSocket,
|
|
14
|
+
# socket: IO.for_fd(6))
|
|
15
|
+
#
|
|
16
|
+
# If you're running thin inside a reactor with other servers, then pass
|
|
17
|
+
# preserve_reactor: true. This ensures that when you stop the Thin server,
|
|
18
|
+
# it will not stop your reactor.
|
|
19
|
+
#
|
|
20
|
+
# If you're doing that you probably also want to pass signals: false so that
|
|
21
|
+
# you can control when thin shuts down:
|
|
22
|
+
#
|
|
23
|
+
# @example
|
|
24
|
+
#
|
|
25
|
+
# Thin::Server.new(MyApp,
|
|
26
|
+
# backend: Thin::Backends::AttachSocket,
|
|
27
|
+
# socket: IO.for_fd(6),
|
|
28
|
+
# signals: false,
|
|
29
|
+
# preserve_reactor: true)
|
|
30
|
+
#
|
|
31
|
+
class AttachSocket < Base
|
|
32
|
+
def initialize(host, port, options)
|
|
33
|
+
@socket = options[:socket]
|
|
34
|
+
@preserve_reactor = !!options[:preserve_reactor]
|
|
35
|
+
super()
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def connect
|
|
39
|
+
@signature = EventMachine.attach_server(@socket, Connection, &method(:initialize_connection))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def disconnect
|
|
43
|
+
EventMachine.stop_server(@signature)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def to_s
|
|
47
|
+
"socket:#{@socket.inspect}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def stop!
|
|
51
|
+
if @preserve_reactor
|
|
52
|
+
# This is the code for super, with the EM::stop call removed.
|
|
53
|
+
@running = false
|
|
54
|
+
@stopping = false
|
|
55
|
+
|
|
56
|
+
@connections.each { |connection| connection.close_connection_after_writing }
|
|
57
|
+
close
|
|
58
|
+
else
|
|
59
|
+
super
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = "thin-attach_socket"
|
|
3
|
+
s.version = "0.1"
|
|
4
|
+
s.platform = Gem::Platform::RUBY
|
|
5
|
+
s.author = "Conrad Irwin"
|
|
6
|
+
s.email = "conrad.irwin@gmail.com"
|
|
7
|
+
s.homepage = "http://github.com/ConradIrwin/thin-attach_socket"
|
|
8
|
+
s.summary = "Provides Thin::Backends::AttachServer for booting thin on an existing socket."
|
|
9
|
+
s.description = "This is useful for running thin behind einhorn, and requires eventmachine-le"
|
|
10
|
+
s.files = `git ls-files`.split("\n")
|
|
11
|
+
s.require_path = "lib"
|
|
12
|
+
s.add_dependency 'thin'
|
|
13
|
+
s.add_dependency 'eventmachine-le'
|
|
14
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: thin-attach_socket
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease:
|
|
5
|
+
version: '0.1'
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Conrad Irwin
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-12-11 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
type: :runtime
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
prerelease: false
|
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
+
none: false
|
|
25
|
+
requirements:
|
|
26
|
+
- - ! '>='
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '0'
|
|
29
|
+
name: thin
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
type: :runtime
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
prerelease: false
|
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
40
|
+
none: false
|
|
41
|
+
requirements:
|
|
42
|
+
- - ! '>='
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: '0'
|
|
45
|
+
name: eventmachine-le
|
|
46
|
+
description: This is useful for running thin behind einhorn, and requires eventmachine-le
|
|
47
|
+
email: conrad.irwin@gmail.com
|
|
48
|
+
executables: []
|
|
49
|
+
extensions: []
|
|
50
|
+
extra_rdoc_files: []
|
|
51
|
+
files:
|
|
52
|
+
- README.md
|
|
53
|
+
- lib/thin/attach_socket.rb
|
|
54
|
+
- thin-attach_socket.gemspec
|
|
55
|
+
homepage: http://github.com/ConradIrwin/thin-attach_socket
|
|
56
|
+
licenses: []
|
|
57
|
+
post_install_message:
|
|
58
|
+
rdoc_options: []
|
|
59
|
+
require_paths:
|
|
60
|
+
- lib
|
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
|
+
none: false
|
|
63
|
+
requirements:
|
|
64
|
+
- - ! '>='
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '0'
|
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
|
+
none: false
|
|
69
|
+
requirements:
|
|
70
|
+
- - ! '>='
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '0'
|
|
73
|
+
requirements: []
|
|
74
|
+
rubyforge_project:
|
|
75
|
+
rubygems_version: 1.8.24
|
|
76
|
+
signing_key:
|
|
77
|
+
specification_version: 3
|
|
78
|
+
summary: Provides Thin::Backends::AttachServer for booting thin on an existing socket.
|
|
79
|
+
test_files: []
|
|
80
|
+
has_rdoc:
|