drctrl 0.1.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c57e89d0b5d7c9822a9413407e881054f9419ba2
4
+ data.tar.gz: 57495ebe3caa40066010ea7886100867ca1e9eb7
5
+ SHA512:
6
+ metadata.gz: 510ec94063e41c05cfeae3d9a5c9a59298caa4c4e1ca9fa7eb64bf7a028870a72f619746bc3a9058857d5c74071c89358f8846219385c2050e45e927a2d7833d
7
+ data.tar.gz: c0a553383dfc42001bde3d261f0073b6a5a70eb9e6fc06482b34ee9a7a21b7d458fd2f0aa8ff2069adac4de55b1dfbe0811786ebc6704625dae0657a1f5c600a
data/LICENSE ADDED
@@ -0,0 +1,166 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
166
+
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # drctrl
2
+
3
+ A local control for DRb service.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/drctrl.svg)](http://badge.fury.io/rb/drctrl)
6
+ [![GitHub license](https://img.shields.io/badge/license-LGPLv3-orange.svg?style=flat)](https://raw.githubusercontent.com/shikhalev/drctrl/master/LICENSE)
7
+ [![Code Climate](https://codeclimate.com/github/shikhalev/drctrl/badges/gpa.svg)](https://codeclimate.com/github/shikhalev/drctrl)
8
+
9
+ This gem provides a local dRuby service for control purposes and a command line
10
+ tool for it.
11
+
12
+ ## Usage
13
+
14
+ ### At server side
15
+
16
+ ```Ruby
17
+ require 'drctrl'
18
+
19
+ DRCtrl.start_service do
20
+ # some finalize code
21
+ end
22
+
23
+ . . . . .
24
+
25
+
26
+ DRCtrl.wait
27
+
28
+ ```
29
+
30
+ This code creates object with methods `stop` and `restart`. And it starts
31
+ a dRuby service at unix-socket `/tmp/<appname>-<pid>`.
32
+
33
+ Use `DRCtrl.wait` instead `DRb.thread.join` for correct stopping.
34
+
35
+ ### At client side
36
+
37
+ Use a command line tool `drctrl` or your own code with
38
+ `require 'drctrl/client'`.
39
+
40
+ `drctrl` find appropriate dRuby server and send to it command and arguments.
41
+
42
+ ```
43
+ drctrl [<options>] <command> [<args>]
44
+ -U, --uri=URI
45
+ -P, --path=PATH
46
+ -N, --name=NAME
47
+ -I, --pid=PID
48
+ ```
49
+
50
+ There is required to set one of options: `--uri` (any dRuby URI), `--path`
51
+ (a path to unix-socket), or `--name` (name of controlled app).
data/bin/drctrl ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/ruby
2
+ # encoding: utf-8
3
+
4
+ require 'optparse'
5
+ require 'current_spec'
6
+ require_relative '../lib/drctrl/client'
7
+
8
+ verbose = false
9
+
10
+ options = {
11
+ uri: nil,
12
+ path: nil,
13
+ name: nil,
14
+ pid: nil
15
+ }
16
+
17
+ opts = OptionParser.new do |o|
18
+
19
+ o.banner = 'drctrl [<options>] <command> [<args>]'
20
+
21
+ o.on '-h', '-?', '--help', 'Show this help and exit.' do
22
+ puts opts.help
23
+ exit
24
+ end
25
+
26
+ o.on '-V', '--version', 'Show version info and exit' do
27
+ puts(Gem.current_spec_version || DRCtrl::VERSION.join('.'))
28
+ exit
29
+ end
30
+
31
+ o.on '-v', '--[no-]verbose', 'Verbose mode.' do |value|
32
+ verbose = value
33
+ end
34
+
35
+ o.separator ''
36
+
37
+ o.on '-U', '--uri', '=URI', String do |value|
38
+ options[:uri] = value
39
+ end
40
+
41
+ o.on '-P', '--path', '=PATH', String do |value|
42
+ options[:path] = value
43
+ end
44
+
45
+ o.on '-N', '--name', '=NAME', String do |value|
46
+ options[:name] = value
47
+ end
48
+
49
+ o.on '-I', '--pid', '=PID', Integer do |value|
50
+ options[:pid] = value
51
+ end
52
+
53
+ end
54
+
55
+ command, *args = opts.parse ARGV
56
+
57
+ obj = DRCtrl.connect options
58
+
59
+ if Array === obj
60
+ obj.each do |o|
61
+ if verbose
62
+ puts "Send #{command.intern.inspect} to #{o.__drburi.inspect}..."
63
+ end
64
+ o.send command.intern, *args
65
+ end
66
+ else
67
+ if verbose
68
+ puts "Send #{command.intern.inspect} to #{obj.__drburi.inspect}..."
69
+ end
70
+ obj.send command.intern, *args
71
+ end
data/lib/drctrl.rb ADDED
@@ -0,0 +1,89 @@
1
+ # encoding: utf-8
2
+
3
+ require 'drb'
4
+
5
+ require_relative 'drctrl/version'
6
+
7
+ # Namespace module. Contains server-side methods if you use
8
+ # require 'drctrl'
9
+ # and client-side methods if you use
10
+ # require 'drctrl/client'
11
+ module DRCtrl
12
+
13
+ # Controller service front object class.
14
+ class Server
15
+
16
+ # @yield Block without parameters which will be runned before stop
17
+ # the service.
18
+ def initialize &block
19
+ @block = block
20
+ end
21
+
22
+ # Stop the service.
23
+ # @return [void]
24
+ def stop
25
+ if @block
26
+ Thread.exclusive do
27
+ block.call
28
+ end
29
+ end
30
+ DRb.primary_server = DRCtrl.server
31
+ DRb.stop_service
32
+ end
33
+
34
+ # Restart the service.
35
+ # @return [Integer] Process ID for new process.
36
+ def restart
37
+ stop
38
+ sleep 0
39
+ spawn 'ruby', File.expand_path($0), *($*)
40
+ end
41
+
42
+ end
43
+
44
+ class << self
45
+
46
+ # @!group Server-side Module Attributes
47
+
48
+ # DRCtrl server.
49
+ # @return [DRb::DRbServer]
50
+
51
+ attr_reader :server
52
+
53
+ # @!endgroup
54
+
55
+ # @!group Server-side Module Methods
56
+
57
+ # Start control service with provided or default URI. Create
58
+ # a {DRCtrl::Server} instance and start it as a front object of dRuby service.
59
+ # @param uri [String] Optional. Custom URI for this control service.
60
+ # If not set the automated '+drbunix:+' socket will be used.
61
+ # @param opts [Hash] Options for +DRb::start_service+.
62
+ # @yield Block without parameters which will be runned before stop
63
+ # the service.
64
+ # @return [DRb::DRbServer]
65
+
66
+ def start_service uri: nil, **opts, &block
67
+ if uri.nil?
68
+ uri = "drbunix:/tmp/#{File.basename($0, '.rb')}-#{Process.pid}"
69
+ end
70
+ oldprim = DRb.primary_server
71
+ @server = DRb.start_service uri, Server.new(&block), opts
72
+ DRb.primary_server = oldprim if oldprim
73
+ @server
74
+ end
75
+
76
+ # Wait when control service will be stopped.
77
+ # @return [void]
78
+
79
+ def wait
80
+ @server.thread.join if @server
81
+ end
82
+
83
+ alias :join :wait
84
+
85
+ # @!endgroup
86
+
87
+ end
88
+
89
+ end
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+
3
+ require 'drb'
4
+
5
+ require_relative 'version'
6
+
7
+ module DRCtrl
8
+
9
+ class << self
10
+
11
+ # @!group Client-side Module Methods
12
+
13
+ # Find socket path for name and process ID.
14
+ # @param [String] name Application name.
15
+ # @param [Integer] pid Process ID.
16
+ # @return [String, Array<String>, nil]
17
+
18
+ def detect name, pid = nil
19
+ if pid
20
+ result = "/tmp/#{name}-#{pid}"
21
+ if File.socket? result
22
+ return result
23
+ else
24
+ return nil
25
+ end
26
+ else
27
+ files = Dir["/tmp/#{name}*"]
28
+ result = files.select { |f| File.socket? f }
29
+ if result.length == 0
30
+ return nil
31
+ elsif result.length == 1
32
+ return result[0]
33
+ else
34
+ return result
35
+ end
36
+ end
37
+ end
38
+
39
+ # Connect to dRuby socket(-s).
40
+ # @param uri [String] Socket's URI.
41
+ # @param path [String] Path to unix-socket.
42
+ # @param name [String] Application name.
43
+ # @param pid [Integer] Process ID.
44
+ # @return [DRb::DRbObject, Array<DRbObject>, nil]
45
+ # @raise [RuntimeError] If socket not found.
46
+ # @raise [ArgumentError] If no required arguments setted.
47
+
48
+ def connect uri: nil, path: nil, name: nil, pid: nil
49
+ if uri
50
+ DRbObject.new nil, uri
51
+ elsif path
52
+ DRbObject.new nil, "drbunix:#{path}"
53
+ elsif name
54
+ socket = detect name, pid
55
+ case socket
56
+ when String
57
+ DRbObject.new nil, "drbunix:#{socket}"
58
+ when Array
59
+ socket.map { |s| DRbObject.new nil, "drbunix:#{s}" }
60
+ else
61
+ raise RuntimeError, "Socket for { name: #{name.inspect}," +
62
+ " pid: #{pid.inspect} } not found!", caller
63
+ end
64
+ else
65
+ raise ArgumentError,
66
+ "One of this arguments: uri, path or name must be setted!", caller
67
+ end
68
+ end
69
+
70
+ # @!endgroup
71
+
72
+ end
73
+
74
+ end
75
+
76
+
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ module DRCtrl
4
+
5
+ # Version of drctrl gem without build number.
6
+ VERSION = [0, 1, 1]
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drctrl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Shikhalev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: current_spec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: set_version
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ description: A local control for DRb service.
42
+ email: shikhalev@gmail.com
43
+ executables:
44
+ - drctrl
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - LICENSE
49
+ - README.md
50
+ - bin/drctrl
51
+ - lib/drctrl.rb
52
+ - lib/drctrl/client.rb
53
+ - lib/drctrl/version.rb
54
+ homepage: https://github.com/shikhalev/drctrl
55
+ licenses:
56
+ - GNU LGPLv3
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '2.0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.4.6
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: A local control for DRb service
78
+ test_files: []
79
+ has_rdoc: