Class: ReliableMsg::CLI
- Inherits:
-
Object
- Object
- ReliableMsg::CLI
- Defined in:
- lib/reliable-msg/cli.rb
Overview
:nodoc:
Defined Under Namespace
Classes: InvalidUsage
Constant Summary collapse
- USAGE =
"usage: queues [-c config] command [args]\n\nTo see list of available commands and options\n queues help\n"- HELP =
"usage: queues [-c config] command [args]\n\nReliable messaging queue manager, version \#{VERSION}\n\nAvailable commands:\n\nhelp\n Display this help message.\n\nmanager start\n Start the queue manager as a standalone server\n\nmanager stop\n Stop a running queue manager.\n\ninstall disk [<path>]\n Configure queue manager to use disk-based message store\n using the specified directory. Uses 'queues' by default.\n\ninstall mysql <host> <username> <password> <database> [options]\n [--port <port>] [--socket <socket>] [--prefix <prefix>]\n Configure queue manager to use MySQL for message store,\n using the specified connection properties. Updates database\n schema.\n\nOptions for install mysql are (defaults apply if missing):\n\n--port Port to connect to\n--socket Socket to connect to\n--prefix Prefix for table names\n\n"
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
67 68 |
# File 'lib/reliable-msg/cli.rb', line 67 def initialize end |
Instance Method Details
#run ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/reliable-msg/cli.rb', line 70 def run begin config_file = nil opts = OptionParser.new opts.on("-c FILE", "--config FILE", String) { |value| config_file = value } opts.on("-v", "--version") do puts "Reliable messaging queue manager, version #{VERSION}" exit end opts.on("-h", "--help") do puts HELP exit end args = opts.parse(ARGV) raise InvalidUsage if args.length < 1 case args[0] when 'help' puts HELP when 'manager' case args[1] when 'start', nil manager = QueueManager.new({:config=>config_file}) manager.start begin while manager.alive? sleep 3 end rescue Interrupt manager.stop end when 'stop' if config_file config = Config.new config_file, nil unless config.load_no_create || config_file.nil? puts "Could not find configuration file #{config.path}" exit end drb = Config::DEFAULT_DRB drb.merge(config.drb) if config.drb drb_uri = "druby://localhost:#{drb['port']}" else drb_uri = Queue::DEFAULT_DRB end begin DRbObject.new(nil, drb_uri).stop rescue DRb::DRbConnError =>error puts "No queue manager at #{drb_uri}" end else raise InvalidUsage end when 'install' config = Config.new config_file, nil case args[1] when 'disk' store = MessageStore::Disk.new({}, nil) config.store = store.configuration if config.create_if_none store.setup puts "Created queues configuration file: #{config.path}" else puts "Found existing queues configuration file: #{config.path}" puts "No changes made" end when 'mysql' host, username, password, database = args[2], args[3], args[4], args[5] raise InvalidUsage unless host && database && username && password conn = { "host"=>host, "username"=>username, "password"=>password, "database"=>database } store = MessageStore::MySQL.new(conn, nil) config.store = store.configuration if config.create_if_none puts "Created queues configuration file: #{config.path}" if store.setup puts "Created queue manager tables in database '#{database}'" end else puts "Found existing queues configuration file: #{config.path}" puts "No changes made" end else raise InvalidUsage end else raise InvalidUsage end rescue InvalidUsage puts USAGE end end |