dotnet

 

目錄

  • Install
  • Service

Install

 

rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm

# It can execute applications that are built for it

yum -y install dotnet-runtime-2.1

# a collection of libraries that form a Framework for building web applications

yum -y install aspnetcore-runtime-2.1

Notes

ASP.NET Core (aspnetcore-runtime) is built "on top of" .NET Core (dotnet-runtime)

 


Kestrel Service

 

红隼, web server for ASP.NET Core

included and enabled by default in ASP.NET Core

Service

/etc/systemd/system/PortalService.service

[Unit]
Description=Portal Application

[Service]
WorkingDirectory=/data/webapp
ExecStart=/usr/share/dotnet/dotnet /data/webapp/Portal.dll
Restart=always
RestartSec=10
SyslogIdentifier=webapp

Restart=always
RestartSec=5
KillSignal=SIGINT

# chown yourusername -R /data/webapp
User=yourusername

Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
Environment=ASPNETCORE_URLS=http://*:80
Environment=ASPNETCORE_VERSION=2.1.18
# SSL Settings
#Environment=ASPNETCORE_URLS=http://*:80;https://*:443
#Environment=ASPNETCORE_HTTPS_PORT=443
#Environment=ASPNETCORE_Kestrel__Certificates__Default__Password=PFX_PASS
#Environment=ASPNETCORE_Kestrel__Certificates__Default__Path=/data/SSL.pfx

[Install]
WantedBy=multi-user.target

說明

ASPNETCORE_URLS

Indicates the IP addresses or host addresses with ports and protocols that the server should listen on for requests.

i.e.

# Directs Kestrel to listen on port 5000 on all addresses
ENV ASPNETCORE_URLS=5000
# To also enable HTTPS on port 5001, copy the following example to your app Dockerfile
# ENV ASPNETCORE_URLS=5000;https://+:5001

ASPNETCORE_HTTPS_PORT

Set the HTTPS redirect port. Used in enforcing HTTPS.

Test

ps aux | grep dotnet

root     13495  0.0  1.4 12088696 115960 ?     SLsl May31   0:55 /usr/share/dotnet/dotnet /data/webapp/Portal.dll

P.S.

不可以用 "Type=notify" 除非

(1) 安了 Package: dotnet add package Microsoft.Extensions.Hosting.Systemd
(2) Code 內有 builder.Host.UseSystemd();

 


appsettings.json

 

Environment Variables

ASPNETCORE_URLS=http://localhost:5001/

相當於

{
  "Urls": "http://localhost:5001"
}

 


 

Creative Commons license icon Creative Commons license icon