vi /etc/systemd/system/demoNetCore.service
![复制代码](https://common.cnblogs.com/images/copycode.gif)
[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
![复制代码](https://common.cnblogs.com/images/copycode.gif)
# 重载系统
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