Class: OsCtld::DistConfig::Slackware

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

Instance Attribute Summary

Attributes inherited from Base

#ct, #ctrc, #distribution, #version

Instance Method Summary collapse

Methods inherited from Base

#add_netif, #bin_path, distribution, #dns_resolvers, #initialize, #passwd, #remove_netif, #rename_netif, #stop, #unset_etc_hosts, #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
# File 'lib/osctld/dist_config/slackware.rb', line 29

def network(_opts)
  tpl_base = 'dist_config/network/slackware'

  {start: 'add', stop: 'del'}.each do |operation, cmd|
    cmds = ct.netifs.map do |netif|
      OsCtld::ErbTemplate.render(
        File.join(tpl_base, netif.type.to_s),
        {netif: netif, cmd: cmd}
      )
    end

    writable?(File.join(ctrc.rootfs, 'etc/rc.d', "rc.venet.#{operation}")) do |path|
      File.write(path, cmds.join("\n"))
    end
  end
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/slackware.rb', line 7

def set_hostname(opts)
  # /etc/hostname
  writable?(File.join(ctrc.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(old_hostname: opts[:original])

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

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