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.
38 39 40 41 |
# File 'lib/osctl/exportfs/server.rb', line 38 def initialize(name) @name = name leave_ns end |
Instance Attribute Details
#config_file ⇒ String (readonly)
Path to file with server config
27 28 29 |
# File 'lib/osctl/exportfs/server.rb', line 27 def config_file @config_file end |
#dir ⇒ String (readonly)
Server root directory
11 12 13 |
# File 'lib/osctl/exportfs/server.rb', line 11 def dir @dir end |
#exports_file ⇒ String (readonly)
Path to file mounted to /etc/exportfs
31 32 33 |
# File 'lib/osctl/exportfs/server.rb', line 31 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)
7 8 9 |
# File 'lib/osctl/exportfs/server.rb', line 7 def name @name end |
#nfs_state ⇒ String (readonly)
Directory mounted to /var/lib/nfs
15 16 17 |
# File 'lib/osctl/exportfs/server.rb', line 15 def nfs_state @nfs_state end |
#pid_file ⇒ String (readonly)
Path to file with the PID of the server’s init process
35 36 37 |
# File 'lib/osctl/exportfs/server.rb', line 35 def pid_file @pid_file end |
#runsv_dir ⇒ String (readonly)
Server service running on the host
23 24 25 |
# File 'lib/osctl/exportfs/server.rb', line 23 def runsv_dir @runsv_dir end |
#shared_dir ⇒ String (readonly)
Directory used to propagate mounts from the host to the server’s namespace
19 20 21 |
# File 'lib/osctl/exportfs/server.rb', line 19 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
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_ns ⇒ Object
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_config ⇒ Config::TopLevel
55 56 57 |
# File 'lib/osctl/exportfs/server.rb', line 55 def open_config Config.open(self) end |
#read_pid ⇒ 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
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_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
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 |