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
# File 'lib/osctl/exportfs/operations/server/delete.rb', line 12

def initialize(name)
  @server = Server.new(name)
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

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
# 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
    end

    Dir.rmdir(path)
  end
end

#executeObject



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
# File 'lib/osctl/exportfs/operations/server/delete.rb', line 16

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 = CGroup.new('systemd', 'osctl/exportfs/servers')

    begin
      cg.destroy(server.name)
    rescue Errno::ENOENT
    end
  end
end