【发布时间】:2017-11-02 18:35:07
【问题描述】:
我尝试在 CentOS 上部署 asp.net web.api 应用程序。当我使用 dotnet /var/www/html/CoreApiTest.dll 手动运行它时,它工作正常(使用 apache 作为代理)。当我使用服务运行它时,我得到一个错误。这是服务代码:
[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
我使用systemctl enable kestrel-CoreApiTest.service 安装它。然后启动它并检查状态:systemctl status kestrel-CoreApiTest.service 并得到这个错误:
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.
在日志中 (journalctl -u kestrel-CoreApiTest) 我看到了这个:
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)
我做错了什么?
【问题讨论】:
-
正如错误所说,您没有授予进程访问文件夹中文件的权限。 apache 用户需要访问权限。
-
@Sami Kuhmonen 据我了解,apache 用户可以完全访问此文件夹:stat 2.0.0.dotnetFirstUseSentinel 文件:'2.0.0.dotnetFirstUseSentinel' 大小:6 块:0 IO 块:4096 目录设备: fd02h/64770d Inode: 51363393 链接: 2 访问: (0777/drwxrwxrwx) Uid: (48/ apache) Gid: (48/ apache)
-
@AlexeyRumin 检查进程实际运行的用户。我不熟悉 CentOS 或根据您的配置描述服务,但我会说这就是问题所在。另外,尝试使用
sudo su apache,然后查看是否可以以 apache 用户身份运行该应用。
标签: c# asp.net .net asp.net-core