Method: RightScale::InstanceState.shutdown
- Defined in:
- lib/instance/instance_state.rb
.shutdown(user_id, skip_db_update, kind) ⇒ Object
Ask core agent to shut ourselves down for soft termination Do not specify the last recorded state since does not matter at this point and no need to risk request failure Add a timer to force shutdown if do not hear back from the cloud or the request hangs
Parameters
- user_id(Integer)
-
ID of user that triggered soft-termination
- skip_db_update(Boolean)
-
Whether to re-query instance state after call to Ec2 to terminate was made
- kind(String)
-
‘terminate’, ‘stop’ or ‘reboot’
Return
- true
-
Always return true
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/instance/instance_state.rb', line 335 def self.shutdown(user_id, skip_db_update, kind) payload = {:agent_identity => @identity, :state => FINAL_STATE, :user_id => user_id, :skip_db_update => skip_db_update, :kind => kind} Sender.instance.send_retryable_request("/state_recorder/record", payload) do |r| res = OperationResult.from_results(r) case kind when 'reboot' RightScale::Platform.controller.reboot unless res.success? when 'terminate', 'stop' Sender.instance.send_push("/registrar/remove", {:agent_identity => @identity, :created_at => Time.now.to_i}) RightScale::Platform.controller.shutdown unless res.success? else Log.error("InstanceState.shutdown() kind was unexpected: #{kind}") end end case kind when 'reboot' EM.add_timer(FORCE_SHUTDOWN_DELAY) { RightScale::Platform.controller.reboot } when 'terminate', 'stop' EM.add_timer(FORCE_SHUTDOWN_DELAY) { RightScale::Platform.controller.shutdown } else Log.error("InstanceState.shutdown() kind was unexpected: #{kind}") end end |