Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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=

share|improve this question
    
This service file apparently works fine: github.com/CleverCloud/CleverCloud-exheres/blob/master/packages/… Now, I would appreciate explanations about why it works and why the default one does not :-) –  bortzmeyer Apr 7 '13 at 15:09

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
Tested and it works. Thanks. –  bortzmeyer Apr 7 '13 at 16:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.