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)


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

def initialize(name)
  @name = name
  leave_ns
end

Instance Attribute Details

#config_fileString (readonly)

Path to file with server config

Returns:

  • (String)


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

def config_file
  @config_file
end

#dirString (readonly)

Server root directory

Returns:

  • (String)


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

def dir
  @dir
end

#exports_fileString (readonly)

Path to file mounted to /etc/exportfs

Returns:

  • (String)


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

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)


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

def name
  @name
end

#nfs_stateString (readonly)

Directory mounted to /var/lib/nfs

Returns:

  • (String)


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

def nfs_state
  @nfs_state
end

#pid_fileString (readonly)

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

Returns:

  • (String)


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

def pid_file
  @pid_file
end

#runsv_dirString (readonly)

Server service running on the host

Returns:

  • (String)


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

def runsv_dir
  @runsv_dir
end

#shared_dirString (readonly)

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

Returns:

  • (String)


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

def shared_dir
  @shared_dir
end

Instance Method Details

#enter_nsObject

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



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

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



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

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

#open_configConfig::TopLevel

Returns:



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

def open_config
  Config.open(self)
end

#read_pidInteger

Returns:

  • (Integer)


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

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

#running?Boolean

Returns:

  • (Boolean)


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

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



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

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