Class: OsCtl::ExportFS::Operations::Server::Runsv

Inherits:
Base
  • Object
show all
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

Instance Method Summary collapse

Methods inherited from Base

#execute, run

Constructor Details

#initialize(name) ⇒ Runsv

Returns a new instance of Runsv.

Parameters:

  • name (String)


11
12
13
14
15
# File 'lib/osctl/exportfs/operations/server/runsv.rb', line 11

def initialize(name)
  super()
  @server = Server.new(name)
  @cfg = server.open_config
end

Instance Attribute Details

#cfgObject (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

#serverObject (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

#restartObject



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


66
67
68
# File 'lib/osctl/exportfs/operations/server/runsv.rb', line 66

def service_link
  File.join(RunState::RUNSVDIR, server.name)
end

#startObject

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)

Returns:

  • (Boolean)


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

#stopObject

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