Class: OsCtld::Commands::Self::Shutdown
- Defined in:
- lib/osctld/commands/self/shutdown.rb
Instance Attribute Summary
Attributes inherited from Base
#client, #client_handler, #id, #opts
Instance Method Summary collapse
- #execute ⇒ Object
- #grab_all_cts ⇒ Object protected
- #grab_pools ⇒ Object protected
Methods inherited from Base
#base_execute, #call_cmd, #call_cmd!, cmd, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!
Constructor Details
This class inherits a constructor from OsCtld::Commands::Base
Instance Method Details
#execute ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/osctld/commands/self/shutdown.rb', line 7 def execute # Make sure that osctld crash/restart will not stop the shutdown Daemon.get.begin_shutdown # Grab manipulation locks of all pools grab_pools # Disable all pools DB::Pools.get.each do |pool| progress("Disabling pool #{pool.name}") pool.exclusively { pool.disable } end # Grab manipulation locks of all containers grab_all_cts # Export pools one by one DB::Pools.get.each do |pool| progress("Exporting pool #{pool.name}") call_cmd!( Commands::Pool::Export, name: pool.name, force: true, grab_containers: false, stop_containers: true, unregister_users: false, ) end # Confirm the shutdown for anyone waiting for it, i.e. osctl shutdown Daemon.get.confirm_shutdown ok end |
#grab_all_cts ⇒ Object (protected)
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/osctld/commands/self/shutdown.rb', line 65 def grab_all_cts progress('Grabbing all containers') cts = DB::Containers.get loop do cts.delete_if do |ct| begin ct.acquire_manipulation_lock(self) true rescue ResourceLocked => e progress(e.) false end end break if cts.empty? sleep(1) end end |
#grab_pools ⇒ Object (protected)
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/osctld/commands/self/shutdown.rb', line 44 def grab_pools progress('Grabbing pools') pools = DB::Pools.get loop do pools.delete_if do |pool| begin pool.acquire_manipulation_lock(self) true rescue ResourceLocked => e progress(e.) false end end break if pools.empty? sleep(1) end end |