rv 2.9 → 2.99
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/CHANGELOG +1 -1
- data/Manifest +1 -0
- data/README +10 -3
- data/TODO +4 -0
- data/bin/rv +5 -2
- data/lib/rv.rb +48 -21
- data/lib/rv_harness.rb +2 -1
- metadata +3 -2
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
data/README
CHANGED
@@ -22,10 +22,10 @@ First, run:
|
|
22
22
|
sudo gem install rv
|
23
23
|
sudo rv install
|
24
24
|
|
25
|
-
|
25
|
+
This copies a very small script to <tt>/etc/init.d/rv</tt>. <b>Edit it and change the <tt>'user'</tt> keypair in the file if your app user is not <tt>httpd</tt>.</b> There are a few other options you can set; see the Rv class for details.
|
26
26
|
|
27
27
|
Now, install it as a boot service. On Ubuntu, run:
|
28
|
-
sudo /usr/sbin/update-rc.d
|
28
|
+
sudo /usr/sbin/update-rc.d rv defaults
|
29
29
|
|
30
30
|
On Gentoo, run:
|
31
31
|
sudo rc-update add rv default
|
@@ -37,8 +37,15 @@ Each Camping app should live in its own directory. Traverse to this directory an
|
|
37
37
|
|
38
38
|
It will now start at boot. You can start it manually (along with your other Rv apps) by running:
|
39
39
|
sudo /etc/init.d/rv start
|
40
|
+
|
41
|
+
The script also responds to <tt>status</tt>, <tt>restart</tt>, and <tt>stop</tt>.
|
42
|
+
|
43
|
+
== Troubleshooting
|
40
44
|
|
41
|
-
|
45
|
+
If you're having problems, run:
|
46
|
+
RV_DEBUG=true sudo /etc/init.d/rv start
|
47
|
+
|
48
|
+
Copy out the inner command (between the '<tt>nohup su -c "</tt>' and the first '<tt>< /dev/null...</tt>') and try running it by hand. Make sure you're using the correct user. You can also check <tt>/var/log/rv.log</tt> as well as the application log.
|
42
49
|
|
43
50
|
== Apache configuration
|
44
51
|
|
data/TODO
ADDED
data/bin/rv
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
=begin rdoc
|
4
|
-
Executable for running Rv.
|
5
|
-
|
4
|
+
Executable for running Rv.
|
5
|
+
|
6
|
+
Accepts <tt>start</tt>, <tt>restart</tt>, <tt>stop</tt>, <tt>status</tt>, <tt>setup</tt> and <tt>install</tt> as command-line parameters.
|
7
|
+
|
8
|
+
See the Rv class for a list options which can be passed to Rv.new, below.
|
6
9
|
=end
|
7
10
|
|
8
11
|
require 'rubygems'
|
data/lib/rv.rb
CHANGED
@@ -3,14 +3,25 @@ require 'yaml'
|
|
3
3
|
require 'ftools'
|
4
4
|
require 'highline/import'
|
5
5
|
|
6
|
-
|
6
|
+
=begin rdoc
|
7
|
+
This class implements all the functionality of Rv. You shouldn't need to use this class directly, rather, use the <tt>rv</tt> executable. However, you may want to override some of the keys in the DEFAULT hash by passing them to Rv.new in the executable.
|
8
|
+
|
9
|
+
Available keys are:
|
10
|
+
* <tt>'conf_dir'</tt> - the directory of the YAML configuration files.
|
11
|
+
* <tt>'user'</tt> - the system user used to start the apps.
|
12
|
+
* <tt>'max_tries'</tt> - the number of retries before giving up on an app (each try takes a half second).
|
13
|
+
* <tt>'log'</tt> - the path to Rv's own logfile.
|
14
|
+
* <tt>'ruby'</tt> - a string used to start the Ruby interpreter.
|
15
|
+
|
16
|
+
=end
|
17
|
+
|
7
18
|
class Rv
|
8
19
|
|
9
20
|
class << self
|
10
21
|
|
11
22
|
# Get an Rv parameter from the process environment variables.
|
12
|
-
def env(key)
|
13
|
-
value = ENV["#{
|
23
|
+
def env(key) #:nodoc:
|
24
|
+
value = ENV["RV_#{key.upcase}"]
|
14
25
|
raise "Rv key #{key} not found" unless value
|
15
26
|
|
16
27
|
if value == value.to_i.to_s
|
@@ -21,14 +32,14 @@ class Rv
|
|
21
32
|
end
|
22
33
|
|
23
34
|
# Turn an underscored name into a class reference.
|
24
|
-
def classify(string)
|
35
|
+
def classify(string) #:nodoc:
|
25
36
|
eval("::" + string.split("_").map do |word|
|
26
37
|
word.capitalize
|
27
38
|
end.join)
|
28
39
|
end
|
29
40
|
|
30
41
|
# Get the canonical pid_file name.
|
31
|
-
def pid_file(app = nil, port = nil)
|
42
|
+
def pid_file(app = nil, port = nil) #:nodoc:
|
32
43
|
"#{app || env('app')}.#{port || env('port')}.pid"
|
33
44
|
end
|
34
45
|
|
@@ -37,12 +48,11 @@ class Rv
|
|
37
48
|
DEFAULTS = {
|
38
49
|
'user' => 'httpd',
|
39
50
|
'ruby' => '/usr/bin/env ruby',
|
40
|
-
'pidfile' => 'application.pid',
|
41
51
|
'conf_dir' => '/etc/rv',
|
42
|
-
'harness' => 'rv_harness.rb',
|
43
52
|
'log' => '/var/log/rv.log',
|
44
|
-
'null_stream' =>
|
45
|
-
'log_stream' =>
|
53
|
+
'null_stream' => '< /dev/null > /dev/null 2>&1',
|
54
|
+
'log_stream' => '< /dev/null >> #{LOG} 2>&1',
|
55
|
+
'max_tries' => 10
|
46
56
|
}
|
47
57
|
|
48
58
|
VALID_ACTIONS = ['start', 'restart', 'stop', 'status', 'setup', 'install']
|
@@ -55,7 +65,7 @@ class Rv
|
|
55
65
|
raise "Invalid options #{extra_keys.join(', ')}" if extra_keys.any?
|
56
66
|
|
57
67
|
@options = DEFAULTS.merge(opts)
|
58
|
-
options['log_stream'].sub!(
|
68
|
+
options['log_stream'].sub!('#{LOG}', options['log'])
|
59
69
|
|
60
70
|
# make sure the log exists
|
61
71
|
begin
|
@@ -89,6 +99,8 @@ class Rv
|
|
89
99
|
|
90
100
|
end
|
91
101
|
|
102
|
+
private
|
103
|
+
|
92
104
|
# Runs a daemon action. Only called from <tt>perform</tt>.
|
93
105
|
def daemon(action, match)
|
94
106
|
filenames = Dir["#{options['conf_dir']}/#{match}.yml"]
|
@@ -107,8 +119,8 @@ class Rv
|
|
107
119
|
config = real_config.dup
|
108
120
|
@port = config['port'] += cluster_index
|
109
121
|
|
110
|
-
|
111
|
-
pid = File.open(
|
122
|
+
pid_file = Rv.pid_file(config['app'], config['port'])
|
123
|
+
pid = File.open(pid_file).readlines.first.chomp rescue nil
|
112
124
|
running = pid ? `ps -p #{pid}`.split("\n")[1] : nil
|
113
125
|
|
114
126
|
case action
|
@@ -127,20 +139,27 @@ class Rv
|
|
127
139
|
note "stopped"
|
128
140
|
elsif pid
|
129
141
|
note "not running"
|
130
|
-
File.delete
|
142
|
+
File.delete pid_file
|
131
143
|
else
|
132
|
-
note "pid file #{
|
144
|
+
note "pid file #{pid_file.inspect} not found. Application was probably not running."
|
133
145
|
end
|
134
146
|
when "start"
|
135
147
|
unless running
|
136
148
|
env_variables = config.map {|key, value| "RV_#{key.upcase}=#{value}"}.join(" ")
|
137
149
|
system %[nohup su -c "#{env_variables} #{options['ruby']} #{options['harness']} #{options['null_stream']}" #{options['user']} #{options['log_stream']} &]
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
150
|
+
|
151
|
+
# wait for the app to initialize
|
152
|
+
tries = 0
|
153
|
+
begin
|
154
|
+
sleep(0.5)
|
155
|
+
tries += 1
|
156
|
+
end while tries < options['max_tries'] and !File.exist?(pid_file)
|
157
|
+
if File.exist?(pid_file)
|
158
|
+
note "started"
|
159
|
+
else
|
142
160
|
note "failed to start"
|
143
161
|
end
|
162
|
+
|
144
163
|
else
|
145
164
|
note "already running"
|
146
165
|
end
|
@@ -158,11 +177,13 @@ class Rv
|
|
158
177
|
harness_source = "#{File.dirname(__FILE__)}/rv_harness.rb"
|
159
178
|
harness_target = "#{this_dir}/rv_harness.rb"
|
160
179
|
|
161
|
-
|
180
|
+
if !File.exist?(harness_target) or
|
181
|
+
(File.open(harness_target).readlines[2] != File.open(harness_source).readlines[2] and
|
182
|
+
agree("rv_harness.rb is out-of-date; overwrite? "))
|
162
183
|
puts "Installing rv_harness.rb file."
|
163
184
|
File.copy harness_source, harness_target
|
164
185
|
else
|
165
|
-
puts "rv_harness.rb
|
186
|
+
puts "rv_harness.rb not changed."
|
166
187
|
end
|
167
188
|
|
168
189
|
defaults = {
|
@@ -212,7 +233,7 @@ class Rv
|
|
212
233
|
exit_with "Couldn't write to '#{options['conf_dir']}'. Please rerun with 'sudo'."
|
213
234
|
end
|
214
235
|
|
215
|
-
exit_with "All done. Please double-check the database configuration in '
|
236
|
+
exit_with "All done. Please double-check the database configuration in 'rv_harness.rb';\nthen run 'sudo /etc/init.d/rv start'."
|
216
237
|
end
|
217
238
|
|
218
239
|
# Installs the 'rv' executable into /etc/init.d.
|
@@ -221,6 +242,7 @@ class Rv
|
|
221
242
|
bin_target = "/etc/init.d/rv"
|
222
243
|
begin
|
223
244
|
File.copy bin_source, bin_target
|
245
|
+
system("chmod u+x #{bin_target}")
|
224
246
|
rescue Errno::EACCES
|
225
247
|
exit_with "Couldn't write to '#{bin_target}'. Please rerun with 'sudo'."
|
226
248
|
end
|
@@ -238,5 +260,10 @@ class Rv
|
|
238
260
|
puts " #{msg.capitalize} (#{@port})"
|
239
261
|
end
|
240
262
|
|
263
|
+
# system() with debugging output
|
264
|
+
def system(string)
|
265
|
+
$stderr.puts string if ENV['RV_DEBUG']
|
266
|
+
super
|
267
|
+
end
|
241
268
|
|
242
269
|
end
|
data/lib/rv_harness.rb
CHANGED
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rv
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "2.
|
6
|
+
version: "2.99"
|
7
7
|
date: 2007-08-06 00:00:00 -04:00
|
8
8
|
summary: A little init.d system for running Camping apps.
|
9
9
|
require_paths:
|
@@ -11,7 +11,7 @@ require_paths:
|
|
11
11
|
email: ""
|
12
12
|
homepage: http://blog.evanweaver.com/pages/code#rv
|
13
13
|
rubyforge_project: fauna
|
14
|
-
description:
|
14
|
+
description: A little init.d system for running Camping apps.
|
15
15
|
autorequire:
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|
@@ -32,6 +32,7 @@ files:
|
|
32
32
|
- lib/rv_harness.rb
|
33
33
|
- lib/rv.rb
|
34
34
|
- bin/rv
|
35
|
+
- TODO
|
35
36
|
- Rakefile
|
36
37
|
- README
|
37
38
|
- Manifest
|