把dotnet也变成一个像mysql,nginx一样的后台服务,就可以用systemctl来管理了

1
2
# 编辑配置文件
vim /usr/lib/systemd/system/ZhaiFanhuaImage.service

输入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[Unit]
Description=ZhaiFanhuaImage

[Service]
WorkingDirectory=/home/web/zhaifanhua.com/demo/ZhaiFanhuaImage/
ExecStart=dotnet /home/web/zhaifanhua.com/demo/ZhaiFanhuaImage/ZhaiFanhuaImage.dll --urls="http://*:9708" --ip="127.0.0.1"
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=ZhaiFanhuaImage
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

进程守护

1
2
3
4
5
6
7
# -----------进程守护-----------------
# 更新配置
systemctl daemon-reload
# 设置开机自启动
systemctl enable ZhaiFanhuaImage
# 停止开机自启动
systemctl disable ZhaiFanhuaImage

管理命令

1
2
3
4
5
6
7
8
9
# -----------管理命令-----------------
# 启动服务
systemctl start ZhaiFanhuaImage
# 停止服务
systemctl stop ZhaiFanhuaImage
# 重新服务
systemctl restart ZhaiFanhuaImage
# 查看状态
systemctl status ZhaiFanhuaImage