LINUX 守护进程

在/etc/systemd/system 下新建文件(推荐使用MobaXterm),文件名以.service结尾,配置内容为(注意:中文注释需要删掉,否则部分 Linux 服务器会报错):

 

[Unit]
Description=webapi #服务描述,随便填就好

[Service]
WorkingDirectory=/website/webapi #工作目录,填你应用的绝对路径
ExecStart=/usr/bin/dotnet /website/blogcore/CZKJ.CMS.Web.dll --urls http://*:5000      #启动:前半截是你dotnet的位置(一般都在这个位置),后半部分是你程序入口的dll,中间用空格隔开
Restart=always  
RestartSec=25 #如果服务出现问题会在25秒后重启,数值可自己设置
SyslogIdentifier=blogcore  #设置日志标识,此行可以没有
User=root   #配置服务用户,越高越好
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target

写完配置文件后保存,输入指令确认服务:

systemctl enable (你的服务名).service   

例如:systemctl enable webapi.service;

然后启动服务  systemctl start webapi.service

停止服务  systemctl stop webapi.service

然后查看一下服务状态:systemctl status webapi出现状态说明服务运行正常。

 

( 借鉴:https://www.cnblogs.com/Tassdar/p/9587829.html )

posted @ 2022-03-27 23:18  steeld  阅读(207)  评论(0)    收藏  举报