Class: OsCtld::DistConfig::Arch
- Inherits:
-
Base
- Object
- Base
- OsCtld::DistConfig::Arch
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?
#ct_attach, #ct_syscmd
Instance Method Details
#deprecated_service_path(name) ⇒ Object
98
99
100
|
# File 'lib/osctld/dist_config/arch.rb', line 98
def deprecated_service_path(name)
File.join(ct.rootfs, 'etc/systemd/system', service_name(name))
end
|
#do_create_netif(netif) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/osctld/dist_config/arch.rb', line 51
def do_create_netif(netif)
profile = netctl_profile(netif.name)
return unless writable?(profile)
OsCtld::ErbTemplate.render_to(
File.join('dist_config/network/arch', netif.type.to_s),
{netif: netif},
profile
)
s_name = service_name(netif.name)
unlink_if_exists(deprecated_service_path(netif.name))
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/osctld/dist_config/arch.rb', line 75
def do_remove_netif(name)
profile = netctl_profile(name)
return unless writable?(profile)
s_link = service_symlink(name)
File.unlink(s_link) if File.symlink?(s_link)
unlink_if_exists(deprecated_service_path(name))
File.unlink(profile) if File.exist?(profile)
end
|
#netctl_profile(name) ⇒ Object
90
91
92
|
# File 'lib/osctld/dist_config/arch.rb', line 90
def netctl_profile(name)
File.join(ct.rootfs, 'etc/netctl', name)
end
|
#network(_opts) ⇒ Object
30
31
32
33
34
|
# File 'lib/osctld/dist_config/arch.rb', line 30
def network(_opts)
ct.netifs.each do |netif|
do_create_netif(netif)
end
end
|
#remove_netif(opts) ⇒ Object
Remove netctl profile and systemd service
37
38
39
|
# File 'lib/osctld/dist_config/arch.rb', line 37
def remove_netif(opts)
do_remove_netif(opts[:netif].name)
end
|
#rename_netif(opts) ⇒ Object
Rename netctl profile and systemd service
42
43
44
45
46
47
48
|
# File 'lib/osctld/dist_config/arch.rb', line 42
def rename_netif(opts)
do_remove_netif(opts[:original_name])
do_create_netif(opts[:netif])
end
|
#service_name(name) ⇒ Object
94
95
96
|
# File 'lib/osctld/dist_config/arch.rb', line 94
def service_name(name)
"netctl@#{name}.service"
end
|
#service_symlink(name) ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/osctld/dist_config/arch.rb', line 102
def service_symlink(name)
File.join(
ct.rootfs,
'etc/systemd/system/multi-user.target.wants',
service_name(name)
)
end
|
#set_hostname(opts) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/osctld/dist_config/arch.rb', line 8
def set_hostname(opts)
writable?(File.join(ct.rootfs, 'etc', 'hostname')) do |path|
regenerate_file(path, 0644) do |f|
f.puts(ct.hostname.local)
end
end
update_etc_hosts(opts[:original])
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
|