Browse Source

Fix network namespace creation

Change-Id: I258b7f78875baf3de6686032b23743d27268d8de
Olivier Bourdon 2 years ago
parent
commit
0e359cb3cb

+ 9
- 0
deployment_scripts/puppet/modules/plugin_zabbix_snmptrapd/files/initscripts/snmpd View File

@@ -60,7 +60,15 @@ TRAPDOPTS="-Lsd -p $TRAPD_PID"
60 60
 test -x $SNMPD_BINARY || exit 0
61 61
 test -x $TRAPD_BINARY || exit 0
62 62
 
63
+create_ns_if_not_exists() {
64
+  [ -n "$1" ] || return 0
65
+  exists=`$IP_BINARY netns | egrep "^$1\$" | wc -l`
66
+  [ $exists -le 0 ] || return 0
67
+  $IP_BINARY netns add "$1"
68
+}
69
+
63 70
 if [ "x$SNMPDNS" != "x" ]; then
71
+  create_ns_if_not_exists "$SNMPDNS"
64 72
   SNMPDOPTS="netns exec $SNMPDNS $SNMPD_BINARY $SNMPDOPTS"
65 73
   SNMPDEXEC=$IP_BINARY
66 74
 else
@@ -68,6 +76,7 @@ else
68 76
 fi
69 77
 
70 78
 if [ "x$TRAPDNS" != "x" ]; then
79
+  create_ns_if_not_exists "$TRAPDNS"
71 80
   TRAPDOPTS="netns exec $TRAPDNS $TRAPD_BINARY $TRAPDOPTS"
72 81
   TRAPDEXEC=$IP_BINARY
73 82
 else

+ 6
- 0
deployment_scripts/puppet/modules/plugin_zabbix_snmptrapd/files/initscripts/snmptrapd View File

@@ -54,6 +54,12 @@ pidfile=/var/run/snmptrapd.pid
54 54
 
55 55
 if [ "x$NS" != "x" ]; then
56 56
   cmd="/sbin/ip netns exec $NS $binary"
57
+  exists=`$IP_BINARY netns | egrep "^$1\$" | wc -l`
58
+  if [ $exists -le 0 ]; then
59
+    /sbin/ip netns add $NS
60
+  fi
61
+}
62
+
57 63
 else
58 64
   cmd=$binary
59 65
 fi

Loading…
Cancel
Save