0

I have a .Net Core 3 app that I want to run as a system service:

[Unit]
Description=app-prod

[Service]
WorkingDirectory=/var/www/app-prod
ExecStart=/usr/bin/dotnet /var/www/app-prod/app
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-app-prod
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

As you can see in the service configuration I used User=www-data, and the permission of the app path is already owned by that user. But when I start the service, it does checks for folders and tries to make them but it goes into exception:

mar 07 14:15:14 void dotnet-app-prod[8004]: System.UnauthorizedAccessException: Access to the path '/var/www/.
mar 07 14:15:14 void dotnet-app-prod[8004]:  ---> System.IO.IOException: Permission denied
mar 07 14:15:14 void dotnet-app-prod[8004]:    --- End of inner exception stack trace ---
mar 07 14:15:14 void dotnet-app-prod[8004]:    at System.IO.FileSystem.CreateDirectory(String fullPath)

And as you can see the user used to run the service is void which is just a normal user to log in the environment.

What I could be doing wrong to get the wrong user running the service instead of the needed www-data?

3
  • Is the first line of the log cut off? If not, is it really trying to create /var/www? If so, that's probably the problem: www-data cannot create subdirectories in /var. Create it (as root) by hand and chown it to www-data, then restart the service.
    – NickD
    Commented Mar 7, 2020 at 19:01
  • @NickD A little, this is just after the normal log info of the service starting up, but failing almost immediately, and it's trying to create a directory in /var/www/app/wwwroot/images/, does linux limit you in making folders because some parent folder is not owner by the user used for the app for making folders inside it's own folder?
    – Eugene
    Commented Mar 7, 2020 at 19:44
  • I'm gonna try anyway as you said.
    – Eugene
    Commented Mar 7, 2020 at 19:45

0

You must log in to answer this question.

Browse other questions tagged .