Class: RSMP::CLI
- Inherits:
-
Thor
- Object
- Thor
- RSMP::CLI
- Defined in:
- lib/rsmp/cli.rb
Class Method Summary collapse
-
.exit_on_failure? ⇒ Boolean
avoid Thor returnin 0 on failures, see github.com/coinbase/salus/pull/380/files.
Instance Method Summary collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
avoid Thor returnin 0 on failures, see github.com/coinbase/salus/pull/380/files
190 191 192 |
# File 'lib/rsmp/cli.rb', line 190 def self.exit_on_failure? true end |
Instance Method Details
#convert ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/rsmp/cli.rb', line 168 def convert unless [:in] puts "Error: Input option missing" exit end unless [:out] puts "Error: Output option missing" exit end unless File.exist? [:in] puts "Error: Input path file #{[:in]} not found" exit end sxl = RSMP::Convert::Import::YAML.read [:in] RSMP::Convert::Export::JSONSchema.write sxl, [:out] end |
#site ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 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 |
# File 'lib/rsmp/cli.rb', line 19 def site settings = {} log_settings = { 'active' => true } if [:config] if File.exist? [:config] settings = YAML.load_file [:config] log_settings = settings.delete('log') || {} else puts "Error: Config #{[:config]} not found" exit end end if [:id] settings['site_id'] = [:id] end if [:supervisors] settings['supervisors'] = [] [:supervisors].split(',').each do |supervisor| ip, port = supervisor.split ':' ip = '127.0.0.1' if ip.empty? port = '12111' if port.empty? settings['supervisors'] << {"ip"=>ip, "port"=>port} end end if [:core] settings['core_version'] = [:core] end site_class = RSMP::Site site_type = [:type] || settings['type'] case site_type when 'tlc' site_class = RSMP::TLC::TrafficControllerSite else puts "Error: Unknown site type #{site_type}" exit end if [:log] log_settings['path'] = [:log] end if [:json] log_settings['json'] = [:json] end Async do |task| task.annotate 'cli' loop do begin site = site_class.new(site_settings: settings, log_settings: log_settings) site.start site.wait rescue Psych::SyntaxError => e puts "Cannot read config file #{e}" break rescue RSMP::Schema::UnknownSchemaTypeError => e puts "Cannot start site: #{e}" break rescue RSMP::Schema::UnknownSchemaVersionError => e puts "Cannot start site: #{e}" break rescue RSMP::ConfigurationError => e puts "Cannot start site: #{e}" break rescue RSMP::Restart site.stop end end end rescue Interrupt # cntr-c rescue Exception => e puts "Uncaught error: #{e}" puts caller.join("\n") end |
#supervisor ⇒ Object
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 163 |
# File 'lib/rsmp/cli.rb', line 108 def supervisor settings = {} log_settings = { 'active' => true } if [:config] if File.exist? [:config] settings = YAML.load_file [:config] log_settings = settings.delete 'log' else puts "Error: Config #{[:config]} not found" exit end end if [:id] settings['site_id'] = [:id] end if [:ip] settings['ip'] = [:ip] end if [:port] settings['port'] = [:port] end if [:core] settings['guest'] = {} settings['guest']['core_version'] = [:core] end if [:log] log_settings['path'] = [:log] end if [:json] log_settings['json'] = [:json] end Async do |task| task.annotate 'cli' supervisor = RSMP::Supervisor.new(supervisor_settings:settings,log_settings:log_settings) supervisor.start supervisor.wait rescue Psych::SyntaxError => e puts "Cannot read config file #{e}" rescue RSMP::Schema::UnknownSchemaTypeError => e puts "Cannot start supervisor: #{e}" rescue RSMP::Schema::UnknownSchemaVersionError => e puts "Cannot start supervisor: #{e}" rescue RSMP::ConfigurationError => e puts "Cannot start supervisor: #{e}" end rescue Interrupt # ctrl-c end |