vi /etc/systemd/system/demoNetCore.service
[Unit]
Description=AspnetCoreDemo running on Centos8
[Service]# 應用程序所在的文件目錄
WorkingDirectory=/www/wwwroot/demo.cn/
ExecStart=/usr/share/dotnet/dotnet /www/wwwroot/demo.cn/Jb.Web.dll
Restart=always
# 如果dotnet服務崩潰,10秒後重新啓動服務
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=AspNetCoreDemo
User=root
#Production:生產環境 Development:開發環境
Environment=ASPNETCORE_ENVIRONMENT=Development
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
# 重載系統
systemctl daemon-reload
# 開機自啓動
systemctl enable aspnetCore.service
2.使自啓動生效
systemctl enable demoNetCore.service
3.立即啓動項目服務
systemctl start demoNetCore.service
systemctl stop demoNetCore.service
systemctl restart demoNetCore.service
systemctl list-units --type=service