Install-BoxStarterPackage on remote machine with Invoke-Reboot installs first package repeatedly

Feb 8, 2014 at 6:09 AM
Edited Feb 8, 2014 at 6:17 AM
Using BoxStarter v2.3.24 and Chocolatey v0.9.8.23

Using the ChocolateyInstall.ps1 below. Setup a simple read only NuGet.Server that works just fine with Chocolatey, and each of the individual chocolatey packages being referenced have been tested successfully with Chocolatey. Trying to use BoxStarter to remotely deploy my chocolatey packages and survive reboots.

I add my internal repo to the boxstarter config. First package installs successfully (install-iis_tc setsup 23 features for IIS) and the remote box is rebooted. BoxStarter reconnects and kicks off the BoxStarter package, but it doesn't resume on the 2nd cinst for SetupXFF_64. Instead it tries to install the first package again (which is already installed). Remote box reboots, then the cycle starts over again.

Am I missing something obvious?

I haven't tried running it locally from the remote server console - I've been able to stop the cycle by killing the BoxStarter shell on my local computer which breaks the session to the remote server, but the remote server is a VM in a remote data center and I'm not sure yet how to stop this cycle if I can't RDP into the box fast enough or know which remote commands to issue to kill it!

Thanks in advance!


Set-ExecutionPolicy Unrestricted -Force
cinst install-iis_tc -source
cinst SetupXFF_x64 -source
cinst IIS-AppWarmup_x64 -source
Using the following command after setting the $cred:
$cred = Get-Credential username
Install-BoxStarterPackage -ComputerName -Package myPackage -Credential $cred
I've also tried using it if setting up a remote session:
$cred = Get-Credential username
$session = New-PSSession -Credential $cred
Install-BoxStarterPackage -Session $session -Package myPackage -Credential $cred
Feb 8, 2014 at 6:55 AM
Hi there,

Yes there is one key thing that needs to be corrected here. Having the explicit Invoke-Reboot will always reboot at that point in the script. The Invoke-Reboot command should only be used if you absolutely know you need to reboot and you should include some kind of IF condition otherwise the reboot will always occur. In most cases, like yours as well I think, you do not need the Invoke-Reboot. Before every call to CINST, Boxstarter checks for pending reboots and will reboot if it detects one, so in your case you should simply remove them.

Does that make sense?
Marked as answer by jfosc on 2/9/2014 at 7:43 PM
Feb 8, 2014 at 2:06 PM
Thanks for the reply!

I removed the reboot statements and rebuilt the package. Two of my chocolatey packages require reboots (based on output of manual installs before I built the chocolatey packages) and I got different results depending on the order I put them in the BoxStarter package. (install-iis_tc requires a reboot as does IIS-AppWarmup_x64)

I just did two tests with the packages in slightly different order. I was thinking that the install-iis_tc, which is basically powershell add-windowsfeature installing IIS with some features, perhaps didn't set the pending reboot flag. so I changed the order in a 2nd test to see the effects. In the order listing below, rq=reboot required (per the manual install prior to converting into silent/chocolatey packages)

First test order: install-iis_tc (rq), SetupXFF_x64, IIS-AppWarmup_x64 (rq).
Result: I got a reboot at the end only.

Second test order: install-iis_tc (rq), IIS-AppWarmup_x64 (rq), SetupXFF_x64
Result: Reboot after install-iis_tc only, forcing me to manually reboot at the end to address the reboot of IIS-AppWarmup_x64

Not sure why if there are two reboots required I only get one and why that one reboot occurs at different times.

(As a side note, I also had a weird issue with the PS execution policy using set-exectionpolicy vs update-execution policy. I'll keep an eye on this one but it tells me that the policy has been updated but the setting is overridden by a policy defined at a more specific scope. when I removed the invoke-reboot my set-executionpolicy command seemed to break the permissions. I modified it to update-execution policy and while I still get the error it at least installs)

Feb 10, 2014 at 4:02 AM
Wanted to thank you again, Matt. I did a bit of additional testing - seems that the only chocolatey package that requires a reboot is the IIS install. I lifted the Get-PendingReboot function from The Scripting Guys that you also leverage in the Test-PendingReboot. I installed the chocolatey packages manually to confirm whether or not they tripped the flags checked, checking them with Get-PendingReboot.

I'm still a bit confused by some of the difference in behavior though. In case 1, if I force a reboot after the IIS install with Invoke-Reboot it forces the install of the first package again and the cycle repeats and it never moves on. In case 2, if I remove the Invoke-Reboot let BoxStarter detect the need for the reboot, it resumes the BoxStarter script from the start (e.g. the need for the individually chocolatey package to be repeatable/not break anything to be installed a second time) but doesn't go through the actual install again and moves on.

Case 1:
After the reboot:
[MyServer]Boxstarter: Waiting for Computer Configuration Manager to stop...
[MyServer]+ Boxstarter starting Calling Chocolatey to install tcWebBuild. This may take several minutes to complete...
Chocolatey (v0.9.8.23) is installing 'tcWebBuild' and dependencies. By installing you accept the license for 'tcWebBuild' and each dependency you are installing.
______ tcWebBuild v1.0.0 ______
[MyServer]Boxstarter: Setting powershell execution context to Unrestricted
[MyServer]++ Boxstarter starting Calling Chocolatey to install install-iis_tc. This may take several minutes to complete...
Chocolatey (v0.9.8.23) is installing 'install-iis_tc' and dependencies. By installing you accept the license for 'install-iis_tc' an
d each dependency you are installing.
'install-iis_tc 1.0' already installed.
If you want to reinstall the current version of an existing package, please use the -force command.

Finished installing 'install-iis_tc' and dependencies - if errors not shown in console, none detected. Check log for errors if unsur
[MyServer]++ Boxstarter finished Calling Chocolatey to install install-iis_tc. This may take several minutes to complete... 00:
[MyServer]++ Boxstarter starting Calling Chocolatey to install IIS-AppWarmup_x64. This may take several minutes to complete...
Chocolatey (v0.9.8.23) is installing 'IIS-AppWarmup_x64' and dependencies. By installing you accept the license for 'IIS-AppWarmup_x
64' and each dependency you are installing.
______ IIS-AppWarmup_x64 v1.0 ______
Case 2
I didn't save the output in this case, but it actually went through the install of IIS again each time it rebooted, and that was the repeating issue.
What drives the different behavior?

(This is an awesome tool - thx so much for building and maintaining it!)
Feb 10, 2014 at 11:10 AM
Hi. Sorry for the confusion here. I definitely need to add some info to the docs on creating packages that touches on this. Let me try to explain the difference.

If you have an Invoke-Reboot in your script without any condition, then the script will always reboot, start from the beginning and then reboot again when it gets to the Invoke-Reboot again. Using Invoke-Reboot is really only necessary if you are doing something that Boxstarter does not already intercept and you know needs a reboot in order to continue successfully. Boxstarter intercepts all calls to chocolatey's installer and also calls to windows update if you use the Install-WindowsUpdate command.

When you omit the Invoke-Reboot, Boxstarter determines if a reboot is pending when it gets to your second cinst and reboots. After a reboot, when the Chocolatey installer of your first package is called, Chocolatey notices that package has already been installed and so moves on to the next without installing again.

This is not always the right course of action for Windows roles/features but there is a better way to handle this.

Instead of wrapping calls to the ServerManager module or DISM inside of a separate package, Chocolatey supports a "WindowsFeature" feed. For example, using:
CINST IIS-WebServerRole -source windowsfeatures
Installs the IIS-WebserverRole features. Simply use the same feature name you would normally use with DISM.exe.

The advantage of doing this is that Chocolatey uses a slightly different strategy for checking if the feature is installed. Instead of simply looking to see if you have installed the package before, Chocolatey inspects the "State" of the feature and only skips it if it is "Enabled" or "Enable Pending." If you are using windows 8/2012 or higher, Chocolatey uses the "/ALL" switch in DISM which will install any dependent features of the feature you are installing.

Hope this clarifies things.
Feb 14, 2014 at 1:57 AM
Thanks for the info, Matt! It definitely clarifies things.

I'll take a look at using the windowsfeatures source!