Class: OsCtl::ExportFS::Operations::Server::Delete

Inherits:
Base
  • Object
show all
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

Instance Method Summary collapse

Methods inherited from Base

run

Constructor Details

#initialize(name) ⇒ Delete

Returns a new instance of Delete.

Parameters:

  • name (String)


12
13
14
15
16
# File 'lib/osctl/exportfs/operations/server/delete.rb', line 12

def initialize(name)
  super()
  @server = Server.new(name)
  @sys = OsCtl::Lib::Sys.new
end

Instance Attribute Details

#serverObject (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

#sysObject (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_dirObject (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

#executeObject



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