vim /lib/systemd/system/MqttDemo.service
编辑内容
[Unit]
Description=MqttDemo running on Centos8
[Service]# 应用程序所在的文件目录
WorkingDirectory=/home/demo/
ExecStart=dotnet /home/demo/MqttDemo.dll
Restart=always
# 如果dotnet服务崩溃,10秒后重新启动服务
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=MqttDemo
User=root
#Production:生产环境 Development:开发环境
Environment=ASPNETCORE_ENVIRONMENT=Development
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
7.3、重载系统及设置开机启动
# 重载系统
systemctl daemon-reload
# 开机自启动
systemctl enable MqttDemo.service
#启动
systemctl start MqttDemo
#重新加载systectl
systemctl daemon-reload