Class: OsCtld::DistConfig::Debian

Inherits:
Base
  • Object
show all
Defined in:
lib/osctld/dist_config/debian.rb

Direct Known Subclasses

Alpine, Devuan, Ubuntu

Instance Attribute Summary

Attributes inherited from Base

#ct, #distribution, #version

Instance Method Summary collapse

Methods inherited from Base

#add_netif, #bin_path, distribution, #dns_resolvers, #initialize, #passwd, #remove_netif, #rename_netif, #update_etc_hosts, #writable?

Methods included from Utils::SwitchUser

#ct_attach, #ct_syscmd

Constructor Details

This class inherits a constructor from OsCtld::DistConfig::Base

Instance Method Details

#network(_opts) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/osctld/dist_config/debian.rb', line 29

def network(_opts)
  base = File.join(ct.rootfs, 'etc', 'network')
  config = File.join(base, 'interfaces')
  return unless writable?(config)

  vars = {
    netifs: ct.netifs,
    head: nil,
    interfacesd: Dir.exist?(File.join(base, 'interfaces.d')),
    tail: nil,
  }

  %i(head tail).each do |v|
    f = File.join(base, "interfaces.#{v}")

    begin
      # Ignore large files
      if File.size(f) > 10*1024*1024
        log(:warn, ct, "/etc/network/interfaces.#{v} found, but is too large")
        next
      end

      vars[v] = File.read(f)
    rescue Errno::ENOENT
      next
    end
  end

  OsCtld::ErbTemplate.render_to(
    'dist_config/network/debian/interfaces',
    vars,
    config
  )
end

#set_hostname(opts) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/osctld/dist_config/debian.rb', line 7

def set_hostname(opts)
  # /etc/hostname
  writable?(File.join(ct.rootfs, 'etc', 'hostname')) do |path|
    regenerate_file(path, 0644) do |f|
      f.puts(ct.hostname.local)
    end
  end

  # Entry in /etc/hosts
  update_etc_hosts(opts[:original])

  # Apply hostname if the container is running
  if ct.running?
    begin
      ct_syscmd(ct, 'hostname -F /etc/hostname')

    rescue SystemCommandFailed => e
      log(:warn, ct, "Unable to apply hostname: #{e.message}")
    end
  end
end