Class: OsCtl::ExportFS::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/osctl/exportfs/server.rb

Overview

Represents a NFS server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Server

Returns a new instance of Server.

Parameters:

  • name (String)


38
39
40
41
# File 'lib/osctl/exportfs/server.rb', line 38

def initialize(name)
  @name = name
  leave_ns
end

Instance Attribute Details

#config_fileString (readonly)

Path to file with server config

Returns:

  • (String)


27
28
29
# File 'lib/osctl/exportfs/server.rb', line 27

def config_file
  @config_file
end

#dirString (readonly)

Server root directory

Returns:

  • (String)


11
12
13
# File 'lib/osctl/exportfs/server.rb', line 11

def dir
  @dir
end

#exports_fileString (readonly)

Path to file mounted to /etc/exportfs

Returns:

  • (String)


31
32
33
# File 'lib/osctl/exportfs/server.rb', line 31

def exports_file
  @exports_file
end

#lock_fileObject (readonly, protected)

Returns the value of attribute lock_file.



97
98
99
# File 'lib/osctl/exportfs/server.rb', line 97

def lock_file
  @lock_file
end

#nameString (readonly)

Returns:

  • (String)


7
8
9
# File 'lib/osctl/exportfs/server.rb', line 7

def name
  @name
end

#nfs_stateString (readonly)

Directory mounted to /var/lib/nfs

Returns:

  • (String)


15
16
17
# File 'lib/osctl/exportfs/server.rb', line 15

def nfs_state
  @nfs_state
end

#pid_fileString (readonly)

Path to file with the PID of the server’s init process

Returns:

  • (String)


35
36
37
# File 'lib/osctl/exportfs/server.rb', line 35

def pid_file
  @pid_file
end

#runsv_dirString (readonly)

Server service running on the host

Returns:

  • (String)


23
24
25
# File 'lib/osctl/exportfs/server.rb', line 23

def runsv_dir
  @runsv_dir
end

#shared_dirString (readonly)

Directory used to propagate mounts from the host to the server’s namespace

Returns:

  • (String)


19
20
21
# File 'lib/osctl/exportfs/server.rb', line 19

def shared_dir
  @shared_dir
end

Instance Method Details

#enter_nsObject

Reconfigure the object to return paths relative to the server’s mount namespace



67
68
69
70
# File 'lib/osctl/exportfs/server.rb', line 67

def enter_ns
  @dir = File.join(RunState::CURRENT_SERVER)
  set_paths
end

#leave_nsObject

Reconfigure the object to return paths relative to the host’s mount namespace



74
75
76
77
# File 'lib/osctl/exportfs/server.rb', line 74

def leave_ns
  @dir = File.join(RunState::SERVERS, name)
  set_paths
end

#open_configConfig::TopLevel

Returns:



61
62
63
# File 'lib/osctl/exportfs/server.rb', line 61

def open_config
  Config.open(self)
end

#read_pidInteger

Returns:

  • (Integer)


56
57
58
# File 'lib/osctl/exportfs/server.rb', line 56

def read_pid
  File.read(pid_file).strip.to_i
end

#running?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/osctl/exportfs/server.rb', line 43

def running?
  return false if !File.exist?(pid_file) || File.stat(pid_file).size <= 0

  pid = read_pid
  Process.kill(0, pid)
  true
rescue Errno::ENOENT, Errno::ESRCH
  false
rescue Errno::EPERM
  true
end

#set_pathsObject (protected)



99
100
101
102
103
104
105
106
107
# File 'lib/osctl/exportfs/server.rb', line 99

def set_paths
  @nfs_state = File.join(@dir, 'state')
  @shared_dir = File.join(@dir, 'shared')
  @runsv_dir = File.join(@dir, 'runsv')
  @config_file = File.join(@dir, 'config.yml')
  @exports_file = File.join(@dir, 'exports')
  @lock_file = File.join(@dir, 'lock')
  @pid_file = File.join(@dir, 'pid')
end

#synchronizeObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/osctl/exportfs/server.rb', line 79

def synchronize
  return yield if Thread.current[:filelock_held]

  Filelock(lock_file) do
    Thread.current[:filelock_held] = true

    begin
      ret = yield
    ensure
      Thread.current[:filelock_held] = false
    end

    ret
  end
end