Systemd 似乎没有正确生成主 PID

Systemd 似乎没有正确生成主 PID

我根据需要修改了 /lib/systemd/system/snmpd.service 文件。以下是我修改的 snmpd.service 文件的内容。

[Unit]
Description=Simple Network Management Protocol (SNMP) Daemon.
After=network.target
ConditionPathExists=/etc/snmp/snmpd.conf

[Service]
Type=notify
RuntimeDirectory=agentx
ExecStart=/usr/sbin/snmpd -Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux,mteTrigger,mteTriggerConf -p /run/snmpd.pid
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

daemon-reload 后,我输入命令“systemctl start snmpd”。我收到以下错误。

× snmpd.service - Simple Network Management Protocol (SNMP) Daemon.
     Loaded: loaded (/lib/systemd/system/snmpd.service; enabled; vendor preset: enabled)
     Active: failed (Result: protocol) since Thu 2023-03-16 11:39:21 KST; 12min ago
    Process: 3046725 ExecStart=/usr/sbin/snmpd -Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux,mteTrigger,mteTriggerConf -p /run/snmpd.pid (code=exited, status=0/SUCCESS)
   Main PID: 3046725 (code=exited, status=0/SUCCESS)
        CPU: 48ms

Mar 16 11:39:21 esm-dev systemd[1]: Starting Simple Network Management Protocol (SNMP) Daemon....
Mar 16 11:39:21 esm-dev snmpd[3046725]: Turning on AgentX master support.
Mar 16 11:39:21 esm-dev snmpd[3046727]: NET-SNMP version 5.9.1
Mar 16 11:39:21 esm-dev systemd[1]: snmpd.service: Got notification message from PID 3046727, but reception only permitted for main PID which is currently not known
Mar 16 11:39:21 esm-dev snmpd[3046727]: Received TERM or STOP signal...  shutting down...
Mar 16 11:39:21 esm-dev systemd[1]: snmpd.service: Failed with result 'protocol'.
Mar 16 11:39:21 esm-dev systemd[1]: Failed to start Simple Network Management Protocol (SNMP) Daemon..

根据错误信息,似乎主PID和下发通知消息的PID不同。

主PID:3046725

收到来自 PID 3046727 的通知消息

...

/run/snmpd.pid 文件包含 3046727

一件有趣的事情是,MainPID 和发送通知消息的 PID 之间的差异始终为 2。

当我再次进入systemctl start snmpd时,

× snmpd.service - Simple Network Management Protocol (SNMP) Daemon.
     Loaded: loaded (/lib/systemd/system/snmpd.service; enabled; vendor preset: enabled)
     Active: failed (Result: protocol) since Thu 2023-03-16 11:58:30 KST; 2s ago
    Process: 3047690 ExecStart=/usr/sbin/snmpd -Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux,mteTrigger,mteTriggerConf -p /run/snmpd.pid (code=exited, status=0/SUCCESS)
   Main PID: 3047690 (code=exited, status=0/SUCCESS)
        CPU: 41ms

Mar 16 11:58:30 esm-dev systemd[1]: Starting Simple Network Management Protocol (SNMP) Daemon....
Mar 16 11:58:30 esm-dev snmpd[3047690]: Turning on AgentX master support.
Mar 16 11:58:30 esm-dev snmpd[3047692]: NET-SNMP version 5.9.1
Mar 16 11:58:30 esm-dev snmpd[3047692]: Received TERM or STOP signal...  shutting down...
Mar 16 11:58:30 esm-dev systemd[1]: snmpd.service: Got notification message from PID 3047692, but reception only permitted for main PID which is currently not known
Mar 16 11:58:30 esm-dev systemd[1]: snmpd.service: Failed with result 'protocol'.
Mar 16 11:58:30 esm-dev systemd[1]: Failed to start Simple Network Management Protocol (SNMP) Daemon..

主PID:3047690

收到来自 PID 3047692 的通知消息

我想知道为什么 MainPID 和来自 PID 的通知消息不同。我想知道如何使用 systemctl 正常运行 snmpd。

有人帮助我吗?

答案1

-f从命令行中删除了该标志snmpd;该标志指示snmpd 不是分叉。如果您希望服务正常工作,您需要恢复该标志。

顺便说一句,您不应该修改/lib/systemd/system/snmpd.service,而应该将更改作为覆盖:

sudo systemctl edit snmpd

如何对 .service 进行修改并保持其持久性?了解详情。

相关内容