It seems that from Ubuntu 18.04 service will ignore the file /etc/default/snmpd
file.
I need to run snmpd
with the following options (as I have them in /etc/default/snmpd
):
SNMPDOPTS='-Lsd -Lf /dev/null -I -smux,mteTrigger,mteTriggerConf -p /run/snmpd.pid udp:161,udp6:161'
However when I run it as service, this is what is executing:
# service snmpd status
● snmpd.service - Simple Network Management Protocol (SNMP) Daemon.
Loaded: loaded (/lib/systemd/system/snmpd.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-10-23 10:44:56 JST; 2s ago
Process: 3089 ExecStartPre=/bin/mkdir -p /var/run/agentx (code=exited, status=0/SUCCESS)
Main PID: 3091 (snmpd)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/snmpd.service
└─3091 /usr/sbin/snmpd -Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux mteTrigger mteTriggerConf -f
10月 23 10:44:56 example.com systemd[1]: Starting Simple Network Management Protocol (SNMP) Daemon....
10月 23 10:44:56 example.com systemd[1]: Started Simple Network Management Protocol (SNMP) Daemon..
10月 23 10:44:58 example.com snmpd[3091]: NET-SNMP version 5.7.3
I have tried the solution posted here:
As root (or with sudo) run systemctl edit snmpd. In that new file, enter:
[Service]
ExecStart=
ExecStart=/usr/sbin/snmpd -Lsd -Lf /dev/null -I -smux,mteTrigger,mteTriggerConf -p /run/snmpd.pid udp:161,udp6:161
However when I do that, service snmpd status
reports:
● snmpd.service - Simple Network Management Protocol (SNMP) Daemon.
Loaded: loaded (/lib/systemd/system/snmpd.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/snmpd.service.d
└─override.conf
Active: inactive (dead) since Fri 2020-10-23 10:51:19 JST; 4s ago
Process: 14039 ExecStart=/usr/sbin/snmpd -Lsd -Lf /dev/null -I -smux,mteTrigger,mteTriggerConf -p /run/snmpd.pid udp:161,udp6:161 (code=exited, status=0/SUCCESS)
Process: 14038 ExecStartPre=/bin/mkdir -p /var/run/agentx (code=exited, status=0/SUCCESS)
Main PID: 14039 (code=exited, status=0/SUCCESS)
10月 23 10:51:17 example.com systemd[1]: Starting Simple Network Management Protocol (SNMP) Daemon....
10月 23 10:51:17 example.com systemd[1]: Started Simple Network Management Protocol (SNMP) Daemon..
10月 23 10:51:19 example.com snmpd[14063]: NET-SNMP version 5.7.3
10月 23 10:51:19 example.com snmpd[14063]: Received TERM or STOP signal... shutting down...
It seems to work for a few seconds before it exits without error.
If I stop the service and I start snmpd
with those options manually it works fine.
What can I do to fix it?
I solved adding
-f
at the end (which prevent the daemon from exiting):