Class: SensuGenerator::SensuServer
- Inherits:
-
Object
- Object
- SensuGenerator::SensuServer
- Defined in:
- lib/sensu_generator/sensu_server.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#config ⇒ Object
Returns the value of attribute config.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(address:, config: Application.config, logger: Application.logger) ⇒ SensuServer
constructor
A new instance of SensuServer.
- #process ⇒ Object
- #restart ⇒ Object
- #running? ⇒ Boolean
- #state ⇒ Object
- #sync ⇒ Object
Constructor Details
#initialize(address:, config: Application.config, logger: Application.logger) ⇒ SensuServer
Returns a new instance of SensuServer.
9 10 11 12 13 |
# File 'lib/sensu_generator/sensu_server.rb', line 9 def initialize(address:, config: Application.config, logger: Application.logger) @address = address @config = config @logger = logger end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
6 7 8 |
# File 'lib/sensu_generator/sensu_server.rb', line 6 def address @address end |
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/sensu_generator/sensu_server.rb', line 7 def config @config end |
#logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/sensu_generator/sensu_server.rb', line 7 def logger @logger end |
Instance Method Details
#process ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sensu_generator/sensu_server.rb', line 15 def process unless @process client = RubySupervisor::Client.new(address, 9001, user: config.get[:sensu][:supervisor][:user], password: config.get[:sensu][:supervisor][:password] ) @process = client.process('sensu-server') end @process end |
#restart ⇒ Object
26 27 28 29 30 |
# File 'lib/sensu_generator/sensu_server.rb', line 26 def restart process.restart logger.info "Send restart command to sensu-server #{address}" running? end |
#running? ⇒ Boolean
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sensu_generator/sensu_server.rb', line 32 def running? 10.times do |t| logger.info "Trying to restart server #{address}. Attempt=#{t}." if process.state.to_s == 'running' logger.info "Sensu-server #{address} was successfully restarted" return true else sleep 1 if t == 10 raise SensuServerError, "Sensu-server #{address} restart FAILED" end end end rescue SensuServerError false end |
#state ⇒ Object
49 50 51 |
# File 'lib/sensu_generator/sensu_server.rb', line 49 def state process.state end |
#sync ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sensu_generator/sensu_server.rb', line 53 def sync begin res = Rsync.run("#{config.result_dir}/", "rsync://#{address}/#{config.get[:sensu][:rsync_repo]}", "--delete --recursive") status = res.success? if status msg = "synced" logger.info "Sensu-server #{address}: #{msg}" else msg = "sync FAILED, out: #{res.inspect}" raise SensuServerError, "Sensu-server #{address}: #{msg}" end rescue SensuServerError status = false end status end |