前言
我們一般可以在Linux服務器上執行 dotnet
創建服務文件
創建服務定義文件:
<code>vim /etc/systemd/system/qf-intecabinet.service/<code>
以下是應用的一個示例服務文件:
<code>[Unit]
Description=運行Qf.InteCabinet服務
[Service]
WorkingDirectory=/opt/InteCabinet # 依賴環境,可以指定多個
ExecStart=/usr/bin/dotnet /opt/InteCabinet/Qf.InteCabinet.WebApi.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=qf-intecabinet
User=root # 管理服務的用戶,用戶必須存在並且擁有正確應用文件的所有權
Environment=ASPNETCORE_ENVIRONMENT=Production # 環境變量
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target # 該服務所在的Target/<code>
管理服務
保存該文件並啟用該服務
<code>systemctl enable qf-intecabinet.service/<code>
啟動該服務
<code>systemctl start qf-intecabinet.service/<code>
查看服務狀態
<code>systemctl status qf-intecabinet.service/<code>
查看日誌
<code>journalctl -fu qf-intecabinet.service/<code>
使用時間選項(如 --since today、--until 1 hour ago)或這些選項的組合可以減少返回的條目數
<code>journalctl -fu qf-intecabinet.service --since "2020-01-01" --until "2020-03-01 12:00"/<code>
關閉服務
<code>systemctl stop qf-intecabinet.service/<code>
閱讀更多 愛踢狂人 的文章