[Pkg-net-snmp-devel] snmpd init script checking status of snmptrapd even when snmpdtrapd isn't configured to run?

Jordan Webb jwebb at cleversafe.com
Tue Jan 31 18:52:46 UTC 2012

I'm currently working on an application where I need to check if snmpd is running or not. We have generalized checking if a service is running by using "/usr/sbin/service $service status", which in turn runs "/etc/init.d/$service status" and gives us a return code to interpret. My machine is configured to run snmpd but not snmptrapd (SNMPDRUN=yes and TRAPDRUN=no in /etc/default/snmpd). The problem is that the "status" action in the init script checks both snmpd and snmptrapd, even if snmptrapd isn't configured to start. When I run "/etc/init.d/snmpd status" with snmpd running, I get $?=3 because snmptrapd isn't running, instead of the $?=0 I was expecting.

I'm not sure if you would consider this a bug or not; after all, snmptrapd isn't running, so the init script is technically correct in saying so. On the other hand, I don't really care that it isn't running, because I never asked for it to be started in the first place.

What I have done is wrap the "status_of_proc" calls in the same if statements that are used in the "start" action:

    if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
        status_of_proc /usr/sbin/snmpd snmpd || status=$?
    if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
        status_of_proc /usr/sbin/snmptrapd snmptrapd || status=$?

I do not know enough to be sure that it would be reasonable to run snmptrapd without running snmpd, but it appears from the init script that it would be. If this is the case, an possibly better alternative to my solution would be to have separate init scripts for snmpd and snmptrapd, so that they can be independently stopped, started, and checked without inadvertently conflating the return status of the two.

If this behavior is indeed deemed to be a bug, I would be happy to file a proper bug report and submit a patch to resolve it in either of the ways suggested above.


More information about the Pkg-net-snmp-devel mailing list