0

I modified the /lib/systemd/system/snmpd.service file as needed. Below is the contents of the snmpd.service file that I modified.

[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

After daemon-reload, I entered the command "systemctl start snmpd". And I got the error below.

× 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..

According to the error, it seems that the main PID and the PID that delivered the notification message are different.

Main PID: 3046725

Got notification message from PID 3046727

...

and The /run/snmpd.pid file contained 3046727

One interesting thing is that the difference between the MainPID and the PID that delivered the notification message is always 2.

When I entered systemctl start snmpd again,

× 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..

MainPID: 3047690

Got notification message from PID 3047692

I wonder why MainPID and notification message from PID are different. And I wonder how to run snmpd normally with systemctl.

anyone help me?

1 Answer 1

0

You removed the -f flag from the snmpd command line; that flag instructs snmpd not to fork. You need to restore the flag if you want your service to work properly.

Incidentally, instead of modifying /lib/systemd/system/snmpd.service, you should make your changes as an override:

sudo systemctl edit snmpd

See How can I make a modification to a .service and keep it persistent? for details.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .