Umbraco 9 on Linux Server (Kestrel Service)- Site Dies After Deploying Code Changes - linux

I've gotten an Umbraco 9.0.1 instance up and running on a Linux server (Ubuntu 20.04). I'm using what appears to be the recommended approach of using Nginx as a reverse proxy to a Kestrel service
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-5.0
The issue I'm having is that any time I do a code update and deploy it to my Linux server, followed by a restart of the kestrel service, the site dies. I get a 502 bad gateway error. Reloading the daemon does nothing. The only thing I've found that seems to work is if I navigate to place in the filesystem where I've deployed the published application and run the command:
dotnet Umbraco.Nine.Linux.dll (Umbraco.Nine.Linux being the name of my project and the corresponding dll the result of the publish)
that command just hangs so I hit ctrl + C to stop it, but that brings the site back up.
Has anyone else experienced anything like this? If not, how are you handling Umbraco code deployments to a Linux server? I should add that if I use the default .net core website from Visual Studio, I don't have this issue. I deploy my code and restart the kestrel service and everything is beautiful, no site outage, changes show up. So maybe there is some Umbraco startup process that's making things die?
I've checked the logs for the kestrel service and they just indicate the service stops/restarts as expected. The logs in Nginx confuse me. They say something like
2021/09/27 15:35:08 [error] 81048#81048: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 184.67.248.194, server: <mysite.com>, request: "GET /umbraco/api/test/another HTTP/1.1", upstream: "http://127.0.0.1:2003/umbraco/api/test/another", ..."
EDIT:
I thought I should post some additional details, just in case it helps. For the publishing of the project, I am using Visual Studio built in publishing and choosing File System.
(Note I've tried the single file publish but I haven't even gotten that to run. I get an error indicating some library the project depends upon will not run in single file publish. Again, this seems Umbraco specific as I can get a default asp.net core site to publish just fine like this. I'm only adding this note in case it's relevant to something just being wrong with Umbraco 9 as we're still very early in the release.)
After that I just zip it up, upload it to the server, unzip it with commands like:
unzip -o website.zip -d <path/to/my/web/app/>
Then
sudo systemctl restart <my.kestrel.service>
That's when browsing the site yields the 502 Bad Gateway I described above. Any help on what I'm doing wrong would be greatly appreciated.

So, I solved this, sort of. I've abandoned the whole kestrel thing and I'm using a docker container to run the asp.net core application. I'm still hosting using nginx as a reverse proxy. The only difference is instead of having a systemd kestrel service listening on the specified port, it's a docker container doing it.
I posted details here: https://our.umbraco.com/forum/umbraco-9/107189-umbraco-nine-on-linux-server-site-dies-after-deploying-code-changes
Hopefully it helps someone else out!
I'm pretty excited because the whole thing is 'script'-able so I managed to automate it in an AWS CodePipeline.

Related

dotnet core IIS website restart on error (for example sql server reboot)

I'm currently facing the following problem when hosting a dotnet core application with IIS.
When the webserver boots before the database server, the dotnet-application throws an error that it is unable to connect to the database. So for so good offcourse.
But the problem is that when it faces this error on startup, it will never again try to connect to the database. The dotnet core application seems to be giving up when facing a startup error.
Is there some general re-try mechanism available to handle these kind of errors? So for example when the application detects a problem, to restart every 5 minutes?
I seem to have found the answer myself. It was during my startup-logic that I already was connecting to the sql database. I could simply force IIS to try to restart the process, until initialization worked out by explicitly shutting down the application using Environment.Exit(-1); whenever an error occured

How to run ASP.NET Core site under IIS

I've studied the docs on how to do this but am still not understanding:
I've published my site from Visual Studio and can run the site from the command prompt using the command:
dotnet MyDotnetCoreApp.dll
That tells me the app started on http://localhost:5000 and I can browse to it just fine.
But how do I get IIS to start the app though so that I can go to the normal port 80? The web.config has the correct entry:
<aspNetCore processPath="dotnet" arguments=".\MyDotnetCoreApp.dll" .... />
All I get is 500 An error occurred while starting the application.
Must be missing some simple step. Thanks in advance.
Actually in your case you are not running using IIS, but using Kestrel HTTP Server.
You can read about Kestrel hosting configuration (and find how to change listening port) in this SO answer.
In case if you need to run under IIS (that is still publish option #1 on Windows, despite IIS is acting now merely as a reverse proxy and the application itself runs as a separate process using the Kestrel HTTP server), you may find Running ASP.Net Core applications with IIS article very useful, as it explains not just how to make ASP.NET Core works with IIS, but also "what’s really happening, why it’s happening and how the blocks fit together"

Web deployment task failed. Destination not reachable

I've been successfully using Azure for months. Today I'm getting the following error when I publish from via Web Deploy from Visual Studio 2013
Error 5 Web deployment task failed. (Could not connect to the remote computer ("waws-prod-hk1-001.publish.azurewebsites.windows.net"). On the remote computer, make sure that Web Deploy is installed and that the required process ("Web Management Service") is started. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_DESTINATION_NOT_REACHABLE.)
I tried downloaded a new Publishing Profile from the Azure Dashboard and turning off my firewall - no change.
I can't ping the listed server.
It seems to be the same issue as http://social.msdn.microsoft.com/Forums/windowsazure/en-US/83d4e635-2851-4526-b21b-31101d00aa86/web-deployment-task-failed-errorcouldnotconnecttoremotesvc?forum=windowsazurewebsitespreview
Any ideas? Thank you.
I had the exact same problem for a couple of days (sometimes I could published and sometimes not).
The problem was my internet configuration (not related to Microsoft or Azure in anyway).
To solve this issue I disconnected my modem (its actually modem+router) for 10 min and reconnect it and it was fixed!
Hope it will help someone someday...
Nevermind. It would appear that Azure was in a 'challenged' state.
It's working fine now..
What worked for me was disabling and re-enabling my network adapter.
The reasoning is, quite possibly naive, that having Fiddler running during a deployment will fail but it also changes the network state and that state continues
to exist even after exiting Fiddler (which disables the proxy).

msdeploy mvc to Windows7 getting ERROR_DESTINATION_NOT_REACHABLE and 404

I'm trying to do msdeploy of a MVC app to a windows7 box, running on command-line. And kept getting this error:
Error Code: ERROR_DESTINATION_NOT_REACHABLE
More Information: Could not connect to the destination computer ("192.168.xxx.xxx"
). On the destination computer, make sure that Web Deploy is installed and that
the required process ("The Web Management Service") is started.
Error: The remote server returned an error: (404) Not Found.
Error count: 1.
I've verified both Wmsvc (seems this is being used) and MsDepSvc are running. And firewall are disabled. In the browser when I visit https://192.168.xxx.xxx:8172/msdeploy.axd, I got a Server Error 404, seems a bit further than where the command-line stopped.
Most of instructions on setting up IIS7 and Web deployment I could find online is for MS Servers. Both my local machine and the Windows7 machine has the same version of Msdeploy installed.
I had exactly the same issue with a VM on Azure, and the solution was to enable first the IIS Management Service and then install Web Deploy (I used Web Platform Installer). Seems that the installation order matters. You can find a blog entry I wrote about this here http://davidjrh.intelequia.com/2012/10/configurando-web-platform-installer-y.html
For non-server operating systems (i.e. Windows 7) the Web Deploy publish via Web Management Service is not supported. Instead you will have to use the Remote Agent Service, this is an admin only publishing service. You can find more info at http://technet.microsoft.com/en-us/library/dd569059(v=WS.10).aspx.
I had the same issue using MSDeploy to deploy my web application to remote IIS 7.5 web server running windows 7. I have just figured out how to fix the problem today after reading Sayed's post, so I wanna post my solution here for anyone who would run into this problem like me. Try this:
Enable IIS Management Service (in control panel >> add or remove features >> add or remove windows features)
Install Web Deploy (http://www.iis.net/downloads/microsoft/web-deploy)
Open cmd with Administrative privilege, type “net start msdepsvc” to start the “Web Deploy Agent Service”.
Check this link in your browser: http://serveraddress/MsDeployAgentService/, if it prompts for username and password, MsDeployAgentService is running on server, go to the next step.
In VS, type in http://serveraddress/MsDeployAgentService/ in Service URL while creating publish, instead of https://serveraddress:8172/MsDeploy.axd, and click test connection. It should be ok now.
After checking the Management Service and Web Deploy 3.0 were correctly installed, I found that (from VS2012 at least) the Service URL seems to matter here too, attempting to publish to any of the following did not work for me:
FQDN (localmachine.domain.local)
Domain IP Address (172.22.xxx.xxx)
Loop-back IP (127.0.0.1)
Whereas the following DID work:
localhost
NetBIOS name (localmachine)

Unable to start debugging on the web server. The underlying connection was closed. The connection was closed unexpectedly

All of the sudden I'm getting the following error on my local web server (Win7 64bit, IIS 7.5). I've uninstalled & reinstalled IIS locally and it didn't fix it. IIS is set to start up automatically and I can see that the service has been successfully started. Upon a fresh reboot if I go into IIS and click on start website I get the following error:
The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020
If I try to start debugging on my local website project I get the following error:
Unable to start debugging on the web server. The underlying connection was closed. The connection was closed unexpectedly.
Any ideas on what I can try? I've been doing research on the issue and Microsoft suggest making sure no other service is listening on the same ports. I've verified that this isn't the issue.
Try changing the web site to use a port other than 80 (suggest 8080 for example) and see it if will start. If so that's a sure sign of another service using port 80 (Skype is a common culprit for this).
Application pool's identity password changed?
I know this is an old post, but I can't believe how many times I've been bitten by this. Some shops use integrated security for SQL, and often then on your local IIS needs your network login for the application pool. When your password expires, and you forget to change your password here, start banging your head on the wall... DOH!
Open IIS. Select Application Pools. Select the application pool used by your app. Click Advanced Settings... Select Identity, and the little "..." button to update your user/password.

Resources