Linux自定义服务的创建

在/etc/systemd/system下创建gateway.service服务文件

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

[Service]
WorkingDirectory=/var/lib/jenkins/workspace/netcore/Ic.GateWay/bin/Debug/netcoreapp2.2/publish
ExecStart=/usr/bin/dotnet /var/lib/jenkins/workspace/netcore/Ic.GateWay/bin/Debug/netcoreapp2.2/publish/Ic.GateWay.dll --ip * --port 5200
Restart=always
RestartSec=25
SyslogIdentifier=gateway
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target

启动:systemctl start my-demo.service
结束:systemctl stop my-demo.service
重启:systemctl restart my-demo.service
状态:systemctl status my-demo.service
查看服务状态: systemctl status network.service
列出所有可用单元:systemctl list-unit-files
列出所有运行中单元:systemctl list-units
列出所有失败单元:systemctl --failed
重新载入已修改的服务 systemctl daemon-reload