Reputation: 3001
I am trying to host an ASP.Net Core MVC application on Ubuntu Server 16.04 LTS by following the directions in this tutorial.
From the Linux machine, I use git pull
to pull in my project. I build it successfully with dotnet build
, which triggers a package restore. I publish it successfully with dotnet publish -c Release -r linux-x64
. I change directories to bin/Release/netcoreapp2.1
and run sudo cp ./*.* /var/aspnetcore/myapp/
to copy the files into the directory where I am hosting the project. I navigate to that directory and type dotnet myapp.dll
- the app begins listening on ports 5000 and 5001, and from a different computer, I can type my domain name into a browser and see the web site, which means the Nginx reverse proxy and Kestrel must be working fine.
Now I want to run the application as a service so that it starts with the computer, restarts on crash, logs errors, etc, but when I type sudo systemctl start kestrel-myapp.service
it crashes immediately and attempts to restart every 10 seconds but fails. The log shows the error: An assembly in the application dependencies manifest (myapp.deps.json) was not found: package: 'Microsoft.EntityFrameworkCore.Relational.Design', version '1.1.5' path: 'lib/netstandard1.3/Microsoft.EntityFrameworkCore.Relational.Design.dll' Main process exited, code=exited, status=140/n/a
So, the version 1.1.5 looks suspiciously low, but I updated all of my NuGet packages and it still wants to use it. Plus, I don't understand why it doesn't crash with dotnet myapp.dll
if there is a problem with the dependencies. Does anybody know how to fix the issue?
Here is my service file:
[Unit]
Description=myapp ASP.Net Core MVC Application
[Service]
WorkingDirectory=/var/aspnetcore/myapp
ExecStart=/usr/bin/dotnet /var/aspnetcore/myapp/myapp.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
SyslogIdentifier=myapp
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
Bonus question: where do I copy my wwwroot folder with my static files to? The application runs but can't find any of my javascript or css files, and I'm not sure where they belong.
Upvotes: 2
Views: 3216
Reputation: 8446
Make sure the WorkingDirectory is set to the directory where the runtime dll file is located.
Upvotes: 0
Reputation: 15233
When you dotnet publish -c Release -r linux-x64
it creates several directories. You want to use the bin/Release/netcoreapp2.1/linux-x64/publish
directory. Other directories contain builds too, but those builds assume they will be run on development systems. Only the publish
directory contains bits that should be deployed. The other directories contain bits that assume they are running in a development environment.
It works when you run dotnet myapp.dll
because you are still running as your regular user and it sees your local development assets, including the nuget cache.
When you run via systemctl
, it runs as root
which does not have any local nuget cache and can't use the development (non-publish
ed) version of your code.
Upvotes: 3