通过守护进程 systemd 在相对路径中启动 dotnet core 可执行文件

通过守护进程 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)

答案1

通过在参数中直接输入执行路径可以解决此问题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.

相关内容