Skip to content

Commit

Permalink
Merge pull request #5753 from jfilip/fix/master/ubuntu_vivid_hostname
Browse files Browse the repository at this point in the history
Fix #5673 - Use hostnamectl to set the hostname on Ubuntu Vivid 15.
  • Loading branch information
mitchellh committed Jul 6, 2015
2 parents 7319673 + 67cde0d commit 6c8c15b
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion plugins/guests/ubuntu/cap/change_host_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,39 @@ def self.change_host_name(machine, name)
super
end

def update_etc_hostname
super unless vivid?
sudo("hostnamectl set-hostname '#{short_hostname}'")
end

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")
elsif vivid?
# Service runs via hostnamectl
else
sudo("service hostname start")
end
end

def hardy?
machine.communicate.test("[ `lsb_release -c -s` = hardy ]")
os_version("hardy")
end

def vivid?
os_version("vivid")
end

def renew_dhcp
sudo("ifdown -a; ifup -a; ifup -a --allow=hotplug")
end

private

def os_version(name)
machine.communicate.test("[ `lsb_release -c -s` = #{name} ]")
end
end
end
end
Expand Down

0 comments on commit 6c8c15b

Please sign in to comment.