From 53323ba54e6ff444752bd50cc750dc9ce43cf447 Mon Sep 17 00:00:00 2001 From: Ladar Levison Date: Sat, 3 Aug 2019 15:19:51 +0530 Subject: [PATCH] Fix the hostname config logic for Alpine. And allow those who like `vagrant` to go Alpine skiing! --- plugins/guests/alt/cap/change_host_name.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/guests/alt/cap/change_host_name.rb b/plugins/guests/alt/cap/change_host_name.rb index a2c7b8453..6b73d27ad 100644 --- a/plugins/guests/alt/cap/change_host_name.rb +++ b/plugins/guests/alt/cap/change_host_name.rb @@ -17,7 +17,11 @@ module VagrantPlugins NEW_HOSTNAME_SHORT="${NEW_HOSTNAME_FULL%%.*}" # Update sysconfig - sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network + if [ -f /etc/sysconfig/network ]; then + sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network + elif [ -f /etc/hostname ]; then + sed -i 's/.*/#{name}/' /etc/hostname + fi # Set the hostname - use hostnamectl if available if command -v hostnamectl; then @@ -36,7 +40,14 @@ module VagrantPlugins fi # Restart network - service network restart + if command -v hostnamectl; then + if [ -f /etc/init.d/network ]; then + service network restart + elif [ -f /etc/init.d/networking ]; then + service networking restart + fi + fi + EOH end end