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-07-11 18:15:54 +00:00
|
|
|
return super unless vivid?
|
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-05-25 20:06:51 +00:00
|
|
|
elsif vivid?
|
|
|
|
# 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
|
|
|
|
|
|
|
|
def vivid?
|
|
|
|
os_version("vivid")
|
2013-11-23 23:48:00 +00:00
|
|
|
end
|
2013-09-22 07:33:24 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
def os_version(name)
|
|
|
|
machine.communicate.test("[ `lsb_release -c -s` = #{name} ]")
|
|
|
|
end
|
2013-04-04 06:53:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|