Systemd
通過守護程序 systemd 在相對路徑中啟動 dotnet core 執行檔
dotnet core
我已經為 linux arm 機器開發並發布了一個 Web 應用程序。為此,已啟動命令:dotnet publish --runtime linux-arm -p:PublishSingleFile=true
結果給出了目錄:
Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 10/03/2020 8:56 wwwroot -a---- 09/03/2020 10:54 162 appsettings.Development.json -a---- 09/03/2020 10:54 192 appsettings.json -a---- 10/03/2020 8:56 108097487 coremonitor -a---- 09/03/2020 12:59 7248 coremonitor.pdb -a---- 10/03/2020 8:56 474 web.config
coremonitor
執行檔在哪裡。該數據被發送到伺服器並儲存在路徑中/root/datalogger/linux-arm/
。然後我們創建了 systemd 守護程序來啟動它:[Unit] Description=Data Logger Monitor Daemon [Service] ExecStart=./coremonitor WorkingDirectory=/root/dataloggermonitor/linux-arm User=dotnetuser Group=dotnetuser Restart=on-failure SyslogIdentifier=DataLoggerMonitor-Service PrivateTmp=true [Install] WantedBy=multi-user.target
重新啟動後,我得到以下 systemd 日誌(
systemctl status dataloggermonitor
):● dataloggermonitor.service - Data Logger Monitor Daemon Loaded: error (Reason: Invalid argument) Active: inactive (dead)
ExecStart
這可以通過直接在參數中輸入執行路徑來解決。系統將從自己的相對路徑啟動執行檔:[Unit] Description=Data Logger Monitor Daemon [Service] ExecStart=/root/dataloggermonitor/linux-arm/coremonitor User=dotnetuser Group=dotnetuser Restart=on-failure SyslogIdentifier=DataLoggerMonitor-Service PrivateTmp=true [Install] WantedBy=multi-user.target
得到:
● dataloggermonitor.service - Data Logger Monitor Daemon Loaded: loaded (/etc/systemd/system/dataloggermonitor.service; enabled) Active: active (running) since Tue 2020-03-10 10:33:41 CET; 28s ago Main PID: 403 (coremonitor) CGroup: /system.slice/dataloggermonitor.service └─403 /root/dataloggermonitor/linux-arm/coremonitor Mar 10 10:33:41 techbase systemd[1]: Starting Data Logger Monitor Daemon... Mar 10 10:33:41 techbase systemd[1]: Started Data Logger Monitor Daemon. Mar 10 10:34:01 techbase DataLoggerMonitor-Service[403]: Hosting environment: Production Mar 10 10:34:01 techbase DataLoggerMonitor-Service[403]: Content root path: /var/tmp/.net/coremonitor/gcrmbwbh.wxk/ Mar 10 10:34:01 techbase DataLoggerMonitor-Service[403]: Now listening on: http://[::]:5000 Mar 10 10:34:01 techbase DataLoggerMonitor-Service[403]: Application started. Press Ctrl+C to shut down.