mattmcspirit / azurestack

Azure Stack Resources
80 stars 41 forks source link

Can't retry appservice deployment due to an existing database #59

Closed gijs007 closed 5 years ago

gijs007 commented 5 years ago

My previous run of the post deployment script failed, during the step DeployAppService (probably during the deployment of an Appservice virtual machine, see ticket #60 ). If I rerun the post deployment script it fails, due to a database (appservice_hosting) which already exists.

The AppServiceLog for this run shows:

[7BE0:2078][2018-11-16T07:52:55]: [Websites]: System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: The database 'appservice_hosting' already exists. Please choose another SQL instance or remove the existing database and retry.

   at Microsoft.Web.Hosting.Common.DatabaseServerHelper.TestConnectivity(String serverName, String userName, String password, String dbObjsPrefix)

Perhaps it's possible to adjust the script so that:

  1. it checks if the database exists and validates it.
  2. Reuse the existing database if it's valid and continue from there.

Alternatively it might be an idea to remove the existing database, as cleanup step for this task within the script. (This would be necessary if the database ends up being corrupted anyhow)

mattmcspirit commented 5 years ago

The creation of the DB and associated logins is automatically handled by the AppService.exe automated installer (which my script simply calls) and its this that cant handle the existing DB unfortunately. I can write a check to see if the DB exists, along with its logins, then clean it up if it does exist (as it will likely be a rerun).

As far as I know, there’s no way to reuse the existing DB at install time unless it’s handled by the AppService.exe itself.

Probably easier just to clean up.

Leave it with me.

gijs007 commented 5 years ago

Makes sense. A clean up will work nicely too :)

mattmcspirit commented 5 years ago

OK, cleanup should work. Replace your DeployAppService.ps1 version, with this one: https://raw.githubusercontent.com/mattmcspirit/azurestack/1809.2/deployment/powershell/DeployAppService.ps1

My only worry with this cleanup, is if the AppService process proceeds quite far, and then fails - it may be that the database doesn't need to be cleaned, for example, if the AppService install gets 90% of the way through. I need to understand at which point in the AppService.exe install, the DB is created/validated and perhaps figure out a workaround.

Right now, with this new version, if the AppService fails at 10% progress, or 90% progress, if the DB exists, it will be completely cleaned up.

I've not seen an AppService fail mid-way - typically it either fails at the start, or doesn't, but we'll continue to review the logs and see if there is anything else I can do, or need to clean up for a re-run.

Let me know if it works.

gijs007 commented 5 years ago

So far it's working nicely, Appservice deployment is running for 17 minutes now. Instead of the almost instant failure after the rerun. Goodwork 👍

If the AppService database is removed at 90%, I assume Appservice will simply reinstall from scratch? It will take a little longer, but as long as it doesn't fail that's nothing to worry about IMO. Although obviously it would be nicer if everything is completed in the fastest possible way.

Maybe it's an idea to utilize PowerShell Desired State Configuration? (For the more complex steps which take a while) If setup correctly DSC can start over from where it failed, instead of redoing everything.

gijs007 commented 5 years ago

After running the updated script the deployment still failed. I've send you the log by email. At least it doesn't fail because of the database. :)

mattmcspirit commented 5 years ago

This is strange. Anyway, I spoke to a friend in the App Service team, and he confirmed that if you experience a failure mid-way through the App Service deployment, it's best to delete the RG, clean the DB and re-rerun, so, the changes I've now made in the latest version of the DeployAppService.ps1 should fix things. You can get it here:

https://raw.githubusercontent.com/mattmcspirit/azurestack/1809.2/deployment/powershell/DeployAppService.ps1

I'd try this one, and make sure it removes the old RG - I didn't have a failed one to test against, so it would be good if you can confirm it :) - it should happen quite early in the process, and you could monitor the deletion from the portal.

Let me know!

Thanks, Matt

mattmcspirit commented 5 years ago

Let's close this one out, as we know that the script now handles cleaning up the DB, so let's focus on the other issue with re-running a failed App Service deployment.