将以下代码复制到Texteditor并将其保存为YourServiceName.services
"/etc/systemd/system"
路径
[Unit]
Description=MyServiceDescription
[Service]
WorkingDirectory=/opt/<MyServicePath>
ExecStart=opt/dotnet/shared/Microsoft.NETCore.App/1.1.2/dotnet /opt/<MyPath>/<MyService>.dll
[Install]
WantedBy=multi-user.target
打开命令框并执行以下命令:
systemctl enable <YourServiceName>.service
systemctl start <YourServiceName>.service
systemctl status <YourServiceName>.service -l
常见的错误是
- .../dotnet
和/opt/...
之间缺少空格
- 落在/opt/dotnet/dotnet
文件位置的dotnet文件
- 没有列出的工作目录(dotnet找不到appsettings.json
文件)