우분투 14에서 .net 코어를 systemd 서비스로 실행

우분투 14에서 .net 코어를 systemd 서비스로 실행

이건 잘 작동해요

webadmin@sandbox:/www/web/prod/prereg.example.org/prereg-sample$ dotnet restore
  Restoring packages for /www/web/prod/prereg.example.org/prereg-sample/WebApplication/WebApplication.csproj...
  Restoring packages for /www/web/prod/prereg.example.org/prereg-sample/WebApplication/WebApplication.csproj...
  Restore completed in 558.64 ms for /www/web/prod/prereg.example.org/prereg-sample/WebApplication/WebApplication.csproj.
  Lock file has not changed. Skipping lock file write. Path: /www/web/prod/prereg.example.org/prereg-sample/WebApplication/obj/project.assets.json
  Restore completed in 2.12 sec for /www/web/prod/prereg.example.org/prereg-sample/WebApplication/WebApplication.csproj.

  NuGet Config files used:
      /home/webadmin/.nuget/NuGet/NuGet.Config

  Feeds used:
      https://api.nuget.org/v3/index.json
webadmin@sandbox:/www/web/prod/prereg.example.org/prereg-sample$ dotnet publish
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.

  WebApplication -> /www/web/prod/prereg.example.org/prereg-sample/WebApplication/bin/Debug/netcoreapp1.1/WebApplication.dll
webadmin@sandbox:/www/web/prod/prereg.example.org/prereg-sample$ cd WebApplication/
webadmin@sandbox:/www/web/prod/prereg.example.org/prereg-sample/WebApplication$ dotnet run
Hosting environment: Production
Content root path: /www/web/prod/prereg.example.org/prereg-sample/WebApplication
Now listening on: http://sandbox.example.lab:5000
Application started. Press Ctrl+C to shut down.

여기 결과가 있습니다

[sandbox]/etc/systemd/system> ps aux |grep dotnet
webadmin 29736  1.2  0.5 3286936 48576 pts/4   SLl+ 13:19   0:00 dotnet run
webadmin 29775  1.5  0.5 21251244 42736 pts/4  SLl+ 13:19   0:00 dotnet exec /www/web/prod/prereg.example.org/prereg-sample/WebApplication/bin/Debug/netcoreapp1.1/WebApplication.dll

하지만 이것을 systemd에 추가하면 예를 들어 자동으로 시작되도록 Linux 서비스처럼 작동하게 만들려고 합니다.

다음 구성으로

[Unit]
    Description=prereg application

    [Service]
    WorkingDirectory=/www/web/prod/prereg.example.org/prereg-sample/WebApplication/bin/Debug/netcoreapp1.1/
    ExecStart=/usr/bin/dotnet /www/web/prod/prereg.example.org/prereg-sample/WebApplication/bin/Debug/netcoreapp1.1/WebApplication.dll
    Restart=always
    RestartSec=10                                          # Restart service after 10 seconds if dotnet service crashes
    SyslogIdentifier=prereg-sample
    User=webadmin
    Environment=ASPNETCORE_ENVIRONMENT=Production

    [Install]
    WantedBy=multi-user.target

이런 오류가 발생합니다. 왜 이런 일이 발생하는지 아시나요?

[sandbox]/etc/systemd/system> systemctl start prereg-sample
[sandbox]/etc/systemd/system> systemctl status prereg-sample
prereg-sample.service - prereg application
   Loaded: loaded (/etc/systemd/system/prereg-sample.service; enabled)
   Active: failed (Result: start-limit) since Sat 2017-03-18 13:24:23 +04; 8s ago
  Process: 30080 ExecStart=/usr/bin/dotnet /www/web/prod/prereg.example.org/prereg-sample/WebApplication/bin/Debug/netcoreapp1.1/WebApplication.dll (code=killed, signal=ABRT)

[sandbox]/etc/systemd/system> journalctl -fu prereg-sample
-- Logs begin at Fri 2017-03-17 11:56:37 +04. --
Mar 18 13:24:23 sandbox.example.lab prereg-sample[30064]: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
Mar 18 13:24:23 sandbox.example.lab prereg-sample[30064]: at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
Mar 18 13:24:23 sandbox.example.lab prereg-sample[30064]: at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
Mar 18 13:24:23 sandbox.example.lab prereg-sample[30064]: at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
Mar 18 13:24:23 sandbox.example.lab prereg-sample[30064]: at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureStartup()
Mar 18 13:24:23 sandbox.example.lab prereg-sample[30080]: Unhandled Exception: System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional. The physical path is '/www/web/prod/prereg.example.o...ppsettings.json'.
Mar 18 13:24:23 sandbox.example.lab prereg-sample[30080]: at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
Mar 18 13:24:23 sandbox.example.lab prereg-sample[30080]: at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
Mar 18 13:24:23 sandbox.example.lab prereg-sample[30080]: at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
Mar 18 13:24:23 sandbox.example.lab prereg-sample[30080]: at WebApplication.Startup..ctor(IHostingEnvironment env) in /www/web/prod/prereg.example.org/prereg-sample/WebApplication/Startup.cs:line 23

답변1

나는 너무 멍청하다.

The configuration file 'appsettings.json' was not found and is not optional.

이는 폴더가 잘못 설정되었음을 의미합니다. 폴더는 /publish여야 하며 appsettings.json이 있습니다. 그리고 그것은 효과가 있었습니다. 그리고 개발자는 MongoDb 연결 문자열이 포함된 구성 파일을 추가하지 않았습니다.

관련 정보