Class: Rv

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 the env utility.
  • ‘ruby‘ - the name of the Ruby interpreter.

Constants

NameValue
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']

Attributes

NameRead/write?
options RW

Public Class Methods


new (opts = {})

Create an Rv instance. You can pass an optional hash to override any key in DEFAULTS.

    # File lib/rv.rb, line 66
66:   def initialize(opts = {})
67:     extra_keys = opts.keys - DEFAULTS.keys
68:     raise "Invalid options #{extra_keys.join(', ')}" if extra_keys.any?    
69: 
70:     @options = DEFAULTS.merge(opts)
71:     options['log_stream'].sub!('#{LOG}', options['log'])
72:     
73:     # make sure the log exists
74:     begin 
75:       unless File.exist? options['log']
76:         File.open(options['log'], "w") {}
77:       end
78:     rescue Errno::EACCES
79:       exit_with "Couldn't write to logfile '#{options['log']}'"
80:     end
81:     system "chown #{options['user']} #{options['log']} #{options['null_stream']}"
82:     system "chgrp #{options['user']} #{options['log']} #{options['null_stream']}"
83:   end

Public Instance Methods


perform (action, match = '*')

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.

     # File lib/rv.rb, line 86
 86:   def perform(action, match = '*')
 87:     exit_with "No action given." unless action
 88:     exit_with "Invalid action '#{action}'." unless VALID_ACTIONS.include? action
 89:     
 90:     case action 
 91:       when "restart"
 92:         daemon("stop", match)
 93:         sleep(5) # wait for the sockets to get released
 94:         daemon("start", match)
 95:       when "install"
 96:         install
 97:       when "setup"
 98:         setup
 99:       else
100:         daemon(action, match)
101:     end
102:     
103:   end