VMware Cloud Community
hawks76
Enthusiast
Enthusiast
Jump to solution

vRA Software Components script error

So, i have a software component that installs SQL and all the tools, and then sets the TCP port to a random number.  The code runs fine, and everything works as expected, but when the port change code runs in the configure phase of the software component, it always exits with an error of exit code 1.  i have looked through all the logs and i can't find anywhere why it's exiting with and error.

I have attached a screen shot.  It's also worth noting that this only happens on SQL 2017 installs, but works fine on SQL 2016 install.  I'm using the same vCenter template (Windows 2016 Standard).  The only difference is the version of SQL.  I can run the code locally under the same user account, and it runs perfectly fine.

Any help is greatly appreciated.

Reply
0 Kudos
1 Solution

Accepted Solutions
hawks76
Enthusiast
Enthusiast
Jump to solution

NOTE:  This is just a work around that fixed the symptoms of the main issue.  This still does not solve the problem i was getting with the exit code of 1.  There is continued discussion around that and how to troubleshoot it effectively.

So, it would seem the fix for this is easier than expected.

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Tcp\' -Name "Enabled" -Value 1

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Tcp\IPAll\' -Name "TcpPort" -Value "random_port_number"

(for versions other than SQL 2017, replace the MSSQL14.MSSQLSERVER with MSSQL##.MSSQLSERVER, where the ## corresponds with the version of SQL you are installing.)

restart the services, and presto!!  Had the SQL guys verify that this works like the expect it too, so if it's wrong, i blame them.....   🙂

View solution in original post

Reply
0 Kudos
43 Replies
daphnissov
Immortal
Immortal
Jump to solution

This is just one of those things you're going to have to troubleshoot from a code level as it's not a failure or problem with vRA software components. Any exit code other than a 0 is interpreted as a failure, regardless of whether there was an error logged to stdout/stderr. Depending on how you're coding this, it could be a process/command that simply returns a 1 because it did something (robocopy does this) or because of another reason. In the past when I've dealt with this, my general workflow is to first determine if the component did its job. If everything was successful, then handle the error code. If so, catch the code and reset it to 0 at the end of the script. But in doing this, you have to be very careful that you rely upon some other method to determine success/failure like an install log/manifest which can be parsed to look for those things. This is typically more complex because there are hundreds or thousands of possibilities that you may not be able to foresee.

Reply
0 Kudos
hawks76
Enthusiast
Enthusiast
Jump to solution

Yeah, i know this isn't a software component issue.  That's what i'm asking for help with is how to troubleshoot the script in the software component.  I put a try-catch block in the script, but still got the same result.  I have narrowed down the block of code that seems to be the problem, but everything executes properly.  I'll change the title to be a more accurate description of my problem incase anyone else has a similar issue. 

Reply
0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

Periodically check the system variable $LASTEXITCODE for anything that's non-zero. Otherwise, like I recommended, you can just strong-arm it back to 0 every time. A try-catch block won't work if it isn't throwing it to stderr, which just because it's non-zero doesn't mean it'll do that. This blog may help.

Reply
0 Kudos
hawks76
Enthusiast
Enthusiast
Jump to solution

So, i placed the $LASTEXITCODE where i thought the code was going sideways, and it always returned 0.  So, i placed it after every line. Still always returned 0. Set the $LASTEXITCODE to 0 in the last line of the script, and it still returned an error.  So, i'm at a total loss for what is going on.

Reply
0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

You might want to create a side thread so you can talk to LucD​ as he can probably give you better advice than I.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you share the code/script?
And how you call it?

And you might want to display $? after each line instead of $lastexitcode.
The latter is used for the return code of native commands, not the PS status.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
hawks76
Enthusiast
Enthusiast
Jump to solution

I've attached the code.  I did put the $? in my last iteration, and it always said successful.  I also put the output in the software component console.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You do seem to be getting a 3010 on the .exe file.
That normally means that a reboot is required.

Can you also check what the $return variable contains after the Start-Process cmdlet for the silent install?
You could do

$return | Format-Custom -Depth 2

Also, the Start-Process perhaps doesn't show you what would be going to stdout and stderr from the EXE.
Can you try adding the -RedirectStandardError  and -RedirectStandardOutput parameters to redirect both streams to a file.

That might give some more information.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
hawks76
Enthusiast
Enthusiast
Jump to solution

I'll try this out and post results.

Thanks!!

Reply
0 Kudos
hawks76
Enthusiast
Enthusiast
Jump to solution

Ok. So, here is the result from the last run with the suggestions:

Last Exit Code: 0

Did Last Command Complete Successfully: True

Generating Random SQL Port Number.....

Last Exit Code: 0

Did Last Command Complete Successfully: True

Last Exit Code: 0

Did Last Command Complete Successfully: True

Last Exit Code: 0

Did Last Command Complete Successfully: True

Last Exit Code: 0

Did Last Command Complete Successfully: True

Randomly generated port number: 34649

Setting Randon SQL Port.....

Import-Module Error Var:

Last Exit Code: 0

Did Last Command Complete Successfully: True

Last Exit Code: 0

Did Last Command Complete Successfully: True

Last Exit Code: 0

Did Last Command Complete Successfully: True

Last Exit Code: 0

Did Last Command Complete Successfully: True

Last Exit Code: 0

Did Last Command Complete Successfully: True

Current TCP Listening Port: 1433

Last Exit Code: 0

Did Last Command Complete Successfully: True

Finalizing New TCP Port.....

Last Exit Code: 0

Did Last Command Complete Successfully: True

Last Exit Code: 0

Did Last Command Complete Successfully: True

New TCP Listening Port: 34649

Restarting Services MSSQLFDLauncher, MSSQLSERVER, SQLBrowser, SQLSERVERAGENT, and SQLWriter.....

Last Exit Code: 0

Did Last Command Complete Successfully: True

Installing SQL 2017 CU13.....

Last Exit Code: 0

Did Last Command Complete Successfully: True

SQL 2017 CU13 Install Exit Code: 3010

class Process

{

  Id = 4044

  Handles =

  CPU = 5.921875

  SI =

  Name =

}

Cleaning up installation files.....

Last Exit Code: 0

Did Last Command Complete Successfully: True

SQL Installation Completed.

Last Exit Code: 0

Did Last Command Complete Successfully: True

Last Exit Code: 0

ABORT. Encountered error in Powershell.

Error while executing script: Process exited with an error: 1 (Exit value: 1)

Having to tinker with the code to get the redirected output, so i'll have that in a little while.

Also, don't know if you saw it, but this same code works with SQL 2016 installs with the same template.  I'm thinking that the code to change the port may be the culprit.  I can comment that code out, and all works fine with no error.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

On a side note, why are you using the WMI method, while you could be using the Set-SqlNetworkConfiguration cmdlet?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
hawks76
Enthusiast
Enthusiast
Jump to solution

To be honest, i was unaware of that ps cmdlet.  I just used what the SQL guys sent me.  I'll see about replacing my code with this and see if that fixes my issue.

Reply
0 Kudos
hawks76
Enthusiast
Enthusiast
Jump to solution

Looks like that cmdlet is Azure specific.

Reply
0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

No, that cmdlet isn't Azure specific, you do need the module though. It works for on-prem SQL as well.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Not sure where you found this cmdlet to be specific for Azure?
In Install SQL Server PowerShell module that doesn't seem to be mentioned.

They only mention that the module is applicable to SQL Server, Azure SQL Database...


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
hawks76
Enthusiast
Enthusiast
Jump to solution

Ok, so i see now where it's part of the feature pack, but it doesn't appear to be part of the 2017 or 2016 feature pack (it is in the 2014 feature pack). I'll poke around with it on the side while i continue down this path trying to figure out this problem.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I think it mentions that you have to get it from the PowerShell Gallery since 2016.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
hawks76
Enthusiast
Enthusiast
Jump to solution

Correct, the module does have to be pulled from PSGallery.  I was refering to the SQL Server Cloud Adapter that is required.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Afaik that is not a requirement for the module.
But you're the SQL specialist :smileygrin:


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos