Centos7下设置.NetCore程序自动启动

1.上传.NetCore项目文件到服务器,比如上传路径为:/data/web/apiweb

2.切换到/lib/systemd/system/目录,创建自启动文件。

cd /lib/systemd/system/
vi apiweb.service

文件内容如下:

[Unit]
Description=apiweb
After=network.target

[Service]
WorkingDirectory=/data/web/apiweb  #项目路径
ExecStart=/usr/bin/dotnet /data/web/apiweb/apiweb.dll  #启动指令
User=root
Group=root
Restart=always  #设置服务停止后一直重启
RestartSec=10  #服务停止后10秒开始重启

[Install]
WantedBy=multi-user.target

 

3.设置自启动

systemctl enable apiweb.service

4.立即启动服务

systemctl start apiweb.service

5.最后检查下服务运行状态

systemctl status apiweb.service

 6.显示所有已启动的服务

systemctl list-units --type=service

 

posted @ 2020-10-10 16:24  JcongJason  阅读(758)  评论(1编辑  收藏  举报