Class: Rv
- Inherits:
-
Object
- Object
- Rv
- Defined in:
- lib/rv.rb
Overview
This class implements all the functionality of Rv. You shouldn’t need to use this class directly, rather, use the rv
executable. However, you may want to override some of the keys in the DEFAULT hash by passing them to Rv.new in the executable.
Available keys are:
-
'conf_dir'
- the directory of the YAML configuration files. -
'user'
- the system user used to start the apps. -
'max_tries'
- the number of retries before giving up on an app (each try takes a half second). -
'log'
- the path to Rv’s own logfile. -
'env'
- the path to theenv
utility. -
'ruby'
- the name of the Ruby interpreter.
Constant Summary collapse
- DEFAULTS =
{ 'user' => 'httpd', 'env' => '/usr/bin/env', 'ruby' => 'ruby', 'conf_dir' => '/etc/rv', 'log' => '/var/log/rv.log', 'harness' => 'rv_harness.rb', 'null_stream' => '< /dev/null > /dev/null 2>&1', 'log_stream' => '< /dev/null >> #{LOG} 2>&1', 'max_tries' => 10 }
- VALID_ACTIONS =
['start', 'restart', 'stop', 'status', 'setup', 'install']
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
-
.classify(string) ⇒ Object
Turn an underscored name into a class reference.
-
.env(key) ⇒ Object
Get an Rv parameter from the process environment variables.
-
.pid_file(app = nil, port = nil) ⇒ Object
Get the canonical pid_file name.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Rv
constructor
Create an Rv instance.
-
#perform(action, match = '*') ⇒ Object
Perform any action in VALID_ACTIONS.
Constructor Details
#initialize(opts = {}) ⇒ Rv
Create an Rv instance. You can pass an optional hash to override any key in DEFAULTS.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rv.rb', line 66 def initialize(opts = {}) extra_keys = opts.keys - DEFAULTS.keys raise "Invalid options #{extra_keys.join(', ')}" if extra_keys.any? @options = DEFAULTS.merge(opts) ['log_stream'].sub!('#{LOG}', ['log']) # make sure the log exists begin unless File.exist? ['log'] File.open(['log'], "w") {} end rescue Errno::EACCES exit_with "Couldn't write to logfile '#{['log']}'" end system "chown #{['user']} #{['log']} #{['null_stream']}" system "chgrp #{['user']} #{['log']} #{['null_stream']}" end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
63 64 65 |
# File 'lib/rv.rb', line 63 def @options end |
Class Method Details
.classify(string) ⇒ Object
Turn an underscored name into a class reference.
36 37 38 39 40 |
# File 'lib/rv.rb', line 36 def classify(string) #:nodoc: eval("::" + string.split("_").map do |word| word.capitalize end.join) end |
.env(key) ⇒ Object
Get an Rv parameter from the process environment variables.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rv.rb', line 24 def env(key) #:nodoc: value = ENV["RV_#{key.upcase}"] raise "Rv key #{key} not found" unless value if value == value.to_i.to_s value.to_i else value end end |
.pid_file(app = nil, port = nil) ⇒ Object
Get the canonical pid_file name.
43 44 45 |
# File 'lib/rv.rb', line 43 def pid_file(app = nil, port = nil) #:nodoc: "#{app || env('app')}.#{port || env('port')}.pid" end |
Instance Method Details
#perform(action, match = '*') ⇒ Object
Perform any action in VALID_ACTIONS. Defaults to running against all applications. Pass a specific app name as match
if this is not what you want.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rv.rb', line 86 def perform(action, match = '*') exit_with "No action given." unless action exit_with "Invalid action '#{action}'." unless VALID_ACTIONS.include? action case action when "restart" daemon("stop", match) sleep(5) # wait for the sockets to get released daemon("start", match) when "install" install when "setup" setup else daemon(action, match) end end |