Parent

Daemons::Controller

Constants

COMMANDS

Attributes

app_name[R]
group[R]
options[R]

Public Class Methods

new(options = {}, argv = []) click to toggle source
    # File lib/daemons/controller.rb, line 22
22:     def initialize(options = {}, argv = [])
23:       @options = options
24:       @argv = argv
25:       
26:       # Allow an app_name to be specified. If not specified use the
27:       # basename of the script.
28:       @app_name = options[:app_name]
29:       
30:       if options[:script]
31:         @script = File.expand_path(options[:script])
32:     
33:         @app_name ||= File.split(@script)[1]
34:       end
35:     
36:       @app_name ||= 'unknown_application'
37:       
38:       @command, @controller_part, @app_part = Controller.split_argv(argv)
39:     
40:       #@options[:dir_mode] ||= :script
41:     
42:       @optparse = Optparse.new(self)
43:     end
split_argv(argv) click to toggle source

Split an argv array. argv is assumed to be in the following format:

  ['command', 'controller option 1', 'controller option 2', ..., '--', 'app option 1', ...]

command must be one of the commands listed in COMMANDS

Returns: the command as a string, the controller options as an array, the appliation options as an array

     # File lib/daemons/controller.rb, line 116
116:     def Controller.split_argv(argv)
117:       argv = argv.dup
118:       
119:       command = nil
120:       controller_part = []
121:       app_part = []
122:        
123:       if COMMANDS.include? argv[0]
124:         command = argv.shift
125:       end
126:       
127:       if i = argv.index('--')
128:         # Handle the case where no controller options are given, just
129:         # options after "--" as well (i == 0)
130:         controller_part = (i == 0 ? [] : argv[0..i-1])
131:         app_part = argv[i+1..1]
132:       else
133:         controller_part = argv[0..1]
134:       end
135:        
136:       return command, controller_part, app_part
137:     end

Public Instance Methods

catch_exceptions(&block) click to toggle source
     # File lib/daemons/cmdline.rb, line 110
110:     def catch_exceptions(&block)
111:       begin
112:         block.call
113:       rescue CmdException, OptionParser::ParseError => e
114:         puts "ERROR: #{e.to_s}"
115:         puts
116:         print_usage()
117:       rescue RuntimeException => e
118:         puts "ERROR: #{e.to_s}"
119:       end
120:     end
run() click to toggle source
     # File lib/daemons/controller.rb, line 55
 55:     def run
 56:       @options.update @optparse.parse(@controller_part).delete_if {|k,v| !v}
 57:       
 58:       setup_options()
 59:       
 60:       #pp @options
 61: 
 62:       @group = ApplicationGroup.new(@app_name, @options)
 63:       @group.controller_argv = @controller_part
 64:       @group.app_argv = @app_part
 65:       
 66:       @group.setup
 67:       
 68:       case @command
 69:         when 'start'
 70:           @group.new_application.start
 71:         when 'run'
 72:           @options[:ontop] ||= true
 73:           @group.new_application.start
 74:         when 'stop'
 75:           @group.stop_all(@options[:no_wait])
 76:         when 'restart'
 77:           unless @group.applications.empty?
 78:             @group.stop_all
 79:             sleep(1)
 80:             @group.start_all
 81:           else
 82:             puts "Warning: no instances running. Starting..."
 83:             @group.new_application.start
 84:           end
 85:         when 'reload'
 86:           @group.reload_all
 87:         when 'zap'
 88:           @group.zap_all
 89:         when 'status'
 90:           unless @group.applications.empty?
 91:             @group.show_status
 92:           else
 93:             puts "#{@group.app_name}: no instances running"
 94:           end
 95:         when nil
 96:           raise CmdException.new('no command given')
 97:           #puts "ERROR: No command given"; puts
 98:           
 99:           #print_usage()
100:           #raise('usage function not implemented')
101:         else
102:           raise Error.new("command '#{@command}' not implemented")
103:       end
104:     end
setup_options() click to toggle source

This function is used to do a final update of the options passed to the application before they are really used.

Note that this function should only update @options and no other variables.

    # File lib/daemons/controller.rb, line 51
51:     def setup_options
52:       #@options[:ontop] ||= true
53:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.