【发布时间】:2017-08-30 18:17:26
【问题描述】:
我有一个针对 dotnet 1.1.0 的 ASP.NET Core Angular 应用程序。
我在我的 Linux Ubuntu 16.04 上安装了 Nginx,并配置了 nginx 配置文件如下:
server {
listen 80;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
和myapp.services文件如下:
[Unit]
Description=Sample application.
[Service]
Type=simple
WorkingDirectory=/var/myappfolder
ExecStart=/usr/bin/dotnet /var/myappfolder/myapp.dll
#User=web
[Install]
WantedBy=multi-user.target
我用一个简单的示例应用程序测试了这个设置,它运行良好。但是,一旦我将适当的应用程序部署到 /var/myappfolder 并配置
systemclt start mywebsite
systemclt daemon_reload
然后检查
systemclt status mywebsite
我收到此错误:
jtrade.service - 示例应用程序。加载:加载 (/lib/systemd/system/jtrade.service;已禁用;供应商预设:已启用) 活动:自 2017 年 8 月 30 日星期三 18:08:08 UTC 以来失败(结果:信号); 9s 前进程:4640 ExecStart=/usr/bin/dotnet /var/jtrade/jtradep.dll (code=killed, signal=ABRT) 主 PID: 4640 (code=killed, signal=ABRT)
8 月 30 日 18:08:08 localhost dotnet[4640]:在 Microsoft.DotNet.Configurer.NuGetCacheSentinel.get_NuGetCachePath()
8 月 30 日 18:08:08 localhost dotnet[4640]:在 Microsoft.DotNet.Configurer.NuGetCacheSentinel.Exists()
8 月 30 日 18:08:08 localhost dotnet[4640]:在 Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.ShouldPrimeNugetCache()
8 月 30 日 18:08:08 localhost dotnet[4640]:在 Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
8 月 30 日 18:08:08 localhost dotnet[4640]:在 Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel)
8 月 30 日 18:08:08 localhost dotnet[4640]:在 Microsoft.DotNet.Cli.Program.ProcessArgs(字符串 [] 参数,ITelemetry 遥测客户端)
8 月 30 日 18:08:08 localhost dotnet[4640]:在 Microsoft.DotNet.Cli.Program.Main(String[] args)
8 月 30 日 18:08:08 localhost systemd[1]: jtrade.service: 主进程 已退出,code=killed,status=6/ABRT
8 月 30 日 18:08:08 localhost systemd[1]: jtrade.service: 输入单位 失败状态。
8 月 30 日 18:08:08 localhost systemd[1]: jtrade.service: 失败 结果“信号”。
所以我用journalctl -u myappname 深入调试了这个错误并获得了一些更有用的信息:
已启动示例应用程序..
8 月 31 日 05:13:34 localhost dotnet[10290]:未处理的异常: System.InvalidOperationException:必需的环境变量“HOME” 未设置。尝试设置“HOME”并再次运行该操作。
8 月 31 日 05:13:34 localhost dotnet[10290]:在 NuGet.Common.NuGetEnvironment.GetValueOrThrowMissingEnvVar(Func`1 getValue,字符串名称)
8 月 31 日 05:13:34 localhost dotnet[10290]:在 NuGet.Common.NuGetEnvironment.GetHome() 8 月 31 日 05:13:34 本地主机 点网[10290]:在 NuGet.Common.NuGetEnvironment.c.<.cctor>b__12_0()
8 月 31 日 05:13:34 localhost dotnet[10290]:在 System.Lazy`1.CreateValue()
8 月 31 日 05:13:34 localhost dotnet[10290]: --- 堆栈跟踪结束 之前抛出异常的位置---
8 月 31 日 05:13:34 localhost dotnet[10290]:在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
8 月 31 日 05:13:34 localhost dotnet[10290]:在 System.Lazy`1.get_Value()
8 月 31 日 05:13:34 localhost dotnet[10290]:在 NuGet.Common.NuGetEnvironment.GetFolderPath(SpecialFolder 文件夹)
8 月 31 日 05:13:34 localhost dotnet[10290]:在 NuGet.Common.NuGetEnvironment.GetFolderPath(NuGetFolderPath 文件夹)
8 月 31 日 05:13:34 localhost dotnet[10290]:在 NuGet.Configuration.SettingsUtility.GetGlobalPackagesFolder(ISettings 设置)
8 月 31 日 05:13:34 localhost dotnet[10290]:在 NuGet.Configuration.NuGetPathContext.Create(ISettings 设置)
8 月 31 日 05:13:34 localhost dotnet[10290]:在 Microsoft.DotNet.Configurer.NuGetCacheSentinel.get_NuGetCachePath()
8 月 31 日 05:13:34 localhost dotnet[10290]:在 Microsoft.DotNet.Configurer.NuGetCacheSentinel.Exists()
8 月 31 日 05:13:34 localhost dotnet[10290]:在 Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.ShouldPrimeNugetCache()
8 月 31 日 05:13:34 localhost dotnet[10290]:在 Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
8 月 31 日 05:13:34 localhost dotnet[10290]:在 Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel)
8 月 31 日 05:13:34 localhost dotnet[10290]:在 Microsoft.DotNet.Cli.Program.ProcessArgs(字符串 [] 参数,ITelemetry 遥测客户端)
8 月 31 日 05:13:34 localhost dotnet[10290]:在 Microsoft.DotNet.Cli.Program.Main(String[] args)
8 月 31 日 05:13:34 localhost systemd[1]: jtrade.service: 主进程 已退出,code=killed,status=6/ABRT
8 月 31 日 05:13:34 localhost systemd[1]: jtrade.service: 输入单位 失败状态。
8 月 31 日 05:13:34 localhost systemd[1]: jtrade.service: 失败 结果“信号”。
如果我从这里用 printenv 运行查看我的环境变量,我会发现 HOME= /root
也许它应该设置为其他东西?
【问题讨论】:
-
请注意,在我在本地机器上使用 dotnet publish 发布应用程序后,我检查了 myapp.dll 并使用 dotnet myapp.dll 运行它,它运行良好。
-
另外,在服务器上,如果我简单地使用 dotnet myapp.dll 运行应用程序,它也可以正常运行。所以我猜这与 systemd 配置有关......
标签: linux ubuntu nginx .net-core