Class: OsCtl::ExportFS::Operations::Server::Delete
- Includes:
- Lib::Utils::Log, Lib::Utils::System
- Defined in:
- lib/osctl/exportfs/operations/server/delete.rb
Overview
Delete NFS server configuration
Instance Attribute Summary collapse
-
#server ⇒ Object
readonly
protected
Returns the value of attribute server.
-
#sys ⇒ Object
readonly
protected
Returns the value of attribute sys.
Instance Method Summary collapse
-
#cleanup_shared_dir ⇒ Object
protected
Safely unmount and remove contents of the shared directory.
- #execute ⇒ Object
-
#initialize(name) ⇒ Delete
constructor
A new instance of Delete.
Methods inherited from Base
Constructor Details
Instance Attribute Details
#server ⇒ Object (readonly, protected)
Returns the value of attribute server.
46 47 48 |
# File 'lib/osctl/exportfs/operations/server/delete.rb', line 46 def server @server end |
#sys ⇒ Object (readonly, protected)
Returns the value of attribute sys.
46 47 48 |
# File 'lib/osctl/exportfs/operations/server/delete.rb', line 46 def sys @sys end |
Instance Method Details
#cleanup_shared_dir ⇒ Object (protected)
Safely unmount and remove contents of the shared directory
The shared directory can contain mounts which were left-over by some unexpected failures. They have to be unmounted and safely removed with rmdir. The shared dir should contain only mounts and then empty directories, otherwise there’s something wrong.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/osctl/exportfs/operations/server/delete.rb', line 54 def cleanup_shared_dir Dir.entries(server.shared_dir).each do |v| next if %w[. ..].include?(v) path = File.join(server.shared_dir, v) begin sys.unmount(path) rescue SystemCallError # ignore end Dir.rmdir(path) end end |
#execute ⇒ Object
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 |
# File 'lib/osctl/exportfs/operations/server/delete.rb', line 18 def execute server.synchronize do if server.running? raise 'the server is running' end cleanup_shared_dir if Dir.exist?(server.shared_dir) begin sys.unmount(server.shared_dir) rescue SystemCallError # ignore end Dir.rmdir(server.shared_dir) end # rm -rf can be run only after the shared directory has been safely removed FileUtils.rm_rf(server.dir, secure: true) cg = Operations::Server::CGroup.new(server) cg.clear_all end end |