Skip to contentSkip to conversation

Package netsnmp: Created start(), stop(), reload().

PATCH New Andreas Ehmanns 4 participants 13 messages Feb 25, 2016 – Jul 6, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 Package netsnmp: Created start(), stop(), reload().

Changed 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.

---
 package/netsnmp/S59snmpd | 71 +++++++++++++++++++++++++-----------------------
 1 file changed, 37 insertions(+), 34 deletions(-)
package/netsnmp/S59snmpd +37 -34
index 4eea512..cfda625 100755
@@ -38,56 +38,59 @@ if [ "$SNMPDCOMPAT" = "yes" ]; then
   ln -sf /var/agentx/master /var/run/agentx
 fi
 
-case "$1" in
-  start)
+start() {
     printf "Starting network management services:"
     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
     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
     echo "."
-    ;;
-  stop)
+}
+
+stop() {
     printf "Stopping network management services:"
     start-stop-daemon -q -K $ssd_oknodo -x /usr/sbin/snmpd
     printf " snmpd"
     start-stop-daemon -q -K $ssd_oknodo -x /usr/sbin/snmptrapd
     printf " snmptrapd"
     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:"
     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
     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
 
 exit 0
Signature · 1 line
2.1.4
#1 lore raw

PATCH 2/4 Package netsnmp: Removed 'set -e'

set -e has been removed from init script since it causes the init script to terminate if an error occurs. This prevents the script to create an "FAIL" printout in case of an error.

---
 package/netsnmp/S59snmpd | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
package/netsnmp/S59snmpd +1 -2
index cfda625..2762082 100755
@@ -1,4 +1,4 @@
-#! /bin/sh -e
+#! /bin/sh
 ### BEGIN INIT INFO
 # Provides:           snmpd snmptrapd
 # Required-Start:     $network $local_fs
@@ -11,7 +11,6 @@
 #
 # Author:    Jochen Friedrich <[email protected]>
 #
-set -e
 
 export PATH=/sbin:/usr/sbin:/bin:/usr/bin
 
Signature · 1 line
2.1.4
#2 lore raw

PATCH 2/4 Package netsnmp: Removed 'set -e'

Andreas, All,

On 2016-02-25 22:24 +0100, Andreas Ehmanns spake thusly:

Quoted 4 lines

set -e has been removed from init script since it causes the init script to terminate if an error occurs. This prevents the script to create an "FAIL" printout in case of an error.

And we're not doing it consistently either. I've looked at the startup script for busybox (mdev, watchdog, telnet, logging) and none uses 'set -e'.

Quoted 1 line

Regards,
Yann E. MORIN.

Quoted 29 lines
---
 package/netsnmp/S59snmpd | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
package/netsnmp/S59snmpd +1 -2
index cfda625..2762082 100755
@@ -1,4 +1,4 @@
-#! /bin/sh -e
+#! /bin/sh
 ### BEGIN INIT INFO
 # Provides:           snmpd snmptrapd
 # Required-Start:     $network $local_fs
@@ -11,7 +11,6 @@
 #
 # Author:    Jochen Friedrich <[email protected]>
 #
-set -e
 
 export PATH=/sbin:/usr/sbin:/bin:/usr/bin
 
Signature · 6 lines
2.1.4

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#3 lore raw

PATCH 3/4 Package netsnmp: Added missing reload of snmptrapd

In reply to Andreas Ehmanns

In case of a reload command the snmpdtrapd wasn't
restarted.

---
 package/netsnmp/S59snmpd | 5 +++++
 1 file changed, 5 insertions(+)
package/netsnmp/S59snmpd +5 -0
index 2762082..2d076e0 100755
@@ -65,6 +65,11 @@ reload() {
         start-stop-daemon -q -K -s 1 -p /var/run/snmpd.pid -x /usr/sbin/snmpd
         printf " snmpd"
     fi
+
+    if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
+        start-stop-daemon -q -K -s 1 -p /var/run/snmptrapd.pid -x /usr/sbin/snmptrapd
+        printf " snmptrapd"
+    fi
     echo "."
 }
 
Signature · 1 line
2.1.4
#4 lore raw

PATCH 3/4 Package netsnmp: Added missing reload of snmptrapd

Andreas, All

[not sure why, but my previous reply did not make it to the list...]

On 2016-02-25 22:24 +0100, Andreas Ehmanns spake thusly:

Quoted 4 lines

In case of a reload command the snmpdtrapd wasn't
restarted.

Regards,
Yann E. MORIN.

Quoted 27 lines
---
 package/netsnmp/S59snmpd | 5 +++++
 1 file changed, 5 insertions(+)
package/netsnmp/S59snmpd +5 -0
index 2762082..2d076e0 100755
@@ -65,6 +65,11 @@ reload() {
         start-stop-daemon -q -K -s 1 -p /var/run/snmpd.pid -x /usr/sbin/snmpd
         printf " snmpd"
     fi
+
+    if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
+        start-stop-daemon -q -K -s 1 -p /var/run/snmptrapd.pid -x /usr/sbin/snmptrapd
+        printf " snmptrapd"
+    fi
     echo "."
 }
 
Signature · 6 lines
2.1.4

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#5 lore raw

PATCH 4/4 Package netsnmp: Added OK/FAIL output

In reply to Andreas Ehmanns

Reworked output of start(), stop() and reload() functions. Return values of start-stop-daemon are now checked and a OK or FAIL message is printed out.

---
 package/netsnmp/S59snmpd | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)
package/netsnmp/S59snmpd +21 -14
index 2d076e0..94773db 100755
@@ -38,39 +38,45 @@ if [ "$SNMPDCOMPAT" = "yes" ]; then
 fi
 
 start() {
-    printf "Starting network management services:"
     if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
+        printf "Starting SNMP daemon: "
         start-stop-daemon -q -S -x /usr/sbin/snmpd -- $SNMPDOPTS
-        printf " snmpd"
+        [ $? = 0 ] && echo "OK" || echo "FAIL"
     fi
+
     if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
+        printf "Starting SNMP trap daemon: "
         start-stop-daemon -q -S -x /usr/sbin/snmptrapd -- $TRAPDOPTS
-        printf " snmptrapd"
+        [ $? = 0 ] && echo "OK" || echo "FAIL"
     fi
-    echo "."
 }
 
 stop() {
-    printf "Stopping network management services:"
-    start-stop-daemon -q -K $ssd_oknodo -x /usr/sbin/snmpd
-    printf " snmpd"
-    start-stop-daemon -q -K $ssd_oknodo -x /usr/sbin/snmptrapd
-    printf " snmptrapd"
-    echo "."
+    if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
+        printf "Stopping SNMP daemon: "
+        start-stop-daemon -q -K $ssd_oknodo -x /usr/sbin/snmpd
+        [ $? = 0 ] && echo "OK" || echo "FAIL"
+    fi
+
+    if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
+        printf "Stopping SNMP trap daemon: "
+        start-stop-daemon -q -K $ssd_oknodo -x /usr/sbin/snmptrapd
+        [ $? = 0 ] && echo "OK" || echo "FAIL"
+    fi
 }
 
 reload() {
-    printf "Reloading network management services:"
     if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
+        printf "Reloading SNMP daemon: "
         start-stop-daemon -q -K -s 1 -p /var/run/snmpd.pid -x /usr/sbin/snmpd
-        printf " snmpd"
+       [ $? = 0 ] && echo "OK" || echo "FAIL" 
     fi
 
     if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
+        printf "Reloading SNMP trap daemon: "
         start-stop-daemon -q -K -s 1 -p /var/run/snmptrapd.pid -x /usr/sbin/snmptrapd
-        printf " snmptrapd"
+        [ $? = 0 ] && echo "OK" || echo "FAIL"
     fi
-    echo "."
 }
 
 case "$1" in
@@ -92,6 +98,7 @@ case "$1" in
     reload|force-reload)
         reload
         ;;
+
     *)
         echo "Usage: $0 {start|stop|restart|reload|force-reload}"
         exit 1
Signature · 1 line
2.1.4
#6 lore raw

PATCH 4/4 Package netsnmp: Added OK/FAIL output

Andreas, All,

On 2016-02-25 22:24 +0100, Andreas Ehmanns spake thusly:

package/netsnmp/S59snmpd

Quoted 13 lines

Reworked output of start(), stop() and reload() functions. Return values of start-stop-daemon are now checked and a OK or FAIL message is printed out.

---
 package/netsnmp/S59snmpd | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)
package/netsnmp/S59snmpd +0 -0
index 2d076e0..94773db 100755

[--SNIP--]

package/netsnmp/S59snmpd case "$1" in · line 101

Quoted 5 lines
package/netsnmp/S59snmpd +1 -0
@@ -92,6 +98,7 @@ case "$1" in
     reload|force-reload)
         reload
         ;;
+

Spurious empty line.

Otherwise:

Regards,
Yann E. MORIN.

Quoted 10 lines
package/netsnmp/S59snmpd +0 -0
     *)
         echo "Usage: $0 {start|stop|restart|reload|force-reload}"
         exit 1
Signature · 6 lines
2.1.4

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#7 lore raw

PATCH 4/4 Package netsnmp: Added OK/FAIL output

Hello,

Quoted 7 lines · Yann E. MORIN

package/netsnmp/S59snmpd case "$1" in · line 101

Quoted 5 lines
package/netsnmp/S59snmpd +1 -0
@@ -92,6 +98,7 @@ case "$1" in
     reload|force-reload)
         reload
         ;;
+  

Spurious empty line.

It's indeed not strictly related, but in all other cases of this switch, there is an empty line separating cases. So I think it's good to also have this one for consistency. It could have been in a separate commit, but oh well, that was good enough.

Thanks for the review!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#8 lore raw

PATCH 4/4 Package netsnmp: Added OK/FAIL output

Dear Thomas, Yann, all,
thanks for revising the patch series and for incorporating the changes into buildroot.

Regards,
Andreas

Am 01.07.2016 um 15:04 schrieb Thomas Petazzoni:

Quoted 18 lines

Hello,

Quoted 6 lines · Yann E. MORIN

package/netsnmp/S59snmpd case "$1" in · line 101

Quoted 5 lines
package/netsnmp/S59snmpd +1 -0
@@ -92,6 +98,7 @@ case "$1" in
      reload|force-reload)
          reload
          ;;
+

Spurious empty line.

It's indeed not strictly related, but in all other cases of this switch, there is an empty line separating cases. So I think it's good to also have this one for consistency. It could have been in a separate commit, but oh well, that was good enough.

Thanks for the review!

Thomas

#9 lore raw

PATCH 1/4 Package netsnmp: Created start(), stop(), reload().

In reply to Andreas Ehmanns

Andreas, All,

On 2016-02-25 22:24 +0100, Andreas Ehmanns spake thusly:

Quoted 6 lines

Changed 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.

Regards,
Yann E. MORIN.

Quoted 109 lines
---
 package/netsnmp/S59snmpd | 71 +++++++++++++++++++++++++-----------------------
 1 file changed, 37 insertions(+), 34 deletions(-)
package/netsnmp/S59snmpd +37 -34
index 4eea512..cfda625 100755
@@ -38,56 +38,59 @@ if [ "$SNMPDCOMPAT" = "yes" ]; then
   ln -sf /var/agentx/master /var/run/agentx
 fi
 
-case "$1" in
-  start)
+start() {
     printf "Starting network management services:"
     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
     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
     echo "."
-    ;;
-  stop)
+}
+
+stop() {
     printf "Stopping network management services:"
     start-stop-daemon -q -K $ssd_oknodo -x /usr/sbin/snmpd
     printf " snmpd"
     start-stop-daemon -q -K $ssd_oknodo -x /usr/sbin/snmptrapd
     printf " snmptrapd"
     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:"
     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
     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
 
 exit 0
Signature · 6 lines
2.1.4

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#10 lore raw

PATCH 1/4 Package netsnmp: Created start(), stop(), reload().

In reply to Andreas Ehmanns

Hello,

Quoted 9 lines · Andreas Ehmanns

Changed 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.

---
 package/netsnmp/S59snmpd | 71 +++++++++++++++++++++++++-----------------------
 1 file changed, 37 insertions(+), 34 deletions(-)

Entire series applied, after tweaking the commit titles and in some cases the commit log.

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#11 lore raw

PATCH 1/4 Package netsnmp: Created start(), stop(), reload().

Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Thomas" == Thomas Petazzoni <[email protected]> writes:

Hello,

Quoted 5 lines · Andreas Ehmanns

Changed 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.

Quoted 7 lines
Quoted 4 lines

---
package/netsnmp/S59snmpd | 71 +++++++++++++++++++++++++-----------------------

1 file changed, 37 insertions(+), 34 deletions(-)

Entire series applied, after tweaking the commit titles and in some cases the commit log.

For the future, please use your full name in the From: as well (git commit user.name "Andreas Ehmanns"). Now these commits are listed as being from "universe II".

Thanks.

Signature · 1 line
Bye, Peter Korsgaard
#12 lore raw

PATCH 1/4 Package netsnmp: Created start(), stop(), reload().

Hello,

Quoted 3 lines · Peter Korsgaard

For the future, please use your full name in the From: as well (git commit user.name "Andreas Ehmanns"). Now these commits are listed as being from "universe II".

Yeah, also noticed that, but after pushing :-/ The Signed-off-by line is more visible and that one was correct, so I didn't notice.

Sadly, the new pedantic git commit hook checks that the e-mail between the From and the SoB line are matching, but not the name itself.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com