Class: OsCtl::ExportFS::Operations::Server::Runsv
- Includes:
- Lib::Utils::Log, Lib::Utils::System
- Defined in:
- lib/osctl/exportfs/operations/server/runsv.rb
Overview
Manage the system runit service on the host
Instance Attribute Summary collapse
-
#cfg ⇒ Object
readonly
protected
Returns the value of attribute cfg.
-
#server ⇒ Object
readonly
protected
Returns the value of attribute server.
Instance Method Summary collapse
-
#initialize(name) ⇒ Runsv
constructor
A new instance of Runsv.
- #restart ⇒ Object
- #service_link ⇒ Object protected
-
#start ⇒ Object
Create the service and place it into runsvdir-managed directory.
- #started? ⇒ Boolean protected
-
#stop ⇒ Object
Remove the service from the runsvdir-managed directory.
Methods inherited from Base
Constructor Details
Instance Attribute Details
#cfg ⇒ Object (readonly, protected)
Returns the value of attribute cfg.
57 58 59 |
# File 'lib/osctl/exportfs/operations/server/runsv.rb', line 57 def cfg @cfg end |
#server ⇒ Object (readonly, protected)
Returns the value of attribute server.
57 58 59 |
# File 'lib/osctl/exportfs/operations/server/runsv.rb', line 57 def server @server end |
Instance Method Details
#restart ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/osctl/exportfs/operations/server/runsv.rb', line 45 def restart server.synchronize do raise 'provide server address' if cfg.address.nil? stop sleep(1) start end end |
#service_link ⇒ Object (protected)
66 67 68 |
# File 'lib/osctl/exportfs/operations/server/runsv.rb', line 66 def service_link File.join(RunState::RUNSVDIR, server.name) end |
#start ⇒ Object
Create the service and place it into runsvdir-managed directory
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/osctl/exportfs/operations/server/runsv.rb', line 18 def start server.synchronize do raise 'server is already running' if started? raise 'provide server address' if cfg.address.nil? FileUtils.mkdir_p(server.runsv_dir) run = File.join(server.runsv_dir, 'run') ErbTemplate.render_to('runsv', { name: server.name, address: cfg.address, netif: cfg.netif }, run) File.chmod(0o755, run) File.symlink(server.runsv_dir, service_link) end end |
#started? ⇒ Boolean (protected)
59 60 61 62 63 64 |
# File 'lib/osctl/exportfs/operations/server/runsv.rb', line 59 def started? File.lstat(service_link) true rescue Errno::ENOENT false end |
#stop ⇒ Object
Remove the service from the runsvdir-managed directory
38 39 40 41 42 43 |
# File 'lib/osctl/exportfs/operations/server/runsv.rb', line 38 def stop server.synchronize do File.unlink(service_link) if File.symlink?(service_link) sleep(1) while server.running? end end |