vegas 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/README.rdoc +1 -1
- data/lib/vegas.rb +4 -3
- data/lib/vegas/runner.rb +57 -33
- data/test/test_app/test_app.rb +10 -0
- metadata +8 -21
- data/Manifest.txt +0 -10
- data/Rakefile +0 -31
data/History.txt
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
== 0.0.3 2009-07-06
|
2
|
+
|
3
|
+
* Vegas::Runner is now Windows compatible (require win32-process gem)
|
4
|
+
* Includes daemon-ization
|
5
|
+
* PID tracking
|
6
|
+
* Vegas::WINDOWS is a top level boolean
|
7
|
+
* Vegas is no longer dependent on Launchy
|
8
|
+
* launching browser is done simply with open/start depending on platform
|
9
|
+
|
1
10
|
== 0.0.1 2009-04-13
|
2
11
|
|
3
12
|
* 1 major enhancement:
|
data/README.rdoc
CHANGED
data/lib/vegas.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'sinatra'
|
3
|
-
require 'launchy'
|
4
3
|
|
5
4
|
$LOAD_PATH.unshift File.dirname(__FILE__)
|
6
5
|
|
7
6
|
module Vegas
|
8
|
-
VERSION = "0.0.
|
7
|
+
VERSION = "0.0.3"
|
8
|
+
WINDOWS = !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i)
|
9
9
|
|
10
10
|
autoload :Runner, 'vegas/runner'
|
11
|
-
end
|
11
|
+
end
|
12
|
+
|
data/lib/vegas/runner.rb
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
require 'logger'
|
3
3
|
|
4
|
+
if Vegas::WINDOWS
|
5
|
+
begin
|
6
|
+
require 'win32/process'
|
7
|
+
rescue
|
8
|
+
puts "Sorry, in order to use Vegas on Windows you need the win32-process gem:\n gem install win32-process"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
4
12
|
module Vegas
|
5
13
|
class Runner
|
6
14
|
attr_reader :app, :app_name, :rack_handler, :port, :host, :options
|
7
15
|
|
8
16
|
ROOT_DIR = File.expand_path(File.join('~', '.vegas'))
|
9
17
|
PORT = 5678
|
10
|
-
HOST = '0.0.0.0'
|
18
|
+
HOST = WINDOWS ? 'localhost' : '0.0.0.0'
|
11
19
|
|
12
20
|
def initialize(app, app_name, set_options = {}, &block)
|
13
21
|
# initialize
|
@@ -29,18 +37,19 @@ module Vegas
|
|
29
37
|
# initialize app dir
|
30
38
|
FileUtils.mkdir_p(app_dir)
|
31
39
|
|
32
|
-
logger.info "
|
40
|
+
logger.info "Running with Windows Settings" if WINDOWS
|
41
|
+
logger.info "Starting #{app_name}"
|
33
42
|
|
34
43
|
check_for_running
|
35
44
|
find_port
|
36
45
|
write_url
|
37
|
-
launch!
|
38
46
|
|
39
47
|
begin
|
48
|
+
launch!
|
40
49
|
daemonize! unless options[:foreground]
|
41
50
|
run!
|
42
51
|
rescue RuntimeError => e
|
43
|
-
logger.warn "
|
52
|
+
logger.warn "There was an error starting #{app_name}: #{e}"
|
44
53
|
exit
|
45
54
|
end
|
46
55
|
end
|
@@ -72,14 +81,14 @@ module Vegas
|
|
72
81
|
def find_port
|
73
82
|
if @port = options[:port]
|
74
83
|
if !port_open?
|
75
|
-
logger.warn "
|
84
|
+
logger.warn "Port #{port} is already in use. Please try another or don't use -P, for auto-port"
|
76
85
|
end
|
77
86
|
else
|
78
87
|
@port = PORT
|
79
|
-
logger.info "
|
88
|
+
logger.info "Trying to start #{app_name} on Port #{port}"
|
80
89
|
while !port_open?
|
81
90
|
@port += 1
|
82
|
-
logger.info "
|
91
|
+
logger.info "Trying to start #{app_name} on Port #{port}"
|
83
92
|
end
|
84
93
|
end
|
85
94
|
end
|
@@ -101,7 +110,7 @@ module Vegas
|
|
101
110
|
if File.exists?(pid_file) && File.exists?(url_file)
|
102
111
|
running_url = File.read(url_file)
|
103
112
|
if !port_open?(running_url)
|
104
|
-
logger.warn "
|
113
|
+
logger.warn "#{app_name} is already running at #{running_url}"
|
105
114
|
launch!(running_url)
|
106
115
|
exit!
|
107
116
|
end
|
@@ -110,10 +119,11 @@ module Vegas
|
|
110
119
|
|
111
120
|
def run!
|
112
121
|
rack_handler.run app, :Host => host, :Port => port do |server|
|
113
|
-
trap(
|
122
|
+
trap(kill_command) do
|
114
123
|
## Use thins' hard #stop! if available, otherwise just #stop
|
115
124
|
server.respond_to?(:stop!) ? server.stop! : server.stop
|
116
|
-
logger.info "
|
125
|
+
logger.info "#{app_name} received INT ... stopping"
|
126
|
+
delete_pid!
|
117
127
|
end
|
118
128
|
end
|
119
129
|
end
|
@@ -121,52 +131,54 @@ module Vegas
|
|
121
131
|
# Adapted from Rackup
|
122
132
|
def daemonize!
|
123
133
|
if RUBY_VERSION < "1.9"
|
124
|
-
|
125
|
-
|
126
|
-
|
134
|
+
logger.debug "Parent Process: #{Process.pid}"
|
135
|
+
exit! if fork
|
136
|
+
logger.debug "Child Process: #{Process.pid}"
|
127
137
|
Dir.chdir "/"
|
128
138
|
File.umask 0000
|
129
|
-
|
139
|
+
FileUtils.touch(log_file)
|
140
|
+
STDIN.reopen log_file
|
130
141
|
STDOUT.reopen log_file, "a"
|
131
142
|
STDERR.reopen log_file, "a"
|
132
143
|
else
|
133
144
|
Process.daemon
|
134
145
|
end
|
146
|
+
logger.debug "Child Process: #{Process.pid}"
|
135
147
|
|
136
|
-
File.open(pid_file, 'w'){
|
137
|
-
at_exit {
|
148
|
+
File.open(pid_file, 'w') {|f| f.write("#{Process.pid}") }
|
149
|
+
at_exit { delete_pid! }
|
138
150
|
end
|
139
151
|
|
140
152
|
def launch!(specific_url = nil)
|
141
|
-
Launchy.open(specific_url || url)
|
153
|
+
# Launchy.open(specific_url || url)
|
154
|
+
cmd = WINDOWS ? "start" : "sleep 2 && open"
|
155
|
+
system "#{cmd} #{specific_url || url}"
|
142
156
|
end
|
143
157
|
|
144
158
|
def kill!
|
145
159
|
pid = File.read(pid_file)
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
logger.warn "== pid not found at #{pid_file}"
|
151
|
-
end
|
160
|
+
logger.warn "Sending INT to #{pid.to_i}"
|
161
|
+
Process.kill(kill_command, pid.to_i)
|
162
|
+
rescue => e
|
163
|
+
logger.warn "pid not found at #{pid_file} : #{e}"
|
152
164
|
end
|
153
165
|
|
154
166
|
def status
|
155
167
|
if File.exists?(pid_file)
|
156
|
-
logger.info "
|
157
|
-
logger.info "
|
158
|
-
logger.info "
|
168
|
+
logger.info "#{app_name} running"
|
169
|
+
logger.info "PID #{File.read(pid_file)}"
|
170
|
+
logger.info "URL #{File.read(url_file)}" if File.exists?(url_file)
|
159
171
|
else
|
160
|
-
logger.info "
|
172
|
+
logger.info "#{app_name} not running!"
|
161
173
|
end
|
162
174
|
end
|
163
175
|
|
164
|
-
def self.logger
|
165
|
-
@logger ||= Logger.new(STDOUT)
|
166
|
-
end
|
167
|
-
|
168
176
|
def logger
|
169
|
-
|
177
|
+
return @logger if @logger
|
178
|
+
@logger = Logger.new(STDOUT)
|
179
|
+
@logger.level = options[:debug] ? Logger::DEBUG : Logger::INFO
|
180
|
+
@logger.formatter = Proc.new {|s, t, n, msg| "[#{t}] #{msg}\n"}
|
181
|
+
@logger
|
170
182
|
end
|
171
183
|
|
172
184
|
private
|
@@ -206,6 +218,10 @@ module Vegas
|
|
206
218
|
status
|
207
219
|
exit!
|
208
220
|
}
|
221
|
+
|
222
|
+
opts.on('-d', "--debug", "raise the log level to :debug (default: :info)") {|s|
|
223
|
+
@options[:debug] = true
|
224
|
+
}
|
209
225
|
|
210
226
|
yield opts if block_given?
|
211
227
|
|
@@ -228,9 +244,17 @@ module Vegas
|
|
228
244
|
|
229
245
|
opts.parse! ARGV
|
230
246
|
}
|
247
|
+
rescue OptionParser::MissingArgument => e
|
248
|
+
logger.warn "#{e}, run -h for options"
|
249
|
+
exit
|
231
250
|
end
|
232
251
|
|
252
|
+
def kill_command
|
253
|
+
WINDOWS ? 1 : :INT
|
254
|
+
end
|
233
255
|
|
234
|
-
|
256
|
+
def delete_pid!
|
257
|
+
File.delete(pid_file) if File.exist?(pid_file)
|
258
|
+
end
|
235
259
|
end
|
236
260
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vegas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Quint
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-06 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,16 +22,6 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 0.9.1
|
24
24
|
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: launchy
|
27
|
-
type: :runtime
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.3.3
|
34
|
-
version:
|
35
25
|
- !ruby/object:Gem::Dependency
|
36
26
|
name: newgem
|
37
27
|
type: :development
|
@@ -81,22 +71,18 @@ extensions: []
|
|
81
71
|
|
82
72
|
extra_rdoc_files:
|
83
73
|
- History.txt
|
84
|
-
- Manifest.txt
|
85
74
|
- README.rdoc
|
86
75
|
files:
|
87
76
|
- History.txt
|
88
77
|
- LICENSE
|
89
|
-
- Manifest.txt
|
90
78
|
- README.rdoc
|
91
|
-
- Rakefile
|
92
79
|
- lib/vegas.rb
|
93
80
|
- lib/vegas/runner.rb
|
94
|
-
- test/test_apps.rb
|
95
|
-
- test/test_helper.rb
|
96
|
-
- test/test_vegas_runner.rb
|
97
81
|
has_rdoc: true
|
98
82
|
homepage: http://code.quirkey.com/vegas
|
99
|
-
|
83
|
+
licenses: []
|
84
|
+
|
85
|
+
post_install_message:
|
100
86
|
rdoc_options:
|
101
87
|
- --main
|
102
88
|
- README.rdoc
|
@@ -117,11 +103,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
103
|
requirements: []
|
118
104
|
|
119
105
|
rubyforge_project: quirkey
|
120
|
-
rubygems_version: 1.3.
|
106
|
+
rubygems_version: 1.3.3
|
121
107
|
signing_key:
|
122
|
-
specification_version:
|
108
|
+
specification_version: 3
|
123
109
|
summary: Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps.
|
124
110
|
test_files:
|
111
|
+
- test/test_app/test_app.rb
|
125
112
|
- test/test_apps.rb
|
126
113
|
- test/test_helper.rb
|
127
114
|
- test/test_vegas_runner.rb
|
data/Manifest.txt
DELETED
data/Rakefile
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
-
require File.dirname(__FILE__) + '/lib/vegas'
|
3
|
-
|
4
|
-
# Generate all the Rake tasks
|
5
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
-
$hoe = Hoe.new('vegas', Vegas::VERSION) do |p|
|
7
|
-
p.developer('Aaron Quint', 'aaron@quirkey.com')
|
8
|
-
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
-
p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
10
|
-
p.rubyforge_name = 'quirkey'
|
11
|
-
p.extra_deps = [
|
12
|
-
['sinatra','>= 0.9.1'],
|
13
|
-
['launchy','>= 0.3.3']
|
14
|
-
]
|
15
|
-
p.extra_dev_deps = [
|
16
|
-
['newgem', ">= #{::Newgem::VERSION}"],
|
17
|
-
['nokogiri', ">= 1.0.6"],
|
18
|
-
['bacon', ">= 1.1.0"]
|
19
|
-
]
|
20
|
-
|
21
|
-
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
22
|
-
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
23
|
-
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
24
|
-
p.rsync_args = '-av --delete --ignore-errors'
|
25
|
-
end
|
26
|
-
|
27
|
-
require 'newgem/tasks' # load /tasks/*.rake
|
28
|
-
Dir['tasks/**/*.rake'].each { |t| load t }
|
29
|
-
|
30
|
-
# TODO - want other tests/tasks run by default? Add them to the list
|
31
|
-
# task :default => [:spec, :features]
|