( 每日一记)centos7.6 使用systemctl自动启动服务(.net webapi)

1. 在centos7.6创建自动启动服务

linux默认指centos7.6 x86_64

2. 后台运行程序常见三种方式

  1. 命令后面 + &
  2. supervisor管理
  3. systemctl管理

3. systemctl管理easc启动

## 文件存放目录
 /usr/lib/systemd/system

## 启动文件名称 webapi.service
[Unit]
Description=The webapi server

[Service]
#Type=forking
WorkingDirectory=/data/webapi
ExecStart=/usr/bin/dotnet Top.webapi.Web.dll --server.urls http://*:2002
#ExecStart=/usr/bin/dotnet /data/webapi/Top.webapi.Web.dll
ExecStop=/usr/bin/kill -9 $KillSignal
Restart=alway
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=wizeasc
PrivateTmp=true
#User=www-data
[Install]
WantedBy=multi-user.target

/data/webapi 为项目文件存放目录,根据实际情况调整
http://*:2002 为项目启动端口
/usr/bin/dotnet 为dotnet命令的绝对路径

4. 启动easc

systemctl daemon-reload
systemctl restart webapi
posted @ 2019-12-20 16:35  在下、剑之初  阅读(408)  评论(0)    收藏  举报