7

I try to deploy asp.net web.api application on CentOS. When I run it manually using dotnet /var/www/html/CoreApiTest.dll it works fine (with apache as the proxy). When I use service to run it I get an error. Here is the service code:

[Unit]
Description=Example .NET Web API Application running on CentOS 7

[Service]
WorkingDirectory=/var/www/html/CoreApiTest
ExecStart=/usr/bin/dotnet /var/www/html/CoreApiTest.dll
Restart=always
# Restart service after 10 seconds if dotnet service crashes
RestartSec=10
SyslogIdentifier=dotnet-example
User=apache
Environment=ASPNETCORE_ENVIRONMENT=Production

[Install]
WantedBy=multi-user.target

I install it using systemctl enable kestrel-CoreApiTest.service. Then start it and check status: systemctl status kestrel-CoreApiTest.service and get this error:

kestrel-CoreApiTest.service - Example .NET Web API Application running on CentOS 7
   Loaded: loaded (/etc/systemd/system/kestrel-CoreApiTest.service; enabled; vendor preset: disabled)
   Active: activating (auto-restart) (Result: exit-code) since Thu 2017-11-02 21:27:35 MSK; 5s ago
  Process: 2093 ExecStart=/usr/bin/dotnet /var/www/html/CoreApiTest.dll (code=exited, status=1/FAILURE)
 Main PID: 2093 (code=exited, status=1/FAILURE)

Nov 02 21:27:35 aryumin.fvds.ru systemd[1]: kestrel-CoreApiTest.service: main process exited, code=exited, status=1/FAILURE
Nov 02 21:27:35 aryumin.fvds.ru systemd[1]: Unit kestrel-CoreApiTest.service entered failed state.
Nov 02 21:27:35 aryumin.fvds.ru systemd[1]: kestrel-CoreApiTest.service failed.

In logs (journalctl -u kestrel-CoreApiTest) I see this:

ov 02 20:59:47 aryumin.fvds.ru systemd[1]: Started Example .NET Web API Application running on CentOS 7.
Nov 02 20:59:47 aryumin.fvds.ru systemd[1]: Starting Example .NET Web API Application running on CentOS 7...
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: Welcome to .NET Core!
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: ---------------------
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available command
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: Telemetry
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: --------------
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: The .NET Core tools collect usage data in order to improve your experience. The data is anonymous a
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 usi
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: System.UnauthorizedAccessException: Access to the path '/usr/share/httpd/.dotnet/2.0.0.dotnetFirstU
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: --- End of inner exception stack trace ---
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 e
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at System.IO.File.Create(String path)
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.Extensions.EnvironmentAbstractions.FileWrapper.CreateEmptyFile(String path)
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.DotNet.Configurer.FirstTimeUseNoticeSentinel.CreateIfNotExists()
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.PrintFirstTimeUseNotice()
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentin
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.DotNet.Cli.Program.Main(String[] args)

What am I doing wrong?

3
  • 2
    As the error says you haven’t given permissions for the process to access the files in the folder. The apache user needs access. Commented Nov 2, 2017 at 18:49
  • @Sami Kuhmonen As I understand apache user has full access to this folder: stat 2.0.0.dotnetFirstUseSentinel File: ‘2.0.0.dotnetFirstUseSentinel’ Size: 6 Blocks: 0 IO Block: 4096 directory Device: fd02h/64770d Inode: 51363393 Links: 2 Access: (0777/drwxrwxrwx) Uid: ( 48/ apache) Gid: ( 48/ apache) Commented Nov 2, 2017 at 19:00
  • @AlexeyRumin check which user the process actually runs at. I'm not familiar with CentOS or describing services as per your config, but i would say that is the issue. Also, try doing sudo su apache and then seeing if you can run the app as apache user. Commented Nov 3, 2017 at 5:07

1 Answer 1

2

dotnet CLI is trying to write a file to the user profile to record the fact that it has displayed the first-run message. This fails because the service user does not have writable profile directory.

You can add the following to your [Service] section to prevent dotnet from displaying this message and creating this file:

Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.