2013-04-04 06:53:17 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module GuestUbuntu
|
|
|
|
module Cap
|
2013-11-23 23:48:00 +00:00
|
|
|
class ChangeHostName < VagrantPlugins::GuestDebian::Cap::ChangeHostName
|
2013-04-04 06:53:17 +00:00
|
|
|
def self.change_host_name(machine, name)
|
2013-11-23 23:48:00 +00:00
|
|
|
super
|
|
|
|
end
|
2013-09-22 07:33:24 +00:00
|
|
|
|
2015-05-25 20:06:51 +00:00
|
|
|
def update_etc_hostname
|
2015-08-31 20:50:58 +00:00
|
|
|
return super unless systemd?
|
2015-05-25 20:06:51 +00:00
|
|
|
sudo("hostnamectl set-hostname '#{short_hostname}'")
|
|
|
|
end
|
|
|
|
|
2013-11-23 23:48:00 +00:00
|
|
|
def refresh_hostname_service
|
|
|
|
if hardy?
|
|
|
|
# hostname.sh returns 1, so use `true` to get a 0 exitcode
|
|
|
|
sudo("/etc/init.d/hostname.sh start; true")
|
2015-08-31 20:50:58 +00:00
|
|
|
elsif systemd?
|
2015-05-25 20:06:51 +00:00
|
|
|
# Service runs via hostnamectl
|
2013-11-23 23:48:00 +00:00
|
|
|
else
|
|
|
|
sudo("service hostname start")
|
|
|
|
end
|
|
|
|
end
|
2013-09-22 07:33:24 +00:00
|
|
|
|
2013-11-23 23:48:00 +00:00
|
|
|
def hardy?
|
2015-05-25 20:06:51 +00:00
|
|
|
os_version("hardy")
|
|
|
|
end
|
|
|
|
|
2013-11-23 23:48:00 +00:00
|
|
|
def renew_dhcp
|
|
|
|
sudo("ifdown -a; ifup -a; ifup -a --allow=hotplug")
|
2013-04-04 06:53:17 +00:00
|
|
|
end
|
2015-05-25 20:06:51 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2015-08-31 20:50:58 +00:00
|
|
|
def init_package
|
|
|
|
machine.communicate.execute('cat /proc/1/comm') do |type, data|
|
|
|
|
return data.chomp if type == :stdout
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-25 20:06:51 +00:00
|
|
|
def os_version(name)
|
|
|
|
machine.communicate.test("[ `lsb_release -c -s` = #{name} ]")
|
|
|
|
end
|
2015-08-31 20:50:58 +00:00
|
|
|
|
|
|
|
def systemd?
|
|
|
|
init_package == 'systemd'
|
|
|
|
end
|
2013-04-04 06:53:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|