Alexey Rumin
Alexey Rumin

Reputation: 303

asp.net core web.api application can't be started

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?

Upvotes: 7

Views: 7798

Answers (1)

Dark Daskin
Dark Daskin

Reputation: 1484

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

Upvotes: 2

Related Questions