guests/debian: Do not restart networking

Restarting networking causes Vagrant to disconnect and fail.
This commit is contained in:
Seth Vargo 2016-06-25 15:51:58 -04:00
parent d1a071d403
commit c4a0a86ee0
No known key found for this signature in database
GPG Key ID: 905A90C2949E8787
1 changed files with 11 additions and 14 deletions

View File

@ -2,22 +2,23 @@ module VagrantPlugins
module GuestDebian
module Cap
class ChangeHostName
# For more information, please see:
#
# https://wiki.debian.org/HowTo/ChangeHostname
#
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split(".", 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, '')
# Ensure exit on command error
set -e
# Set the hostname
echo '#{basename}' > /etc/hostname
hostname -F /etc/hostname
if command -v hostnamectl; then
hostnamectl set-hostname '#{basename}'
fi
# Remove comments and blank lines from /etc/hosts
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
@ -29,17 +30,13 @@ module VagrantPlugins
# Update mailname
echo '#{name}' > /etc/mailname
# Restart networking and force new DHCP
# Restart hostname services
if test -f /etc/init.d/hostname; then
/etc/init.d/hostname start || true
fi
if test -f /etc/init.d/hostname.sh; then
invoke-rc.d hostname.sh start || true
fi
if test -f /etc/init.d/networking; then
invoke-rc.d networking force-reload || true
fi
if test -f /etc/init.d/network-manager; then
invoke-rc.d network-manager force-reload || true
/etc/init.d/hostname.sh start || true
fi
EOH
end