Class: OsCtld::DistConfig::Arch

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

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, #update_etc_hosts, #writable?

Methods included from Utils::SwitchUser

#ct_attach, #ct_control, #ct_exec, #ct_runscript, #ct_syscmd, #init_script, #unlink_file

Constructor Details

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

Instance Method Details

#do_create_netif(netif) ⇒ Object (protected)



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/osctld/dist_config/arch.rb', line 50

def do_create_netif(netif)
  profile = netctl_profile(netif.name)
  return unless writable?(profile)

  # Create netctl profile
  OsCtld::ErbTemplate.render_to(
    File.join('dist_config/network/arch', netif.type.to_s),
    {netif: netif},
    profile
  )

  s_name = service_name(netif.name)
  s_path = service_path(netif.name)

  # Create systemd service for netctl
  OsCtld::ErbTemplate.render_to(
    'dist_config/network/arch/service',
    {netif: netif},
    s_path
  )

  # Start the service on boot
  s_link = service_symlink(netif.name)

  if !File.symlink?(s_link) && !File.exist?(s_link)
    File.symlink(File.join('/etc/systemd/system', s_name), s_link)
  end
end

#do_remove_netif(name) ⇒ Object (protected)



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/osctld/dist_config/arch.rb', line 79

def do_remove_netif(name)
  profile = netctl_profile(name)
  return unless writable?(profile)

  # Disable the service
  s_link = service_symlink(name)
  File.unlink(s_link) if File.symlink?(s_link)

  # Remove the service
  s_path = service_path(name)
  File.unlink(s_path) if File.symlink?(s_path)

  # Remove netctl profile
  File.unlink(profile) if File.exist?(profile)
end

#netctl_profile(name) ⇒ Object (protected)



95
96
97
# File 'lib/osctld/dist_config/arch.rb', line 95

def netctl_profile(name)
  File.join(ct.rootfs, 'etc/netctl', name)
end

#network(_opts) ⇒ Object



29
30
31
32
33
# File 'lib/osctld/dist_config/arch.rb', line 29

def network(_opts)
  ct.netifs.each do |netif|
    do_create_netif(netif)
  end
end

#remove_netif(opts) ⇒ Object

Remove netctl profile and systemd service



36
37
38
# File 'lib/osctld/dist_config/arch.rb', line 36

def remove_netif(opts)
  do_remove_netif(opts[:netif].name)
end

#rename_netif(opts) ⇒ Object

Rename netctl profile and systemd service



41
42
43
44
45
46
47
# File 'lib/osctld/dist_config/arch.rb', line 41

def rename_netif(opts)
  # Remove old network interface
  do_remove_netif(opts[:original_name])

  # Create the new interface
  do_create_netif(opts[:netif])
end

#service_name(name) ⇒ Object (protected)



99
100
101
# File 'lib/osctld/dist_config/arch.rb', line 99

def service_name(name)
  "netctl@#{name}.service"
end

#service_path(name) ⇒ Object (protected)



103
104
105
# File 'lib/osctld/dist_config/arch.rb', line 103

def service_path(name)
  File.join(ct.rootfs, 'etc/systemd/system', service_name(name))
end


107
108
109
110
111
112
113
# File 'lib/osctld/dist_config/arch.rb', line 107

def service_symlink(name)
  File.join(
    ct.rootfs,
    'etc/systemd/system/multi-user.target.wants',
    service_name(name)
  )
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/arch.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