CentOS8 设置.net core开机自动启动

/etc/systemd/system 下创建 test001.service文件:
进入/etc/systemd/system  vi test001.service 内容是以下代码
/usr/src/testDemo/为网站根目录, WebApplication1.dll为主程序 ,/usr/share/dotnet/dotnet为运行时启动程序
[Unit]
Description="test001.Service"      

[Service]
Type=simple
GuessMainPID=true
WorkingDirectory=/usr/src/testDemo/
StandardOutput=journal
StandardError=journal
ExecStart=/usr/lib64/dotnet/dotnet /usr/src/testDemo/WebApplication1.dll  --urls="http://*:5000"                                 
Restart=always
[Install]
WantedBy=multi-user.target
2.使自启动生效
systemctl enable test001.service

3.立即启动项目服务
systemctl start test001.service  //启动
systemctl stop test001.service    //停止
systemctl restart test001.service  // 重启

5.重启服务:
shutdown -r now

6.重启后访问:http://ip:port/



视频教程请访问https://www.bilibili.com/video/BV1E44y1z75K/(如果不会请看我录制的视频教程)



评论