rakeup 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Library dependencies
4
+ gem "rake", "~> 10.0.0"
5
+ gem "rack", "~> 1.5.0"
6
+ gem "puma", "~> 2.0.1"
7
+ gem "thin", "~> 1.5.1"
8
+
9
+ group :development do
10
+ gem "rspec", "~> 2.13.0"
11
+ gem "rdoc", "~> 4.0"
12
+ gem "bundler", "~> 1.3.0"
13
+ gem "jeweler", "~> 1.8.0"
14
+ gem "simplecov", "~> 0.7.0"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ daemons (1.1.9)
5
+ diff-lcs (1.2.4)
6
+ eventmachine (1.0.3)
7
+ git (1.2.5)
8
+ jeweler (1.8.4)
9
+ bundler (~> 1.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ rdoc
13
+ json (1.8.0)
14
+ multi_json (1.7.3)
15
+ puma (2.0.1)
16
+ rack (>= 1.1, < 2.0)
17
+ rack (1.5.2)
18
+ rake (10.0.4)
19
+ rdoc (4.0.1)
20
+ json (~> 1.4)
21
+ rspec (2.13.0)
22
+ rspec-core (~> 2.13.0)
23
+ rspec-expectations (~> 2.13.0)
24
+ rspec-mocks (~> 2.13.0)
25
+ rspec-core (2.13.1)
26
+ rspec-expectations (2.13.0)
27
+ diff-lcs (>= 1.1.3, < 2.0)
28
+ rspec-mocks (2.13.1)
29
+ simplecov (0.7.1)
30
+ multi_json (~> 1.0)
31
+ simplecov-html (~> 0.7.1)
32
+ simplecov-html (0.7.1)
33
+ thin (1.5.1)
34
+ daemons (>= 1.0.9)
35
+ eventmachine (>= 0.12.6)
36
+ rack (>= 1.0.0)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ bundler (~> 1.3.0)
43
+ jeweler (~> 1.8.0)
44
+ puma (~> 2.0.1)
45
+ rack (~> 1.5.0)
46
+ rake (~> 10.0.0)
47
+ rdoc (~> 4.0)
48
+ rspec (~> 2.13.0)
49
+ simplecov (~> 0.7.0)
50
+ thin (~> 1.5.1)
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2009-2012 The RestKit Project
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ RakeUp
2
+ ======
3
+
4
+ RakeUp provides a set of turn-key [Rake](http://rake.rubyforge.org/) tasks for running a local [Rack](http://rack.github.io/) based server application. By configuring a single block in your Rakefile, you will have access to a rich set of tasks for start, stopping, and monitoring your server. These tasks are essentially thin wrappers around the `rackup` command and are useful for running lightweight applications that are used for local development and testing.
5
+
6
+ This project was developed for use with the test server of the [RestKit](http://restkit.org/) project on iOS. RestKit runs numerous tests over HTTP against a local server and RakeUp provides the management of that server instance.
7
+
8
+ ## Example Rakefile
9
+
10
+ ``` ruby
11
+ require 'rubygems'
12
+ require 'bundler/setup'
13
+ require 'rakeup'
14
+
15
+ RakeUp::ServerTask.new do |t|
16
+ t.port = 8558
17
+ t.pid_file = 'tmp/server.pid'
18
+ t.rackup_file = 'server.ru'
19
+ t.server = :thin
20
+ end
21
+ ```
22
+
23
+ After configuring the task, you can run `rake -T server` to see your new server management tasks:
24
+
25
+ ```
26
+ rake server # Run the server in the foreground
27
+ rake server:abort_unless_running # Abort the task chain unless the server is running
28
+ rake server:autostart # Starts the server if there is not already an instance running
29
+ rake server:autostop # Stops the server if executed via autostart
30
+ rake server:restart # Restart the server daemon
31
+ rake server:start # Start the server daemon
32
+ rake server:status # Check the status of the server daemon
33
+ rake server:stop # Stop the server daemon
34
+ ```
35
+
36
+ If you wish to synthesize your tasks under a name other than 'server' you can provide a string when initializing the server task: `RakeUp::ServerTask.new("other_name")`.
37
+
38
+ ## Installation
39
+
40
+ To add RakeUp to your application, edit your Gemfile to import the RakeUp gem:
41
+
42
+ ```ruby
43
+ gem 'rakeup', '~> 1.0'
44
+ ```
45
+
46
+ And then edit your Rakefile to import the RakeUp library and configure your server tasks:
47
+
48
+ ```ruby
49
+ require 'rubygems'
50
+ require 'bundler/setup'
51
+ require 'rakeup'
52
+
53
+ RakeUp::ServerTask.new do |t|
54
+ t.port = 8558
55
+ t.pid_file = 'Tests/Server/server.pid'
56
+ t.rackup_file = 'Tests/Server/server.ru'
57
+ t.server = :thin # Or puma, mongrel, etc.
58
+ end
59
+ ```
60
+
61
+ ## Supported Web Servers
62
+
63
+ Any web server that is imported by your Gemfile and has a Rack handler available is available for execute. Commonly used servers are thin, mongrel, webrick, and puma. See `rakeup --help` for more examples.
64
+
65
+ ## Customizing the Tasks
66
+
67
+ At its core, RakeUp is simply a convenience wrapper around rackup commandline invocations. You can customize the rake tasks by overriding the run, start, stop, and restart commands when configuring the server:
68
+
69
+ ```ruby
70
+ RakeUp::ServerTask.new do |t|
71
+ t.port = 8558
72
+ t.pid_file = 'Tests/Server/server.pid'
73
+ t.rackup_file = 'Tests/Server/server.ru'
74
+ t.log_file = 'Tests/Server/server.log'
75
+
76
+ # Run Thin directly
77
+ t.run_command = "thin -r #{t.rackup_file} -P #{t.pid_file} -p #{t.port} start"
78
+ t.start_command = "thin -r #{t.rackup_file} -P #{t.pid_file} -p #{t.port} start -D"
79
+ t.stop_command = "thin -r #{t.rackup_file} -P #{t.pid_file} -p #{t.port} stop"
80
+ t.restart_command = "thin -r #{t.rackup_file} -P #{t.pid_file} -p #{t.port} restart"
81
+ end
82
+ ```
83
+
84
+ ## Contact
85
+
86
+ Blake Watters
87
+
88
+ - http://github.com/blakewatters
89
+ - http://twitter.com/blakewatters
90
+ - blakewatters@gmail.com
91
+
92
+ ## License
93
+
94
+ RakeUp is available under the Apache 2 License. See the LICENSE file for more info.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rakeup"
18
+ gem.homepage = "http://github.com/blakewatters/RakeUp"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Turn-key tasks for running a Rack based web server via Rake}
21
+ gem.description = %Q{RakeUp provides a set of tasks to automate the management of a local Rack based web application via Rake.}
22
+ gem.email = "blakewatters@gmail.com"
23
+ gem.authors = ["Blake Watters"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "restkit-gem #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/lib/rakeup.rb ADDED
@@ -0,0 +1 @@
1
+ require 'rakeup/server_task'
@@ -0,0 +1,174 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'rakeup/status'
4
+ require 'rakeup/shell'
5
+
6
+ module RakeUp
7
+ class ServerTask < Rake::TaskLib
8
+ include ::Rake::DSL if defined?(::Rake::DSL)
9
+
10
+ attr_accessor :name
11
+ attr_accessor :host
12
+ attr_accessor :port
13
+ attr_accessor :server
14
+ attr_accessor :pid_file
15
+ attr_accessor :rackup_file
16
+ attr_accessor :echo_commands
17
+ attr_accessor :rackup_bin
18
+
19
+ # Commands
20
+ attr_accessor :run_command
21
+ attr_accessor :start_command
22
+ attr_accessor :stop_command
23
+ attr_accessor :restart_command
24
+
25
+ def initialize(name = :server)
26
+ @name = name
27
+ @host = nil
28
+ @port = 4567
29
+ @pid_file = "tmp/#{name}.pid"
30
+ @rackup_file = "#{name}.ru"
31
+ @rackup_bin = "bundle exec rackup"
32
+ @server = "thin"
33
+ @echo_commands = true
34
+
35
+ yield self if block_given?
36
+ define_tasks
37
+ end
38
+
39
+ def rackup_command(options = nil)
40
+ [rackup_bin, "-s #{server}", host_option, "-p #{port}", "-P #{pid_file}", options, rackup_file].compact.join(' ')
41
+ end
42
+
43
+ def host_option
44
+ host && "-o #{host}"
45
+ end
46
+
47
+ def run_command
48
+ @run_command || rackup_command
49
+ end
50
+
51
+ def start_command
52
+ @start_command || rackup_command('-D')
53
+ end
54
+
55
+ def stop_command
56
+ @stop_command || "kill `cat #{pid_file}`"
57
+ end
58
+
59
+ def restart_command
60
+ @restart_command || "#{stop_command} && #{start_command}"
61
+ end
62
+
63
+ private
64
+ def define_tasks
65
+ RakeUp::Shell.echo_commands = @echo_commands
66
+
67
+ namespace name do
68
+ task :run do
69
+ if File.exists?(pid_file)
70
+ pid = File.read(pid_file).chomp
71
+ server_status = RakeUp::Status.new(pid, host, port)
72
+ server_status.check
73
+ if server_status.up?
74
+ $stderr.puts "Unable to run server: Existing process with pid #{server_status.pid} found listening on #{server_status.host}:#{server_status.port}"
75
+ exit(1)
76
+ end
77
+ end
78
+
79
+ # Cleanup the pid file on exit
80
+ at_exit { File.delete(pid_file) if File.exists?(pid_file) }
81
+
82
+ RakeUp::Shell.execute(run_command)
83
+ end
84
+
85
+ desc "Start the Test server daemon"
86
+ task :start do
87
+ unless RakeUp::Shell.execute(start_command)
88
+ puts "\033[0;31m!! Failed to start server (exit code: #{$?.exitstatus})"
89
+ exit($?.exitstatus)
90
+ end
91
+ end
92
+
93
+ desc "Stop the Test server daemon"
94
+ task :stop do
95
+ unless File.exists?(pid_file)
96
+ puts "\033[0;31m!! Unable to stop server: No pid file found at #{pid_file}"
97
+ exit(-1)
98
+ end
99
+
100
+ pid = File.read(pid_file).chomp
101
+ server_status = RakeUp::Status.new(pid, host, port)
102
+ server_status.check
103
+ if server_status.listening?
104
+ unless RakeUp::Shell.execute(stop_command)
105
+ puts "\033[0;31m!! Failed stopping server (exit code: #{$?.exitstatus})"
106
+ exit($?.exitstatus)
107
+ end
108
+ else
109
+ File.delete(pid_file)
110
+ end
111
+ end
112
+
113
+ desc "Restart the Test server daemon"
114
+ task :restart do
115
+ unless RakeUp::Shell.execute(restart_command)
116
+ puts "\033[0;31m!! Failed restarting server (exit code: #{$?.exitstatus})"
117
+ exit($?.exitstatus)
118
+ end
119
+ end
120
+
121
+ desc "Check the status of the Test server daemon"
122
+ task :status do
123
+ if File.exists?(pid_file)
124
+ pid = File.read(pid_file).chomp
125
+ else
126
+ pid = nil
127
+ end
128
+
129
+ server_status = RakeUp::Status.new(pid, host, port)
130
+ server_status.check
131
+ if server_status.listening?
132
+ puts server_status.to_s
133
+ else
134
+ $stderr.puts "!! No server found listening on #{server_status.host_and_port}"
135
+ end
136
+ end
137
+
138
+ desc "Abort the task chain unless the Test server is running"
139
+ task :abort_unless_running do
140
+ server_status = RakeUp::Status.new(nil, host, port)
141
+ server_status.check
142
+ unless server_status.listening?
143
+ $stderr.puts "!! Aborting: No server found listening on #{server_status.host_and_port}"
144
+ exit(-1)
145
+ end
146
+ end
147
+
148
+ desc "Starts the server if there is not already an instance running"
149
+ task :autostart do
150
+ server_status = RakeUp::Status.new(nil, host, port)
151
+ server_status.check
152
+ unless server_status.listening?
153
+ @auto_started = true
154
+ $stderr.puts "!! Auto-starting server: No server found listening on #{server_status.host_and_port}"
155
+ RakeUp::Shell.execute(start_command)
156
+ end
157
+ end
158
+
159
+ desc "Stops the server if executed via autostart"
160
+ task :autostop do
161
+ server_status = RakeUp::Status.new(nil, host, port)
162
+ server_status.check
163
+ if @auto_started && server_status.listening?
164
+ $stderr.puts "!! Stopping auto-started server listening on #{server_status.host_and_port}"
165
+ RakeUp::Shell.execute(stop_command)
166
+ end
167
+ end
168
+ end
169
+
170
+ desc 'Run the Test server in the foreground'
171
+ task name => ["#{name}:run"]
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,19 @@
1
+ module RakeUp
2
+ module Shell
3
+ class << self
4
+ # When true, commands will be echoed before execution
5
+ def echo_commands=(on_off)
6
+ @echo_commands = on_off
7
+ end
8
+
9
+ def echo_commands?
10
+ @echo_commands
11
+ end
12
+
13
+ def execute(command)
14
+ puts "Executing: `#{command}`" if echo_commands?
15
+ system(command)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,48 @@
1
+ require 'rakeup/utilities'
2
+
3
+ module RakeUp
4
+ class Status
5
+ attr_reader :pid, :host, :port
6
+
7
+ def initialize(pid, host, port)
8
+ @pid = pid
9
+ @host = host
10
+ @port = port
11
+ @process_check = Utilities::ProcessCheck.new(pid)
12
+ @port_check = Utilities::PortCheck.new(host, port)
13
+ end
14
+
15
+ def check
16
+ @process_check.run if pid
17
+ @port_check.run
18
+ end
19
+
20
+ def running?
21
+ pid && @process_check.running?
22
+ end
23
+
24
+ def listening?
25
+ @port_check.open?
26
+ end
27
+
28
+ def up?
29
+ running? && listening?
30
+ end
31
+
32
+ def host_and_port
33
+ "#{host}:#{port}"
34
+ end
35
+
36
+ def to_s
37
+ if up?
38
+ "Found server listening on #{host_and_port} (pid #{pid})"
39
+ else
40
+ if pid
41
+ [@process_check.to_s, @port_check.to_s].join("\n")
42
+ else
43
+ @port_check.to_s
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,2 @@
1
+ require 'rakeup/utilities/port_check'
2
+ require 'rakeup/utilities/process_check'
@@ -0,0 +1,54 @@
1
+ require 'socket'
2
+ require 'timeout'
3
+
4
+ module RakeUp
5
+ module Utilities
6
+ class PortCheck
7
+ attr_reader :host, :port, :error
8
+
9
+ def initialize(host, port)
10
+ @host = host
11
+ @port = port
12
+ end
13
+
14
+ def open?
15
+ @status == true
16
+ end
17
+
18
+ def closed?
19
+ @status == false
20
+ end
21
+
22
+ def run
23
+ @status = run_check
24
+ end
25
+
26
+ def to_s
27
+ if open?
28
+ "Found process listening on #{host}:#{port}"
29
+ else
30
+ "Unable to connect to process on #{host}:#{port}: #{error}"
31
+ end
32
+ end
33
+
34
+ private
35
+ def run_check
36
+ begin
37
+ Timeout::timeout(1) do
38
+ begin
39
+ s = TCPSocket.new(host, port)
40
+ s.close
41
+ return true
42
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH => error
43
+ @error = error
44
+ return false
45
+ end
46
+ end
47
+ rescue Timeout::Error => error
48
+ @error = error
49
+ return false
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,33 @@
1
+ module RakeUp
2
+ module Utilities
3
+ class ProcessCheck
4
+ attr_reader :pid, :error
5
+
6
+ def initialize(pid)
7
+ @pid = pid.to_i
8
+ end
9
+
10
+ def run
11
+ begin
12
+ info = Process.getpgid(pid)
13
+ @running = true
14
+ rescue Errno::ESRCH => error
15
+ @running = false
16
+ @error = error
17
+ end
18
+ end
19
+
20
+ def running?
21
+ @running
22
+ end
23
+
24
+ def to_s
25
+ if running?
26
+ "Found process running with pid #{pid}"
27
+ else
28
+ "Unable to find process with pid #{pid}: #{@error}"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
data/rakeup.gemspec ADDED
@@ -0,0 +1,77 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "rakeup"
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Blake Watters"]
12
+ s.date = "2013-05-15"
13
+ s.description = "RakeUp provides a set of tasks to automate the management of a local Rack based web application via Rake."
14
+ s.email = "blakewatters@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/rakeup.rb",
27
+ "lib/rakeup/server_task.rb",
28
+ "lib/rakeup/shell.rb",
29
+ "lib/rakeup/status.rb",
30
+ "lib/rakeup/utilities.rb",
31
+ "lib/rakeup/utilities/port_check.rb",
32
+ "lib/rakeup/utilities/process_check.rb",
33
+ "rakeup.gemspec"
34
+ ]
35
+ s.homepage = "http://github.com/blakewatters/RakeUp"
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = "1.8.25"
39
+ s.summary = "Turn-key tasks for running a Rack based web server via Rake"
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<rake>, ["~> 10.0.0"])
46
+ s.add_runtime_dependency(%q<rack>, ["~> 1.5.0"])
47
+ s.add_runtime_dependency(%q<puma>, ["~> 2.0.1"])
48
+ s.add_runtime_dependency(%q<thin>, ["~> 1.5.1"])
49
+ s.add_development_dependency(%q<rspec>, ["~> 2.13.0"])
50
+ s.add_development_dependency(%q<rdoc>, ["~> 4.0"])
51
+ s.add_development_dependency(%q<bundler>, ["~> 1.3.0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.0"])
53
+ s.add_development_dependency(%q<simplecov>, ["~> 0.7.0"])
54
+ else
55
+ s.add_dependency(%q<rake>, ["~> 10.0.0"])
56
+ s.add_dependency(%q<rack>, ["~> 1.5.0"])
57
+ s.add_dependency(%q<puma>, ["~> 2.0.1"])
58
+ s.add_dependency(%q<thin>, ["~> 1.5.1"])
59
+ s.add_dependency(%q<rspec>, ["~> 2.13.0"])
60
+ s.add_dependency(%q<rdoc>, ["~> 4.0"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.3.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.8.0"])
63
+ s.add_dependency(%q<simplecov>, ["~> 0.7.0"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<rake>, ["~> 10.0.0"])
67
+ s.add_dependency(%q<rack>, ["~> 1.5.0"])
68
+ s.add_dependency(%q<puma>, ["~> 2.0.1"])
69
+ s.add_dependency(%q<thin>, ["~> 1.5.1"])
70
+ s.add_dependency(%q<rspec>, ["~> 2.13.0"])
71
+ s.add_dependency(%q<rdoc>, ["~> 4.0"])
72
+ s.add_dependency(%q<bundler>, ["~> 1.3.0"])
73
+ s.add_dependency(%q<jeweler>, ["~> 1.8.0"])
74
+ s.add_dependency(%q<simplecov>, ["~> 0.7.0"])
75
+ end
76
+ end
77
+
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rakeup
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Blake Watters
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 10.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 10.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rack
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.5.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.5.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: puma
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.0.1
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.1
62
+ - !ruby/object:Gem::Dependency
63
+ name: thin
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.5.1
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.5.1
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 2.13.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 2.13.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: rdoc
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '4.0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '4.0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: bundler
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 1.3.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 1.3.0
126
+ - !ruby/object:Gem::Dependency
127
+ name: jeweler
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 1.8.0
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 1.8.0
142
+ - !ruby/object:Gem::Dependency
143
+ name: simplecov
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 0.7.0
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 0.7.0
158
+ description: RakeUp provides a set of tasks to automate the management of a local
159
+ Rack based web application via Rake.
160
+ email: blakewatters@gmail.com
161
+ executables: []
162
+ extensions: []
163
+ extra_rdoc_files:
164
+ - LICENSE
165
+ - README.md
166
+ files:
167
+ - Gemfile
168
+ - Gemfile.lock
169
+ - LICENSE
170
+ - README.md
171
+ - Rakefile
172
+ - VERSION
173
+ - lib/rakeup.rb
174
+ - lib/rakeup/server_task.rb
175
+ - lib/rakeup/shell.rb
176
+ - lib/rakeup/status.rb
177
+ - lib/rakeup/utilities.rb
178
+ - lib/rakeup/utilities/port_check.rb
179
+ - lib/rakeup/utilities/process_check.rb
180
+ - rakeup.gemspec
181
+ homepage: http://github.com/blakewatters/RakeUp
182
+ licenses:
183
+ - MIT
184
+ post_install_message:
185
+ rdoc_options: []
186
+ require_paths:
187
+ - lib
188
+ required_ruby_version: !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ! '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ segments:
195
+ - 0
196
+ hash: 468669248395576411
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ none: false
199
+ requirements:
200
+ - - ! '>='
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ requirements: []
204
+ rubyforge_project:
205
+ rubygems_version: 1.8.25
206
+ signing_key:
207
+ specification_version: 3
208
+ summary: Turn-key tasks for running a Rack based web server via Rake
209
+ test_files: []