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
# 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,
    interfacesd: Dir.exist?(File.join(base, 'interfaces.d')),
  }

  %i(head tail).each do |v|
    vars[v] = File.exist?(File.join(base, "interfaces.#{v}"))
  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