windows - Azure Custom Script Extension continually restarting -


having bit of trouble azure custom script extension on windows vm. have created script installs particular business application. in order accomplish this, script calls several other scripts , reboot required in between 2 scripts.

the script designed such can "pick left off" checking whether files exist or if registry keys exist. reboot portion of goes fine, however, i'm noticing script handler sets several registry keys keep track of state in

hkey_local_machine\software\microsoft\windows azure\scripthandler

i see registry value called "mreseqnumstarted", presume how script handler keeps track of script it's executing. there 1 script fired extension currently, , value set 0.

what i'm seeing, that, when machine rebooted after script has completed, script fires again. occurs every reboot of virtual machine. believe script extension not marking script "completed", , i'm @ loss why. basic (sanitized) flow of script below:

trap {$_.exception.message; get-pscallstack;continue}  if(test-path c:\scriptlog.txt) {     add-content "c:\scriptlog.txt" "`nscript run, prior log exists." } else {     write-host "begin script" | out-file "c:\scriptlog.txt" }  #$storagepath = [uri]::escapedatastring($storagepath) #create directory structure , download scripts/files if(test-path c:\prepareplatform\) {     add-content "c:\scriptlog.txt" "`nfiles downloaded... continuing" } else {     new-item -itemtype directory -force -path c:\softwarename\prepareplatform\     (new-object net.webclient).downloadfile('sas-url-goes-here','c:\softwarename\prepareplatform\prepareplatform.zip');(new-object -com shell.application).namespace('c:\softwarename\prepareplatform').copyhere((new-object -com shell.application).namespace('c:\softwarename\prepareplatform\prepareplatform.zip').items(),16)     (new-object net.webclient).downloadfile('sas-url-goes-here','c:\softwarename\somezip.zip');(new-object -com shell.application).namespace('c:\softwarename').copyhere((new-object -com shell.application).namespace('c:\softwarename\somezip.zip').items(),16)     add-content "c:\scriptlog.txt" "`nextracted install media" }  if(test-path c:\softwarename\preparedone.txt)   {     add-content "c:\scriptlog.txt" "`nprepareplatform completed... continuing" } else {     invoke-expression "set-location c:\softwarename\prepareplatform\; c:\softwarename\prepareplatform\prepare-windowsplatform.ps1"     createsqluser -identifiervalue $value -sapassword $sqlsapassword -tenantpass $tenantsqlpassword     createsqllogin -identifiervalue $value -sapassword $sqlsapassword -tenantpass $tenantsqlpassword     write-host "prepareplatform complete" | out-file "c:\softwarename\preparedone.txt" } if(test-path c:\softwarename\updateplatform.txt)    {     add-content "c:\scriptlog.txt" "`nupdateplatform completed... continuing" } else {     add-content "c:\scriptlog.txt" "`nbegin update-platform"     invoke-expression "set-location c:\softwarename\prepareplatform\; c:\softwarename\prepareplatform\update-windowsplatform.ps1"     write-host "updateplatform complete" | out-file "c:\softwarename\updateplatform.txt" }  if(test-path c:\softwarename\rebooted.txt)  {     add-content "c:\scriptlog.txt" "`nreboot completed... continuing" } else {     write-host "rebooting" | out-file "c:\softwarename\rebooted.txt"     restart-computer -force     restart-computer -force     start-sleep 3600 #make sure nothing else executes }   #  todo:  make more robust potentially more nodes... need delay 1 hour each node if($env:computername -eq 'pvm-softwarename-1') { write-output "second node, waiting 1 hour"; add-content "c:\scriptlog.txt" "`nnot first node, waiting 1 hour" ;start-sleep -seconds 3600 }   add-content "c:\scriptlog.txt" "`nprepare softwarename installers" set-location c:\softwarename\script\; c:\softwarename\script\prepare-softwarenameinstallers.ps1 -neededparameters $values add-content "c:\scriptlog.txt" "`nprepare softwarename installers complete"  try {         if(-not (get-service -name 'softwarename server')) {             c:\softwarename\script\install-softwarenamebp.ps1 -neededparameters $values         } else {             add-content "c:\scriptlog.txt" "`n installed!"         }  } catch {     $_.exception.message;get-pscallstack     if (-not (get-service -name 'softwarename server').status -eq 'running')      {throw "service unavailable"}  } write-output "install finished." try {     if(-not ((invoke-webrequest -uri https://iissiteurl/).statuscode -eq '200'))     c:\softwarename\script\install-softwarenamesf.ps1 -neededparameters $values } catch {     $_.exception.message;get-pscallstack     if(-not (test-path -path "hklm:\software\wow6432node\microsoft\windows\currentversion\uninstall\{aguid}") )     {throw "smartforms install failed"}  } try {     #begin     c:\softwarename\script\install-softwarenamesp.ps1 -neededparameters $values } catch {     $_.exception.message;get-pscallstack     if(-not (test-path -path "hklm:\software\wow6432node\microsoft\windows\currentversion\uninstall\{aguid}") )     {throw "sharepoint install failed"} }     try {     #[bool]$skipdeploy     #if($env:computername -eq 'pvm-softwarename-0') { $skipdeploy = $false } else { $skipdeploy = $true }      #begin     c:\softwarename\script\install-softwarenamemg.ps1  -neededparameters $values catch {     $_.exception.message;get-pscallstack     if(-not (test-path -path "hklm:\software\wow6432node\microsoft\windows\currentversion\uninstall\{aguid}") )     {throw "management install failed"} }         try {      c:\softwarename\script\install-finalize.ps1  -neededparameters $values } catch {     $_.exception.message;get-pscallstack     if(-not (test-path -path "hklm:\software\wow6432node\microsoft\windows\currentversion\uninstall\{aguid}") )     {throw "install finalize failed"} }  #kill script add-content "c:\scriptlog.txt" "`nscript completed" exit 

below expected output of c:\scriptlog.txt

begin scheduled job regstration extracted install media begin prepareplatform completed prepareplatform begin update-platform script run, prior log exists. files downloaded... continuing prepareplatform completed... continuing updateplatform completed... continuing reboot completed... continuing prepare softwarename installers prepare softwarename installers complete c:\softwarename\script\install-k2bp.ps1 -parametervalues $values c:\softwarename\script\install-k2sf.ps1 -parametervalues $values c:\softwarename\script\install-k2sp.ps1 -parametervalues $values c:\softwarename\script\install-k2mg.ps1 -parametervalues $values c:\softwarename\script\install-finalize.ps1 -parametervalues $values script completed 

after reboot, same log file:

begin scheduled job regstration extracted install media begin prepareplatform completed prepareplatform begin update-platform script run, prior log exists. files downloaded... continuing prepareplatform completed... continuing updateplatform completed... continuing reboot completed... continuing prepare softwarename installers prepare softwarename installers complete c:\softwarename\script\install-softwarenamebp.ps1 -neededparameters $values c:\softwarename\script\install-softwarenamesf.ps1 -neededparameters $values c:\softwarename\script\install-softwarenamesp.ps1 -neededparameters $values c:\softwarename\script\install-softwarenamemg.ps1 -neededparameters $values c:\softwarename\script\install-finalize.ps1 -neededparameters $values script completed script run, prior log exists. files downloaded... continuing prepareplatform completed... continuing updateplatform completed... continuing reboot completed... continuing prepare softwarename installers prepare softwarename installers complete c:\softwarename\script\install-softwarenamebp.ps1 -neededparameters $values... 

edit1: i've commented out calls external scripts. script @ point writes output file effectivley , traps exceptions in doing so. script continues re-fire every vm reboot.


Comments