Class: OsCtl::ExportFS::Operations::Runit::Generate

Inherits:
Base
  • Object
show all
Defined in:
lib/osctl/exportfs/operations/runit/generate.rb

Overview

Generate system files for runit

Note that this operation has to be called from inside the server’s mount namespace.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

run

Constructor Details

#initialize(server, config) ⇒ Generate

Returns a new instance of Generate.

Parameters:



12
13
14
15
16
17
18
19
# File 'lib/osctl/exportfs/operations/runit/generate.rb', line 12

def initialize(server, config)
  super()
  @server = server
  @vars = {
    server:,
    config:
  }
end

Instance Attribute Details

#serverObject (readonly, protected)

Returns the value of attribute server.



39
40
41
# File 'lib/osctl/exportfs/operations/runit/generate.rb', line 39

def server
  @server
end

#varsObject (readonly, protected)

Returns the value of attribute vars.



39
40
41
# File 'lib/osctl/exportfs/operations/runit/generate.rb', line 39

def vars
  @vars
end

Instance Method Details

#executeObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/osctl/exportfs/operations/runit/generate.rb', line 21

def execute
  FileUtils.mkdir_p('/etc/runit')
  %w[1 2 3].each do |v|
    write_script("runit/#{v}", "/etc/runit/#{v}")
  end

  FileUtils.mkdir_p('/etc/runit/runsvdir')
  %w[rpcbind nfsd statd].each do |sv|
    write_service("runsvdir/#{sv}", '/etc/runit/runsvdir', sv)
  end

  return if File.exist?('/service')

  File.symlink('/etc/runit/runsvdir', '/service')
end

#write_script(template, path) ⇒ Object (protected)



49
50
51
52
# File 'lib/osctl/exportfs/operations/runit/generate.rb', line 49

def write_script(template, path)
  ErbTemplate.render_to(template, vars, path)
  File.chmod(0o755, path)
end

#write_service(template, runsvdir, name) ⇒ Object (protected)



41
42
43
44
45
46
47
# File 'lib/osctl/exportfs/operations/runit/generate.rb', line 41

def write_service(template, runsvdir, name)
  svdir = File.join(runsvdir, name)
  FileUtils.mkdir_p(svdir)

  runfile = File.join(svdir, 'run')
  write_script(template, runfile)
end