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.



91
92
93
# File 'lib/osctl/exportfs/server.rb', line 91

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



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

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



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

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

#open_configConfig::TopLevel

Returns:



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

def open_config
  Config.open(self)
end

#read_pidInteger

Returns:

  • (Integer)


50
51
52
# File 'lib/osctl/exportfs/server.rb', line 50

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

#running?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'lib/osctl/exportfs/server.rb', line 43

def running?
  File.stat(pid_file).size > 0
rescue Errno::ENOENT
  false
end

#set_pathsObject (protected)



93
94
95
96
97
98
99
100
101
# File 'lib/osctl/exportfs/server.rb', line 93

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



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/osctl/exportfs/server.rb', line 73

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