Browse Source

netsnmp: adjust init script by creating start(), stop(), reload()

Change the init script to get rid of double code. Start, stop and reload
code has been put into separate functions and 'restart' will just call
stop() and start() with a delay in between.

Signed-off-by: Andreas Ehmanns <universeII@gmx.de>
Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
universe II 9 years ago
parent
commit
291f3f948d
1 changed files with 37 additions and 34 deletions
  1. 37 34
      package/netsnmp/S59snmpd

+ 37 - 34
package/netsnmp/S59snmpd

@@ -38,56 +38,59 @@ if [ "$SNMPDCOMPAT" = "yes" ]; then
   ln -sf /var/agentx/master /var/run/agentx
   ln -sf /var/agentx/master /var/run/agentx
 fi
 fi
 
 
-case "$1" in
-  start)
+start() {
     printf "Starting network management services:"
     printf "Starting network management services:"
     if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
     if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
-      start-stop-daemon -q -S -x /usr/sbin/snmpd -- $SNMPDOPTS
-      printf " snmpd"
+        start-stop-daemon -q -S -x /usr/sbin/snmpd -- $SNMPDOPTS
+        printf " snmpd"
     fi
     fi
     if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
     if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
-      start-stop-daemon -q -S -x /usr/sbin/snmptrapd -- $TRAPDOPTS
-      printf " snmptrapd"
+        start-stop-daemon -q -S -x /usr/sbin/snmptrapd -- $TRAPDOPTS
+        printf " snmptrapd"
     fi
     fi
     echo "."
     echo "."
-    ;;
-  stop)
+}
+
+stop() {
     printf "Stopping network management services:"
     printf "Stopping network management services:"
     start-stop-daemon -q -K $ssd_oknodo -x /usr/sbin/snmpd
     start-stop-daemon -q -K $ssd_oknodo -x /usr/sbin/snmpd
     printf " snmpd"
     printf " snmpd"
     start-stop-daemon -q -K $ssd_oknodo -x /usr/sbin/snmptrapd
     start-stop-daemon -q -K $ssd_oknodo -x /usr/sbin/snmptrapd
     printf " snmptrapd"
     printf " snmptrapd"
     echo "."
     echo "."
-    ;;
-  restart)
-    printf "Restarting network management services:"
-    start-stop-daemon -q -K $ssd_oknodo -x /usr/sbin/snmpd
-    start-stop-daemon -q -K $ssd_oknodo -x /usr/sbin/snmptrapd
-    # Allow the daemons time to exit completely.
-    sleep 2
-    if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
-      start-stop-daemon -q -S -x /usr/sbin/snmpd -- $SNMPDOPTS
-      printf " snmpd"
-    fi
-    if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
-      # Allow snmpd time to start up.
-      sleep 1
-      start-stop-daemon -q -S -x /usr/sbin/snmptrapd -- $TRAPDOPTS
-      printf " snmptrapd"
-    fi
-    echo "."
-    ;;
-  reload|force-reload)
+}
+
+reload() {
     printf "Reloading network management services:"
     printf "Reloading network management services:"
     if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
     if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
-      start-stop-daemon -q -K -s 1 -p /var/run/snmpd.pid -x /usr/sbin/snmpd
-      printf " snmpd"
+        start-stop-daemon -q -K -s 1 -p /var/run/snmpd.pid -x /usr/sbin/snmpd
+        printf " snmpd"
     fi
     fi
     echo "."
     echo "."
-    ;;
-  *)
-    echo "Usage: /etc/init.d/snmpd {start|stop|restart|reload|force-reload}"
-    exit 1
+}
+
+case "$1" in
+    start)
+        start
+        ;;
+
+    stop)
+        stop
+        ;;
+
+    restart)
+        stop
+        # Allow the daemons time to exit completely.
+        sleep 2
+        start
+        ;;
+
+    reload|force-reload)
+        reload
+        ;;
+    *)
+        echo "Usage: $0 {start|stop|restart|reload|force-reload}"
+        exit 1
 esac
 esac
 
 
 exit 0
 exit 0