From c7186236f1ae30b6f4824b5aa2c56574c2fd7e5c Mon Sep 17 00:00:00 2001 From: Jeff Goldschrafe Date: Mon, 31 Aug 2015 16:50:58 -0400 Subject: [PATCH] Better Ubuntu systemd detection Check the running process at PID 1 to determine which init system is currently in use. --- plugins/guests/ubuntu/cap/change_host_name.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/plugins/guests/ubuntu/cap/change_host_name.rb b/plugins/guests/ubuntu/cap/change_host_name.rb index 706d4850a..df68a010a 100644 --- a/plugins/guests/ubuntu/cap/change_host_name.rb +++ b/plugins/guests/ubuntu/cap/change_host_name.rb @@ -7,7 +7,7 @@ module VagrantPlugins end def update_etc_hostname - return super unless vivid? + return super unless systemd? sudo("hostnamectl set-hostname '#{short_hostname}'") end @@ -15,7 +15,7 @@ module VagrantPlugins if hardy? # hostname.sh returns 1, so use `true` to get a 0 exitcode sudo("/etc/init.d/hostname.sh start; true") - elsif vivid? + elsif systemd? # Service runs via hostnamectl else sudo("service hostname start") @@ -26,19 +26,25 @@ module VagrantPlugins 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 init_package + machine.communicate.execute('cat /proc/1/comm') do |type, data| + return data.chomp if type == :stdout + end + end + def os_version(name) machine.communicate.test("[ `lsb_release -c -s` = #{name} ]") end + + def systemd? + init_package == 'systemd' + end end end end