Do not start dotnet with root user
If it is launched from init.d, it is called using the root user . Running the program with root will lead to serious security problems for your computer, especially with the .net kernel, which is still in a difficult development, and yet security is not .
Starting a service with a specific user
Your error is probably due to the fact that no no packages are specified for the root directory, but when started manually, this is with your user , which has the directory /home/user/.nuget/packages .
- From the asp.net core documentation, you can configure the service and specify the user who will start dotnet
- Just use the
su command to start dotnet with the specified user
Supervisor Users
Here is an excerpt from the supervisor for my own site
/etc/supervisor/conf.d/mysite.conf
[program:mysite] command=/usr/bin/dotnet /var/www/mysite/MySite.dll directory=/var/www/mysite autostart=true autorestart=true stderr_logfile=/var/log/mysite.err.log stdout_logfile=/var/log/mysite.out.log environment=ASPNETCORE_ENVIRONMENT=Production user=www-data <=== SPECIFY A USER HERE stopsignal=INT
Do not use dotnet run outside of development / debugging purpose
As dotnet --help says, the start command compiles and runs the project.
run Compiles and immediately executes a .NET project
Compiling wil requires additional steps, and then processing power, and therefore additional time (every time it starts, there are no code changes). It also requires recovery and build to work (which requires a normal developer user). It is also more prone to failures due to extra steps that may fail.
Instead, compile once with your developer user, and then run your program using a service user such as www-data (which is a kind of built-in user for websites).
dotnet MyCompiledAssembly.dll
source share