MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.2k stars 21.35k forks source link

Own script to restart the VM while building without error on Packer? #111372

Closed ii-batman closed 1 year ago

ii-batman commented 1 year ago

Hi Team,

I am using the new AVD Custom Image Integration from the Portal and I am loving the customisers.

I need to add my own script since the Built-In Scripts: Install-LanguagePack and Set-LanguagePack options are not working as these add a restart and I think packer fails right after.

I have tested without the Language Built-In scripts and the image build finished fine.

I want to add my own Language scripts but I would like to know how to create a powershell script to add to Own Scripts that won't make Packer think that there is an issue and fail the build?

Thanks, ii @dknappettmsft


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

Naveenommi-MSFT commented 1 year ago

@ii-batman Thanks for your feedback! We will investigate and update as appropriate.

lukemurraynz commented 1 year ago

Take a look at this blog article: https://endpointcave.com/the-easiest-way-to-install-language-pack-via-intune/

I think what you might be looking for: is Exit.

ie if you finish the script with Exit 0 - then it won't report an error, of course, if the Language fails to install then you won't know, so you need to make sure there are other ways to do the verification.

ii-batman commented 1 year ago

@lukemurraynz 😊 I don't think it's that. I found this nerdio doc I think the language setup messes with sysprep that is why on the portal they added a reboot - this reboot is not happening and that is destroying the build. Do you know of a way to reboot via powershell so packer won't break? I did a script with shutdown /r /f /t 0 /c "packer restart" but this didn't work as expected.

lukemurraynz commented 1 year ago

FYI: This isn't a place to usually get support; it's mainly for Microsoft documentation changes and adjustments and additions; your best bet would be to go to: Microsoft Q&A, where I or someone else can help you properly, having said that:

This should work - https://developer.hashicorp.com/packer/docs/provisioners/shell.

As part of an image build, you should restart; what happens when you run it? You should be able to install the language packs, restart as a separate step - then continue the build process to install Windows patches, which will also require a restart.

What error are you getting?

ii-batman commented 1 year ago

Hi @lukemurraynz I understand this is a doc page and I thank you for trying to help me - specially on a Sunday! This is my scenario please see pic attached. I am configuring an image template from the Azure AVD Custom Image Template. There is no option to add a restart in "add built in scripts" so I need to add it in "add own scripts" so I add an own script to reboot. The script that I am adding is a PowerShell doing: shutdown /r /f /t 0 /c "packer restart" This kills the build with error: [INFO] RPC endpoint: Communicator ended with: 267014

I don't know how else I can add a reboot via this portal and I am not the best with json config. Hope this makes sense and I thank you once again.

question1
lukemurraynz commented 1 year ago

I'm looking into it - but as a workaround,set the Apply Windows Update to the last step; the Windows Update step should reboot the Virtual Machine to install the patches.

lukemurraynz commented 1 year ago

I believe this is not working, as its using the Portal interface; you could try adding Timeout to your restart script:

Restart-Computer -Timeout 300 -Force

However, I don't think this will work; Azure Image Builder needs a way of monitoring the virtual machine to make sure it's getting restarted - It doesn't look like the Portal interface (which is still in Public Preview) is able to control this.

As a workaround, set the Windows Update step to the last - and I will feed this to the product team; no doubt it's on their list, as I see this being a common scenario.

The alternative is to use Azure Bicep or ARM etc. to deploy the Azure Image Builder components, including the restart customizer.

ii-batman commented 1 year ago

@lukemurraynz Putting the Windows update step as last won't make a diff as the Language steps automattically had the reboots right after, I can see it on the json. { "name": "avdBuiltInScript_installLanguagePacks-parameter", "type": "PowerShell", "inline": [ "C:\\AVDImage\\installLanguagePacks.ps1 -LanguageList \"English (United Kingdom)\"" ], "runAsSystem": true, "runElevated": true }, { "name": "avdBuiltInScript_installLanguagePacks-windowsRestart", "type": "WindowsRestart", "restartCheckCommand": "", "restartCommand": "", "restartTimeout": "10m" }, {

}, { "name": "avdBuiltInScript_setDefaultLanguage", "type": "File", "destination": "C:\\AVDImage\\setDefaultLanguage.ps1", "sourceUri": "https://raw.githubusercontent.com/Azure/RDS-Templates/master/CustomImageTemplateScripts/CustomImageTemplateScripts_2023-05-16/SetDefaultLang.ps1" }, { "name": "avdBuiltInScript_setDefaultLanguage-parameter", "type": "PowerShell", "inline": [ "C:\\AVDImage\\setDefaultLanguage.ps1 -Language \"English (United Kingdom)\"" ], "runAsSystem": true, "runElevated": true }, { "name": "avdBuiltInScript_setDefaultLanguage-windowsRestart", "type": "WindowsRestart", "restartCheckCommand": "", "restartCommand": "", "restartTimeout": "5m" } ]

YashikaTyagii commented 1 year ago

@lukemurraynz Thanks for providing your inputs to the Thread. Really Appreciate that.

lukemurraynz commented 1 year ago

@lukemurraynz Putting the Windows update step as last won't make a diff as the Language steps automattically had the reboots right after, I can see it on the json. { "name": "avdBuiltInScript_installLanguagePacks-parameter", "type": "PowerShell", "inline": [ "C:\\AVDImage\\installLanguagePacks.ps1 -LanguageList \"English (United Kingdom)\"" ], "runAsSystem": true, "runElevated": true }, { "name": "avdBuiltInScript_installLanguagePacks-windowsRestart", "type": "WindowsRestart", "restartCheckCommand": "", "restartCommand": "", "restartTimeout": "10m" }, {

}, { "name": "avdBuiltInScript_setDefaultLanguage", "type": "File", "destination": "C:\\AVDImage\\setDefaultLanguage.ps1", "sourceUri": "https://raw.githubusercontent.com/Azure/RDS-Templates/master/CustomImageTemplateScripts/CustomImageTemplateScripts_2023-05-16/SetDefaultLang.ps1" }, { "name": "avdBuiltInScript_setDefaultLanguage-parameter", "type": "PowerShell", "inline": [ "C:\\AVDImage\\setDefaultLanguage.ps1 -Language \"English (United Kingdom)\"" ], "runAsSystem": true, "runElevated": true }, { "name": "avdBuiltInScript_setDefaultLanguage-windowsRestart", "type": "WindowsRestart", "restartCheckCommand": "", "restartCommand": "", "restartTimeout": "5m" } ]

Thanks, I've reached out to the product team for assistance, will let you know if I hear anything

dknappettmsft commented 1 year ago

Hi @ii-batman - thanks for the feedback. As @lukemurraynz mentioned previously, this isn't the correct place to log issues with the product. Microsoft Q&A is a good choice, or the AVD forum: https://techcommunity.microsoft.com/t5/azure-virtual-desktop/bd-p/AzureVirtualDesktopForum

I have spoken with the PM for this feature and they have asked that you open a support ticket for this so they can work with you and gather logs. You can do that in the Azure portal.

As this isn't for docs, and because I'm not the right person to help you further, I'll close this and your other request. Support will continue this once you've logged it.

please-close

abjinugurxo commented 4 months ago

@ii-batman any luck?