我有一个奇怪的问题。
像这样运行我的web-api:
$ /usr/local/bin/dotnet /usr/local/bin/dotnetcoreapps/api/TestService.dll
我已经在/etc/systemd/system/
中创建了此test-service.service:
[Unit]
Description=DoorplateBackendService
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=pi
ExecStart=/usr/local/bin/dotnet /usr/local/bin/dotnetcoreapps/api/TestService.dll
KillSignal=SIGINT
[Install]
WantedBy=network-online.target
不知何故,我不知道它来自哪里:
System.IO.IOException: Invalid argument
at System.IO.Enumeration.FileSystemEnumerator`1.FindNextEntry()
at System.IO.Enumeration.FileSystemEnumerator`1.MoveNext()
at System.IO.FileSystemWatcher.RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory parent, String directoryName)
at System.IO.FileSystemWatcher.RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory parent, String directoryName)
at System.IO.FileSystemWatcher.RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory parent, String directoryName)
at System.IO.FileSystemWatcher.RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory parent, String directoryName)
at System.IO.FileSystemWatcher.RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory parent, String directoryName)
at System.IO.FileSystemWatcher.RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory parent, String directoryName)
at System.IO.FileSystemWatcher.RunningInstance..ctor(FileSystemWatcher watcher, SafeFileHandle inotifyHandle, String directoryPath, Boolean includeSubdirectories, NotifyFilters notifyFilters, CancellationToken cancellationToken)
at System.IO.FileSystemWatcher.StartRaisingEvents()
at System.IO.FileSystemWatcher.StartRaisingEventsIfNotDisposed()
at System.IO.FileSystemWatcher.set_EnableRaisingEvents(Boolean value)
at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.TryEnableFileSystemWatcher()
at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.CreateFileChangeToken(String filter)
at Microsoft.Extensions.FileProviders.PhysicalFileProvider.Watch(String filter)
at Microsoft.Extensions.Configuration.FileConfigurationProvider.<.ctor>b__0_0()
at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer)
at Microsoft.Extensions.Configuration.FileConfigurationProvider..ctor(FileConfigurationSource source)
at Microsoft.Extensions.Configuration.Json.JsonConfigurationSource.Build(IConfigurationBuilder builder)
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at BrodicatorService.Program.Main(String[] args) in <my_dir>\Program.cs:line 23;
Program.cs-第23行:CreateWebHostBuilder(args).Build().Run();
答案 0 :(得分:0)
经过数小时的调试和尝试其他操作之后,我最终更改了服务定义:
[Unit]
Description=MyTestService
[Service]
WorkingDirectory=/usr/local/bin/dotnetcoreapps/api
ExecStart=/usr/local/bin/dotnet /usr/local/bin/dotnetcoreapps/api/TestService.dll
Restart=always
RestartSec=10
KillSignal=SIGINT
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target
我发现this link很有帮助。
我不知道这里发生了什么。
答案 1 :(得分:0)
我的.NET 5项目遇到相同的问题,并尝试使用“ .service”文件进行实验。
对我来说,解决方案是将工作目录更改为“ / tmp”。我认为它可以正常工作,因为我的应用程序位于已安装的网络磁盘(NFS)上。
MS Demo服务器端项目正常运行,而工作目录未设置为“ / tmp”。
顺便说一句,我没有发表评论的要点,所以我发布了答案。