When I start Net-SNMP from systemd, there is no error message but the daemon does not run:
% sudo systemctl start snmpd
%
When I start it from the command line, it runs:
% sudo /usr/sbin/snmpd
and answers to SNMP queries.
If I add the debug flags (-LSdd), I see that the daemon launched by systemd is killed immediately after:
Apr 7 15:37:50 localhost snmpd[1298]: NET-SNMP version 5.7.2
Apr 7 15:37:50 localhost snmpd[1298]: Received TERM or STOP signal... shutting down...
The service file is the default one of the Arch Linux package:
[Unit]
Description=Simple Network Management Protocol (SNMP) Daemon
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/usr/sbin/snmpd
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
If I add RemainAfterExit=yes in the service file, snmpd works but the machine no longer starts properly (no DHCP client, for instance)
The system is an up-to-date Arch Linux, the version of the package is:
Name : net-snmp
Version : 5.7.2-3
There is an old Arch Linux bug report apparently for this very bug: https://bugs.archlinux.org/task/32258?string=snmp&project=1&type%5B0%5D=&sev%5B0%5D=&pri%5B0%5D=&due%5B0%5D=&reported%5B0%5D=&cat%5B0%5D=&status%5B0%5D=open&percent%5B0%5D=&opened=&dev=&closed=&duedatefrom=&duedateto=&changedfrom=&changedto=&openedfrom=&openedto=&closedfrom=&closedto=
The problem comes from the fork of snmpd during start.
My service file (for Exherbo) forces snmpd to not use
fork()
(-f
) and run the service withType=simple
.Type=forking
is the good way for the default behavior of snmpd, but it is incomplete.It is highly recommended to specify
PIDFile
when usingType=forking
because systemd is not always able to know which process to monitor after the first process exits.Just add this:
This change will also fix
ExecReload
.