guests/debian: Do not restart networking
Restarting networking causes Vagrant to disconnect and fail.
This commit is contained in:
parent
d1a071d403
commit
c4a0a86ee0
|
@ -2,22 +2,23 @@ module VagrantPlugins
|
||||||
module GuestDebian
|
module GuestDebian
|
||||||
module Cap
|
module Cap
|
||||||
class ChangeHostName
|
class ChangeHostName
|
||||||
# For more information, please see:
|
|
||||||
#
|
|
||||||
# https://wiki.debian.org/HowTo/ChangeHostname
|
|
||||||
#
|
|
||||||
def self.change_host_name(machine, name)
|
def self.change_host_name(machine, name)
|
||||||
comm = machine.communicate
|
comm = machine.communicate
|
||||||
|
|
||||||
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
|
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
|
||||||
basename = name.split(".", 2)[0]
|
basename = name.split(".", 2)[0]
|
||||||
comm.sudo <<-EOH.gsub(/^ {14}/, '')
|
comm.sudo <<-EOH.gsub(/^ {14}/, '')
|
||||||
|
# Ensure exit on command error
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Set the hostname
|
# Set the hostname
|
||||||
echo '#{basename}' > /etc/hostname
|
echo '#{basename}' > /etc/hostname
|
||||||
hostname -F /etc/hostname
|
hostname -F /etc/hostname
|
||||||
|
|
||||||
|
if command -v hostnamectl; then
|
||||||
|
hostnamectl set-hostname '#{basename}'
|
||||||
|
fi
|
||||||
|
|
||||||
# Remove comments and blank lines from /etc/hosts
|
# Remove comments and blank lines from /etc/hosts
|
||||||
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
|
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
|
||||||
|
|
||||||
|
@ -29,17 +30,13 @@ module VagrantPlugins
|
||||||
# Update mailname
|
# Update mailname
|
||||||
echo '#{name}' > /etc/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
|
if test -f /etc/init.d/hostname.sh; then
|
||||||
invoke-rc.d hostname.sh start || true
|
/etc/init.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
|
|
||||||
fi
|
fi
|
||||||
EOH
|
EOH
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue