Class: OsCtl::ExportFS::Server
- Inherits:
-
Object
- Object
- OsCtl::ExportFS::Server
- Defined in:
- lib/osctl/exportfs/server.rb
Overview
Represents a NFS server
Instance Attribute Summary collapse
-
#config_file ⇒ String
readonly
Path to file with server config.
-
#dir ⇒ String
readonly
Server root directory.
-
#exports_file ⇒ String
readonly
Path to file mounted to /etc/exportfs.
-
#lock_file ⇒ Object
readonly
protected
Returns the value of attribute lock_file.
- #name ⇒ String readonly
-
#nfs_state ⇒ String
readonly
Directory mounted to /var/lib/nfs.
-
#pid_file ⇒ String
readonly
Path to file with the PID of the server's init process.
-
#runsv_dir ⇒ String
readonly
Server service running on the host.
-
#shared_dir ⇒ String
readonly
Directory used to propagate mounts from the host to the server's namespace.
Instance Method Summary collapse
-
#enter_ns ⇒ Object
Reconfigure the object to return paths relative to the server's mount namespace.
-
#initialize(name) ⇒ Server
constructor
A new instance of Server.
-
#leave_ns ⇒ Object
Reconfigure the object to return paths relative to the host's mount namespace.
- #open_config ⇒ Config::TopLevel
- #read_pid ⇒ Integer
- #running? ⇒ Boolean
- #set_paths ⇒ Object protected
- #synchronize ⇒ Object
Constructor Details
#initialize(name) ⇒ Server
Returns a new instance of Server.
39 40 41 42 |
# File 'lib/osctl/exportfs/server.rb', line 39 def initialize(name) @name = name leave_ns end |
Instance Attribute Details
#config_file ⇒ String (readonly)
Path to file with server config
28 29 30 |
# File 'lib/osctl/exportfs/server.rb', line 28 def config_file @config_file end |
#dir ⇒ String (readonly)
Server root directory
12 13 14 |
# File 'lib/osctl/exportfs/server.rb', line 12 def dir @dir end |
#exports_file ⇒ String (readonly)
Path to file mounted to /etc/exportfs
32 33 34 |
# File 'lib/osctl/exportfs/server.rb', line 32 def exports_file @exports_file end |
#lock_file ⇒ Object (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 |
#name ⇒ String (readonly)
8 9 10 |
# File 'lib/osctl/exportfs/server.rb', line 8 def name @name end |
#nfs_state ⇒ String (readonly)
Directory mounted to /var/lib/nfs
16 17 18 |
# File 'lib/osctl/exportfs/server.rb', line 16 def nfs_state @nfs_state end |
#pid_file ⇒ String (readonly)
Path to file with the PID of the server's init process
36 37 38 |
# File 'lib/osctl/exportfs/server.rb', line 36 def pid_file @pid_file end |
#runsv_dir ⇒ String (readonly)
Server service running on the host
24 25 26 |
# File 'lib/osctl/exportfs/server.rb', line 24 def runsv_dir @runsv_dir end |
#shared_dir ⇒ String (readonly)
Directory used to propagate mounts from the host to the server's namespace
20 21 22 |
# File 'lib/osctl/exportfs/server.rb', line 20 def shared_dir @shared_dir end |
Instance Method Details
#enter_ns ⇒ Object
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_ns ⇒ Object
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_config ⇒ Config::TopLevel
56 57 58 |
# File 'lib/osctl/exportfs/server.rb', line 56 def open_config Config.open(self) end |
#read_pid ⇒ 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
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_paths ⇒ Object (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 |
#synchronize ⇒ Object
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 |