From 02f40b35fa3b6a95b2fa31042884545525594308 Mon Sep 17 00:00:00 2001 From: Marno van der Molen Date: Sat, 17 May 2014 02:19:34 +0200 Subject: [PATCH 01/10] Adds minimal implementation to deploy a Salt minion on Windows including support for pre-seeding the keys --- plugins/provisioners/salt/bootstrap-salt.ps1 | 26 ++++ plugins/provisioners/salt/provisioner.rb | 126 ++++++++++++++----- 2 files changed, 120 insertions(+), 32 deletions(-) create mode 100644 plugins/provisioners/salt/bootstrap-salt.ps1 diff --git a/plugins/provisioners/salt/bootstrap-salt.ps1 b/plugins/provisioners/salt/bootstrap-salt.ps1 new file mode 100644 index 000000000..0c52b1a85 --- /dev/null +++ b/plugins/provisioners/salt/bootstrap-salt.ps1 @@ -0,0 +1,26 @@ +# Copy minion keys to correct location +New-Item c:\salt\conf\pki\minion\ -ItemType directory +cp C:\tmp\minion.pem C:\salt\conf\pki\minion\ +cp C:\tmp\minion.pub C:\salt\conf\pki\minion\ + +# Detect architecture +if ([IntPtr]::Size -eq 4) { + $arch = "win32" +} else { + $arch = "AMD64" +} + +# Download minion setup file +Write-Host "Downloading Salt minion installer ($arch)..." +$webclient = New-Object System.Net.WebClient +$url = "https://docs.saltstack.com/downloads/Salt-Minion-2014.1.3-1-$arch-Setup.exe" +$file = "C:\tmp\salt.exe" +$webclient.DownloadFile($url, $file) + +# Install minion silently +Write-Host "Installing Salt minion..." +C:\tmp\salt.exe /S + +Write-Host "Waiting for Salt minion to start..." +# Give the minion some time to start before the highstate is called +Start-Sleep -s 5 diff --git a/plugins/provisioners/salt/provisioner.rb b/plugins/provisioners/salt/provisioner.rb index 4946cbc7f..fa14d3a6c 100644 --- a/plugins/provisioners/salt/provisioner.rb +++ b/plugins/provisioners/salt/provisioner.rb @@ -4,11 +4,6 @@ module VagrantPlugins module Salt class Provisioner < Vagrant.plugin("2", :provisioner) def provision - if @machine.config.vm.communicator == :winrm - raise Vagrant::Errors::ProvisionerWinRMUnsupported, - name: "salt" - end - upload_configs upload_keys run_bootstrap_script @@ -38,16 +33,29 @@ module VagrantPlugins ## Determine States, ie: install vs configure desired_binaries = [] if !@config.no_minion - desired_binaries.push('salt-minion') - desired_binaries.push('salt-call') + if @machine.config.vm.communicator == :winrm + desired_binaries.push('C:\\salt\\salt-minion.exe') + desired_binaries.push('C:\\salt\\salt-call.exe') + else + desired_binaries.push('salt-minion') + desired_binaries.push('salt-call') + end end if @config.install_master - desired_binaries.push('salt-master') + if @machine.config.vm.communicator == :winrm + desired_binaries.push('C:\\salt\\salt-master.exe') + else + desired_binaries.push('salt-master') + end end if @config.install_syndic - desired_binaries.push('salt-syndic') + if @machine.config.vm.communicator == :winrm + desired_binaries.push('C:\\salt\\salt-syndic.exe') + else + desired_binaries.push('salt-syndic') + end end found = true @@ -77,7 +85,11 @@ module VagrantPlugins end def temp_config_dir - return @config.temp_config_dir || "/tmp" + if @machine.config.vm.communicator == :winrm + return @config.temp_config_dir || "C:\\tmp" + else + return @config.temp_config_dir || "/tmp" + end end # Generates option string for bootstrap script @@ -191,7 +203,11 @@ module VagrantPlugins if @config.bootstrap_script bootstrap_abs_path = expanded_path(@config.bootstrap_script) else - bootstrap_abs_path = Pathname.new("../bootstrap-salt.sh").expand_path(__FILE__) + if @machine.config.vm.communicator == :winrm + bootstrap_abs_path = Pathname.new("../bootstrap-salt.ps1").expand_path(__FILE__) + else + bootstrap_abs_path = Pathname.new("../bootstrap-salt.sh").expand_path(__FILE__) + end end return bootstrap_abs_path @@ -212,25 +228,43 @@ module VagrantPlugins end bootstrap_path = get_bootstrap - bootstrap_destination = File.join(config_dir, "bootstrap_salt.sh") + if @machine.config.vm.communicator == :winrm + bootstrap_destination = File.join(config_dir, "bootstrap_salt.ps1") + else + bootstrap_destination = File.join(config_dir, "bootstrap_salt.sh") + end + @machine.communicate.sudo("rm -f %s" % bootstrap_destination) @machine.communicate.upload(bootstrap_path.to_s, bootstrap_destination) @machine.communicate.sudo("chmod +x %s" % bootstrap_destination) - bootstrap = @machine.communicate.sudo("%s %s" % [bootstrap_destination, options]) do |type, data| - if data[0] == "\n" - # Remove any leading newline but not whitespace. If we wanted to - # remove newlines and whitespace we would have used data.lstrip - data = data[1..-1] + if @machine.config.vm.communicator == :winrm + bootstrap = @machine.communicate.sudo("powershell.exe -executionpolicy bypass -file %s" % [bootstrap_destination]) do |type, data| + if data[0] == "\n" + # Remove any leading newline but not whitespace. If we wanted to + # remove newlines and whitespace we would have used data.lstrip + data = data[1..-1] + end + if @config.verbose + @machine.env.ui.info(data.rstrip) + end end - if @config.verbose - @machine.env.ui.info(data.rstrip) + else + bootstrap = @machine.communicate.sudo("%s %s" % [bootstrap_destination, options]) do |type, data| + if data[0] == "\n" + # Remove any leading newline but not whitespace. If we wanted to + # remove newlines and whitespace we would have used data.lstrip + data = data[1..-1] + end + if @config.verbose + @machine.env.ui.info(data.rstrip) + end end end if !bootstrap raise Salt::Errors::SaltError, :bootstrap_failed end - + if configure and !install @machine.env.ui.info "Salt successfully configured!" elsif configure and install @@ -242,14 +276,24 @@ module VagrantPlugins @machine.env.ui.info "Salt did not need installing or configuring." end end + def call_overstate if @config.run_overstate if @config.install_master @machine.env.ui.info "Calling state.overstate... (this may take a while)" - @machine.communicate.sudo("salt '*' saltutil.sync_all") - @machine.communicate.sudo("salt-run state.over") do |type, data| - if @config.verbose - @machine.env.ui.info(data) + if @machine.config.vm.communicator == :winrm + @machine.communicate.execute("C:\\salt\\salt.exe '*' saltutil.sync_all") + @machine.communicate.execute("C:\\salt\\salt-run.exe state.over") do |type, data| + if @config.verbose + @machine.env.ui.info(data) + end + end + else + @machine.communicate.sudo("salt '*' saltutil.sync_all") + @machine.communicate.sudo("salt-run state.over") do |type, data| + if @config.verbose + @machine.env.ui.info(data) + end end end else @@ -264,17 +308,35 @@ module VagrantPlugins if @config.run_highstate @machine.env.ui.info "Calling state.highstate... (this may take a while)" if @config.install_master - @machine.communicate.sudo("salt '*' saltutil.sync_all") - @machine.communicate.sudo("salt '*' state.highstate --verbose#{get_loglevel}#{get_colorize}#{get_pillar}") do |type, data| - if @config.verbose - @machine.env.ui.info(data) + if @machine.config.vm.communicator == :winrm + @machine.communicate.execute("C:\\salt\\salt.exe '*' saltutil.sync_all") + @machine.communicate.execute("C:\\salt\\salt.exe '*' state.highstate --verbose#{get_loglevel}#{get_colorize}#{get_pillar}") do |type, data| + if @config.verbose + @machine.env.ui.info(data) + end + end + else + @machine.communicate.sudo("salt '*' saltutil.sync_all") + @machine.communicate.sudo("salt '*' state.highstate --verbose#{get_loglevel}#{get_colorize}#{get_pillar}") do |type, data| + if @config.verbose + @machine.env.ui.info(data) + end end end else - @machine.communicate.sudo("salt-call saltutil.sync_all") - @machine.communicate.sudo("salt-call state.highstate #{get_loglevel}#{get_colorize}#{get_pillar}") do |type, data| - if @config.verbose - @machine.env.ui.info(data) + if @machine.config.vm.communicator == :winrm + @machine.communicate.execute("C:\\salt\\salt-call.exe saltutil.sync_all") + @machine.communicate.execute("C:\\salt\\salt-call.exe state.highstate #{get_loglevel}#{get_colorize}#{get_pillar}") do |type, data| + if @config.verbose + @machine.env.ui.info(data) + end + end + else + @machine.communicate.sudo("salt-call saltutil.sync_all") + @machine.communicate.sudo("salt-call state.highstate #{get_loglevel}#{get_colorize}#{get_pillar}") do |type, data| + if @config.verbose + @machine.env.ui.info(data) + end end end end From 2ddffa4fc640d6287429396dde267108df80f990 Mon Sep 17 00:00:00 2001 From: Marno van der Molen Date: Sat, 17 May 2014 03:31:24 +0200 Subject: [PATCH 02/10] redirect output of mkdir statement to out-null in bootstrap-salt.ps1 --- plugins/provisioners/salt/bootstrap-salt.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/provisioners/salt/bootstrap-salt.ps1 b/plugins/provisioners/salt/bootstrap-salt.ps1 index 0c52b1a85..e8aac47db 100644 --- a/plugins/provisioners/salt/bootstrap-salt.ps1 +++ b/plugins/provisioners/salt/bootstrap-salt.ps1 @@ -1,5 +1,5 @@ # Copy minion keys to correct location -New-Item c:\salt\conf\pki\minion\ -ItemType directory +New-Item c:\salt\conf\pki\minion\ -ItemType directory | out-null cp C:\tmp\minion.pem C:\salt\conf\pki\minion\ cp C:\tmp\minion.pub C:\salt\conf\pki\minion\ From 01f2c522511c692abf25c885f99a62e6879290c5 Mon Sep 17 00:00:00 2001 From: Marno van der Molen Date: Sat, 17 May 2014 03:38:57 +0200 Subject: [PATCH 03/10] sometimes salt-minion wouldn't start - this seems stable so far across 10 deploys --- plugins/provisioners/salt/bootstrap-salt.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/provisioners/salt/bootstrap-salt.ps1 b/plugins/provisioners/salt/bootstrap-salt.ps1 index e8aac47db..f8e256e6c 100644 --- a/plugins/provisioners/salt/bootstrap-salt.ps1 +++ b/plugins/provisioners/salt/bootstrap-salt.ps1 @@ -21,6 +21,7 @@ $webclient.DownloadFile($url, $file) Write-Host "Installing Salt minion..." C:\tmp\salt.exe /S -Write-Host "Waiting for Salt minion to start..." -# Give the minion some time to start before the highstate is called -Start-Sleep -s 5 +# Wait a bit +Start-Sleep -s 10 +net start salt-minion + From fbd919d52c40503e6d330657720c72ecb1759eeb Mon Sep 17 00:00:00 2001 From: Marno van der Molen Date: Mon, 19 May 2014 13:14:25 +0200 Subject: [PATCH 04/10] Retries starting the salt-minion service several times and adds elevated: true to salt calls --- plugins/provisioners/salt/bootstrap-salt.ps1 | 24 +++++++++++++++++--- plugins/provisioners/salt/provisioner.rb | 15 +++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/plugins/provisioners/salt/bootstrap-salt.ps1 b/plugins/provisioners/salt/bootstrap-salt.ps1 index f8e256e6c..6f284a426 100644 --- a/plugins/provisioners/salt/bootstrap-salt.ps1 +++ b/plugins/provisioners/salt/bootstrap-salt.ps1 @@ -21,7 +21,25 @@ $webclient.DownloadFile($url, $file) Write-Host "Installing Salt minion..." C:\tmp\salt.exe /S -# Wait a bit -Start-Sleep -s 10 -net start salt-minion +# Try starting the Salt minion service +Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue +$service = Get-Service salt-minion -ErrorAction SilentlyContinue +$try = 0 +# Retry starting the service 4 times if it's not running +# and wait 2 seconds between each try +While (($service.Status -eq "Stopped") -and ($try -ne 4)) { + Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue + $service = Get-Service salt-minion -ErrorAction SilentlyContinue + Start-Sleep -s 2 + $try += 1 +} + +# If the salt-minion service is still not running, something probably +# went wrong and user intervention is required - report failure. +if ($service.Status -eq "Stopped") { + Write-Host "Failed to start Salt minion" + exit 1 +} + +Write-Host "Salt minion successfully installed" diff --git a/plugins/provisioners/salt/provisioner.rb b/plugins/provisioners/salt/provisioner.rb index fa14d3a6c..6d403093c 100644 --- a/plugins/provisioners/salt/provisioner.rb +++ b/plugins/provisioners/salt/provisioner.rb @@ -282,8 +282,9 @@ module VagrantPlugins if @config.install_master @machine.env.ui.info "Calling state.overstate... (this may take a while)" if @machine.config.vm.communicator == :winrm - @machine.communicate.execute("C:\\salt\\salt.exe '*' saltutil.sync_all") - @machine.communicate.execute("C:\\salt\\salt-run.exe state.over") do |type, data| + opts = { elevated: true } + @machine.communicate.execute("C:\\salt\\salt.exe '*' saltutil.sync_all", opts) + @machine.communicate.execute("C:\\salt\\salt-run.exe state.over", opts) do |type, data| if @config.verbose @machine.env.ui.info(data) end @@ -309,8 +310,9 @@ module VagrantPlugins @machine.env.ui.info "Calling state.highstate... (this may take a while)" if @config.install_master if @machine.config.vm.communicator == :winrm - @machine.communicate.execute("C:\\salt\\salt.exe '*' saltutil.sync_all") - @machine.communicate.execute("C:\\salt\\salt.exe '*' state.highstate --verbose#{get_loglevel}#{get_colorize}#{get_pillar}") do |type, data| + opts = { elevated: true } + @machine.communicate.execute("C:\\salt\\salt.exe '*' saltutil.sync_all", opts) + @machine.communicate.execute("C:\\salt\\salt.exe '*' state.highstate --verbose#{get_loglevel}#{get_colorize}#{get_pillar}", opts) do |type, data| if @config.verbose @machine.env.ui.info(data) end @@ -325,8 +327,9 @@ module VagrantPlugins end else if @machine.config.vm.communicator == :winrm - @machine.communicate.execute("C:\\salt\\salt-call.exe saltutil.sync_all") - @machine.communicate.execute("C:\\salt\\salt-call.exe state.highstate #{get_loglevel}#{get_colorize}#{get_pillar}") do |type, data| + opts = { elevated: true } + @machine.communicate.execute("C:\\salt\\salt-call.exe saltutil.sync_all", opts) + @machine.communicate.execute("C:\\salt\\salt-call.exe state.highstate #{get_loglevel}#{get_colorize}#{get_pillar}", opts) do |type, data| if @config.verbose @machine.env.ui.info(data) end From 7cb50f8a125d5a3b40f07121c646736c9350c65e Mon Sep 17 00:00:00 2001 From: Marno van der Molen Date: Mon, 19 May 2014 14:00:46 +0200 Subject: [PATCH 05/10] Remove Salt Master & Salt Syndic changes - not supported on Windows by Salt --- plugins/provisioners/salt/provisioner.rb | 52 ++++++++---------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/plugins/provisioners/salt/provisioner.rb b/plugins/provisioners/salt/provisioner.rb index 6d403093c..3de295dda 100644 --- a/plugins/provisioners/salt/provisioner.rb +++ b/plugins/provisioners/salt/provisioner.rb @@ -44,7 +44,8 @@ module VagrantPlugins if @config.install_master if @machine.config.vm.communicator == :winrm - desired_binaries.push('C:\\salt\\salt-master.exe') + raise Vagrant::Errors::ProvisionerWinRMUnsupported, + name: "salt.install_master" else desired_binaries.push('salt-master') end @@ -52,7 +53,8 @@ module VagrantPlugins if @config.install_syndic if @machine.config.vm.communicator == :winrm - desired_binaries.push('C:\\salt\\salt-syndic.exe') + raise Vagrant::Errors::ProvisionerWinRMUnsupported, + name: "salt.install_syndic" else desired_binaries.push('salt-syndic') end @@ -279,27 +281,17 @@ module VagrantPlugins def call_overstate if @config.run_overstate - if @config.install_master - @machine.env.ui.info "Calling state.overstate... (this may take a while)" - if @machine.config.vm.communicator == :winrm - opts = { elevated: true } - @machine.communicate.execute("C:\\salt\\salt.exe '*' saltutil.sync_all", opts) - @machine.communicate.execute("C:\\salt\\salt-run.exe state.over", opts) do |type, data| - if @config.verbose - @machine.env.ui.info(data) - end - end - else - @machine.communicate.sudo("salt '*' saltutil.sync_all") - @machine.communicate.sudo("salt-run state.over") do |type, data| - if @config.verbose - @machine.env.ui.info(data) - end - end + if @config.install_master + @machine.env.ui.info "Calling state.overstate... (this may take a while)" + @machine.communicate.sudo("salt '*' saltutil.sync_all") + @machine.communicate.sudo("salt-run state.over") do |type, data| + if @config.verbose + @machine.env.ui.info(data) end - else - @machine.env.ui.info "run_overstate does not make sense on a minion. Not running state.overstate." end + else + @machine.env.ui.info "run_overstate does not make sense on a minion. Not running state.overstate." + end else @machine.env.ui.info "run_overstate set to false. Not running state.overstate." end @@ -309,20 +301,10 @@ module VagrantPlugins if @config.run_highstate @machine.env.ui.info "Calling state.highstate... (this may take a while)" if @config.install_master - if @machine.config.vm.communicator == :winrm - opts = { elevated: true } - @machine.communicate.execute("C:\\salt\\salt.exe '*' saltutil.sync_all", opts) - @machine.communicate.execute("C:\\salt\\salt.exe '*' state.highstate --verbose#{get_loglevel}#{get_colorize}#{get_pillar}", opts) do |type, data| - if @config.verbose - @machine.env.ui.info(data) - end - end - else - @machine.communicate.sudo("salt '*' saltutil.sync_all") - @machine.communicate.sudo("salt '*' state.highstate --verbose#{get_loglevel}#{get_colorize}#{get_pillar}") do |type, data| - if @config.verbose - @machine.env.ui.info(data) - end + @machine.communicate.sudo("salt '*' saltutil.sync_all") + @machine.communicate.sudo("salt '*' state.highstate --verbose#{get_loglevel}#{get_colorize}#{get_pillar}") do |type, data| + if @config.verbose + @machine.env.ui.info(data) end end else From 6d0dd22864b5c9d4508a4d994b2538e7a6eca3fb Mon Sep 17 00:00:00 2001 From: Marno van der Molen Date: Mon, 19 May 2014 14:01:31 +0200 Subject: [PATCH 06/10] Also copy minion config in bootstrap-salt.ps1 & update Salt docs to mention syndic/master not supported on Windows --- plugins/provisioners/salt/bootstrap-salt.ps1 | 3 ++- website/docs/source/v2/provisioning/salt.html.md | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/provisioners/salt/bootstrap-salt.ps1 b/plugins/provisioners/salt/bootstrap-salt.ps1 index 6f284a426..61ce14ad5 100644 --- a/plugins/provisioners/salt/bootstrap-salt.ps1 +++ b/plugins/provisioners/salt/bootstrap-salt.ps1 @@ -1,7 +1,8 @@ -# Copy minion keys to correct location +# Copy minion keys & config to correct location New-Item c:\salt\conf\pki\minion\ -ItemType directory | out-null cp C:\tmp\minion.pem C:\salt\conf\pki\minion\ cp C:\tmp\minion.pub C:\salt\conf\pki\minion\ +cp C:\tmp\minion C:\salt\conf\ # Detect architecture if ([IntPtr]::Size -eq 4) { diff --git a/website/docs/source/v2/provisioning/salt.html.md b/website/docs/source/v2/provisioning/salt.html.md index 2f2f3fe4f..f66ac7c60 100644 --- a/website/docs/source/v2/provisioning/salt.html.md +++ b/website/docs/source/v2/provisioning/salt.html.md @@ -48,18 +48,19 @@ masterless setup. * `install_master` (boolean) - Should vagrant install the salt-master -on this machine +on this machine. Not supported on Windows. * `no_minion` (boolean) - Don't install the minion, default `false` * `install_syndic` (boolean) - Install the salt-syndic, default -`false` +`false`. Not supported on Windows. * `install_type` (stable | git | daily | testing) - Whether to install from a -distribution's stable package manager, git tree-ish, daily ppa, or testing repository. +distribution's stable package manager, git tree-ish, daily ppa, or testing repository. +Not supported on Windows. * `install_args` (develop) - When performing a git install, -you can specify a branch, tag, or any treeish. +you can specify a branch, tag, or any treeish. Not supported on Windows. * `always_install` (boolean) - Installs salt binaries even if they are already detected, default `false` From 1ddef491852cdca5cde8bc3bc73dfd407f843557 Mon Sep 17 00:00:00 2001 From: Marno van der Molen Date: Mon, 19 May 2014 14:10:58 +0200 Subject: [PATCH 07/10] minor indentation fix --- plugins/provisioners/salt/provisioner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/provisioners/salt/provisioner.rb b/plugins/provisioners/salt/provisioner.rb index 3de295dda..a330edfdd 100644 --- a/plugins/provisioners/salt/provisioner.rb +++ b/plugins/provisioners/salt/provisioner.rb @@ -308,7 +308,7 @@ module VagrantPlugins end end else - if @machine.config.vm.communicator == :winrm + if @machine.config.vm.communicator == :winrm opts = { elevated: true } @machine.communicate.execute("C:\\salt\\salt-call.exe saltutil.sync_all", opts) @machine.communicate.execute("C:\\salt\\salt-call.exe state.highstate #{get_loglevel}#{get_colorize}#{get_pillar}", opts) do |type, data| From fc3a2106fd59a0bcf0cd52152b62dbe87ee90122 Mon Sep 17 00:00:00 2001 From: Marno van der Molen Date: Mon, 19 May 2014 15:52:20 +0200 Subject: [PATCH 08/10] Only try to copy keys & config if they have been uploaded --- plugins/provisioners/salt/bootstrap-salt.ps1 | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/provisioners/salt/bootstrap-salt.ps1 b/plugins/provisioners/salt/bootstrap-salt.ps1 index 61ce14ad5..78b1dd39b 100644 --- a/plugins/provisioners/salt/bootstrap-salt.ps1 +++ b/plugins/provisioners/salt/bootstrap-salt.ps1 @@ -1,8 +1,16 @@ # Copy minion keys & config to correct location New-Item c:\salt\conf\pki\minion\ -ItemType directory | out-null -cp C:\tmp\minion.pem C:\salt\conf\pki\minion\ -cp C:\tmp\minion.pub C:\salt\conf\pki\minion\ -cp C:\tmp\minion C:\salt\conf\ + +# Check if minion keys have been uploaded +if (Test-Path C:\tmp\minion.pem) { + cp C:\tmp\minion.pem C:\salt\conf\pki\minion\ + cp C:\tmp\minion.pub C:\salt\conf\pki\minion\ +} + +# Check if minion config has been uploaded +if (Test-Path C:\tmp\minion) { + cp C:\tmp\minion C:\salt\conf\ +} # Detect architecture if ([IntPtr]::Size -eq 4) { From 6c9787483993889f95a70d518d54b615f08fd52f Mon Sep 17 00:00:00 2001 From: Marno van der Molen Date: Mon, 19 May 2014 17:50:22 +0200 Subject: [PATCH 09/10] Wait for to be populated & explicitly check for Running status of service --- plugins/provisioners/salt/bootstrap-salt.ps1 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/provisioners/salt/bootstrap-salt.ps1 b/plugins/provisioners/salt/bootstrap-salt.ps1 index 78b1dd39b..1b5d149e5 100644 --- a/plugins/provisioners/salt/bootstrap-salt.ps1 +++ b/plugins/provisioners/salt/bootstrap-salt.ps1 @@ -35,9 +35,14 @@ Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue $service = Get-Service salt-minion -ErrorAction SilentlyContinue $try = 0 +While (!$service) { + Start-Sleep -s 2 + $service = Get-Service salt-minion -ErrorAction SilentlyContinue +} + # Retry starting the service 4 times if it's not running # and wait 2 seconds between each try -While (($service.Status -eq "Stopped") -and ($try -ne 4)) { +While (($service.Status -ne "Running") -and ($try -ne 4)) { Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue $service = Get-Service salt-minion -ErrorAction SilentlyContinue Start-Sleep -s 2 From 500c40fd42dbc8d1c1cda80858e58c225899fe73 Mon Sep 17 00:00:00 2001 From: Marno van der Molen Date: Mon, 19 May 2014 19:00:18 +0200 Subject: [PATCH 10/10] Now wait for service to be registered before trying to start it --- plugins/provisioners/salt/bootstrap-salt.ps1 | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/plugins/provisioners/salt/bootstrap-salt.ps1 b/plugins/provisioners/salt/bootstrap-salt.ps1 index 1b5d149e5..10138281f 100644 --- a/plugins/provisioners/salt/bootstrap-salt.ps1 +++ b/plugins/provisioners/salt/bootstrap-salt.ps1 @@ -30,18 +30,19 @@ $webclient.DownloadFile($url, $file) Write-Host "Installing Salt minion..." C:\tmp\salt.exe /S -# Try starting the Salt minion service -Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue +# Wait for salt-minion service to be registered before trying to start it $service = Get-Service salt-minion -ErrorAction SilentlyContinue -$try = 0 - While (!$service) { - Start-Sleep -s 2 - $service = Get-Service salt-minion -ErrorAction SilentlyContinue + Start-Sleep -s 2 + $service = Get-Service salt-minion -ErrorAction SilentlyContinue } -# Retry starting the service 4 times if it's not running -# and wait 2 seconds between each try +# Start service +Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue + +# Check if service is started, otherwise retry starting the +# service 4 times. +$try = 0 While (($service.Status -ne "Running") -and ($try -ne 4)) { Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue $service = Get-Service salt-minion -ErrorAction SilentlyContinue