‘Service’ 部分中的 ‘PidFile’ 有什么问题(“Service” 部分中的未知左值 ‘PidFile’)?

‘Service’ 部分中的 ‘PidFile’ 有什么问题(“Service” 部分中的未知左值 ‘PidFile’)?

我有一个使用实例的 systemd 服务文件,该文件对于start和运行良好status,但随后stop显示status这些错误消息:

Runtime directory is not valid, ignoring assignment: /var/run/iotwatch/%i
Unknown lvalue 'PidFile' in section 'Service'

详细信息如下:首先是服务文件:/usr/lib/systemd/system/[email protected]

[Unit]
Description=iotwatch I/O performance monitor instance %I
Documentation=man:iotwatch(1)
PartOf=iotwatch.target
#Requisite=
After=nss-user-lookup.target time-sync.target paths.target
#Before=

[Service]
Type=forking
Environment="IOTWATCH_INSTANCE=%i"
RuntimeDirectory=/var/run/iotwatch/%i
WorkingDirectory=/var/run/iotwatch/%i
ExecStart=/usr/lib/iotwatch/iotwatch-service-wrapper %i start
#ExecReload=/usr/...
ExecStop=/usr/lib/iotwatch/iotwatch-service-wrapper %i stop
#SyslogIdentifier=%p-%i
TimeoutStopSec=30
PidFile=/var/run/iotwatch/iotwatch-%i.pid
Restart=always
RestartPreventExitStatus=5 6
StartLimitBurst=1

[Install]
WantedBy=multi-user.target

然后是启动后的状态:

h02:~ # systemctl start iotwatch@VAR -l
h02:~ # systemctl status iotwatch@VAR -l[email protected] - iotwatch I/O performance monitor instance VAR
   Loaded: loaded (/usr/lib/systemd/system/[email protected]; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2019-04-25 11:40:47 CEST; 6s ago
     Docs: man:iotwatch(1)
  Process: 12907 ExecStart=/usr/lib/iotwatch/iotwatch-service-wrapper %i start (code=exited, status=0/SUCCESS)
 Main PID: 12920 (iotwatch-VAR)
    Tasks: 4 (limit: 512)
   CGroup: /system.slice/system-iotwatch.slice/[email protected]
           └─12920 ./iotwatch-VAR -l /var/log/iotwatch/VAR/iotwatch-VAR.log -m I -p /var/run/iotwatch/VAR/iotwatch-VAR.pid -d1 -a0.00 -b512 -i4 -sD -t0.5 -TX=0.25:0.50,A=0.025:0.05 -OR -OS:T=F75,S:M=O52,N:3.29/60,Q:C=120,P:nagios.nagios=0664 /dev/sys/var

Apr 25 11:40:47 h02 systemd[1]: Starting iotwatch I/O performance monitor instance VAR...
Apr 25 11:40:47 h02 iotwatch-service-wrapper[12907]: Starting iotwatch VAR
Apr 25 11:40:47 h02 systemd[1]: Started iotwatch I/O performance monitor instance VAR.
h02:~ # ll /var/run/iotwatch/VAR/iotwatch-VAR.pid
-rw-r--r-- 1 root root 6 Apr 25 11:40 /var/run/iotwatch/VAR/iotwatch-VAR.pid

最后是停止后的状态:

h02:~ # systemctl stop iotwatch@VAR -l
h02:~ # systemctl status iotwatch@VAR -l[email protected] - iotwatch I/O performance monitor instance VAR
   Loaded: loaded (/usr/lib/systemd/system/[email protected]; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:iotwatch(1)

Apr 25 11:40:47 h02 systemd[1]: Started iotwatch I/O performance monitor instance VAR.
Apr 25 11:41:24 h02 systemd[1]: Stopping iotwatch I/O performance monitor instance VAR...
Apr 25 11:41:24 h02 iotwatch-service-wrapper[12962]: Stopping iotwatch VAR
Apr 25 11:41:27 h02 systemd[1]: Stopped iotwatch I/O performance monitor instance VAR.
Apr 25 11:41:27 h02 systemd[1]: [/usr/lib/systemd/system/[email protected]:12] Runtime directory is not valid, ignoring assignment: /var/run/iotwatch/%i
Apr 25 11:41:27 h02 systemd[1]: [/usr/lib/systemd/system/[email protected]:19] Unknown lvalue 'PidFile' in section 'Service'
Apr 25 11:41:27 h02 systemd[1]: [/usr/lib/systemd/system/[email protected]:12] Runtime directory is not valid, ignoring assignment: /var/run/iotwatch/%i
Apr 25 11:41:27 h02 systemd[1]: [/usr/lib/systemd/system/[email protected]:19] Unknown lvalue 'PidFile' in section 'Service'
Apr 25 11:41:32 h02 systemd[1]: [/usr/lib/systemd/system/[email protected]:12] Runtime directory is not valid, ignoring assignment: /var/run/iotwatch/%i
Apr 25 11:41:32 h02 systemd[1]: [/usr/lib/systemd/system/[email protected]:19] Unknown lvalue 'PidFile' in section 'Service'

我该如何修复服务文件以避免这些消息?

答案1

该设置称为“PIDFile=”,而不是“PidFile=”,请参阅文档。

RuntimeDirectory= 采用相对路径,请参阅文档。

请务必先查看文档。这些内容都有很好的记录。

相关内容