5

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=

bortzmeyer
  • 3,903
  • 1
  • 20
  • 24
  • This service file apparently works fine: https://github.com/CleverCloud/CleverCloud-exheres/blob/master/packages/net/net-snmp/files/systemd/snmpd.service Now, I would appreciate explanations about why it works and why the default one does not :-) – bortzmeyer Apr 07 '13 at 15:09

1 Answers1

6

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 with Type=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 using Type=forking because systemd is not always able to know which process to monitor after the first process exits.

Just add this:

Type=forking
PIDFile=/var/run/snmpd.pid
ExecStart=/usr/sbin/snmpd -p /var/run/snmpd.pid

This change will also fix ExecReload.

Kdecherf
  • 466
  • 3
  • 9