Class: OsCtld::Commands::Container::Delete
- Includes:
- OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System, Utils::SwitchUser
- Defined in:
- lib/osctld/commands/container/delete.rb
Instance Attribute Summary
Attributes inherited from Base
#client, #client_handler, #id, #opts
Instance Method Summary collapse
Methods included from Utils::SwitchUser
Methods inherited from Logged
Methods inherited from Base
#base_execute, #call_cmd, #call_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(ct) ⇒ Object
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 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 99 100 |
# File 'lib/osctld/commands/container/delete.rb', line 16 def execute(ct) unless opts[:force] ct.exclusively do error!('the container is running') if ct.running? end end manipulate(ct) do progress('Stopping container') call_cmd!( Commands::Container::Stop, pool: ct.pool.name, id: ct.id, manipulation_lock: opts[:manipulation_lock], progress: opts[:progress], message: opts[:message] ) if ct.send_log SendReceive.stopped_using_key(ct.pool, ct.send_log.opts.key_name) end progress('Disconnecting console') Console.remove(ct) progress('Removing shared mount directory') ct. ct.mounts.shared_dir.remove progress('Moving dataset to trash') TrashBin.add_dataset(ct.pool, ct.dataset) progress('Removing LXC configuration and script hooks') Monitor::Master.demonitor(ct) syscmd("rm -rf #{ct.lxc_dir} #{ct.user_hook_script_dir}") if File.exist?(ct.log_path) File.rename(ct.log_path, "#{ct.log_path}.destroyed") end File.unlink(ct.config_path) progress('Unregistering container') DB::Containers.remove(ct) ct.pool.autostart_plan.clear_ct(ct) progress('Removing cgroups') begin if ct.group.has_containers?(ct.user) CGroup.rmpath_all(ct.base_cgroup_path) else CGroup.rmpath_all(ct.group.full_cgroup_path(ct.user)) end rescue SystemCallError # If some of the cgroups are busy, just leave them be end if AppArmor.enabled? progress('Removing AppArmor profile') ct.apparmor.destroy_namespace ct.apparmor.destroy_profile end bashrc = File.join(ct.lxc_dir, '.bashrc') FileUtils.rm_f(bashrc) unless ct.group.has_containers?(ct.user) Dir.rmdir(ct.group.userdir(ct.user)) end end if !ct.user.standalone && !ct.user.has_containers? call_cmd!( Commands::User::Delete, pool: ct.user.pool.name, name: ct.user.name ) end progress('Reconfiguring LXC usernet') call_cmd(Commands::User::LxcUsernet) ok end |
#find ⇒ Object
11 12 13 14 |
# File 'lib/osctld/commands/container/delete.rb', line 11 def find ct = DB::Containers.find(opts[:id], opts[:pool]) ct || error!('container not found') end |