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.
43 44 45 |
# File 'lib/osctl/exportfs/operations/server/delete.rb', line 43 def server @server end |
#sys ⇒ Object (readonly, protected)
Returns the value of attribute sys.
43 44 45 |
# File 'lib/osctl/exportfs/operations/server/delete.rb', line 43 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/osctl/exportfs/operations/server/delete.rb', line 51 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 end Dir.rmdir(path) end end |
#execute ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/osctl/exportfs/operations/server/delete.rb', line 17 def execute server.synchronize do if server.running? fail 'the server is running' end cleanup_shared_dir if Dir.exist?(server.shared_dir) begin sys.unmount(server.shared_dir) rescue SystemCallError 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 |