Browse Source

Merge branch 'master' of https://gitlab.ut.mephi.ru/ut/ipw

Dmitry Yu Okunev 6 years ago
parent
commit
6810559d4c
1 changed files with 34 additions and 4 deletions
  1. 34 4
      ipw

+ 34 - 4
ipw

@@ -22,6 +22,14 @@ DEFAULT_BONDING_MODE='balance-tlb'
 
 modprobe bonding
 
+if lockfile-check /run/ipw; then
+	eerror 'Another "ipw" instance is already running'
+	exit -1
+fi
+
+trap 'lockfile-remove /run/ipw' SIGINT SIGTERM SIGHUP SIGQUIT SIGALRM SIGILL SIGABRT SIGPIPE EXIT
+lockfile-create /run/ipw || exit
+
 eerror() {
 	echo "$@" >&2
 }
@@ -156,8 +164,16 @@ ip_cmds() {
 
 	ip addr flush dev "$_IFACE"
 	for IP_CMD in "${!IP_CMDS_VARIABLE}"; do
-		[[ "$IP_CMD" != "" ]] &&
-			ip $IP_CMD dev "$_IFACE"
+		if [[ "$IP_CMD" != "" ]]; then
+			WORDS=($IP_CMD)
+			case "${WORDS[0]}" in
+				link)
+					ip $IP_CMD
+					;;
+				*)
+					ip $IP_CMD dev "$_IFACE"
+			esac
+		fi
 	done
 }
 
@@ -331,6 +347,17 @@ case "$CMD" in
 	fix)	#fix all interfaces to config state
 		#brctl addif bond0 eth2
 
+		if [[ "$IPW_DEBUG" -ge "2" ]]; then
+			cat "$IPW_CONFIG_PATH" > /tmp/ipw.conf-fix.$(date +'%Y%m%d%H%M%S')
+		fi
+
+		if [[ "$IPW_CONFIG_PATH" != "/dev/null" ]]; then
+			if [[ "$(cat $IPW_CONFIG_PATH 2>/dev/null)" = "" ]]; then
+				eerror "Empty config file"
+				exit -1
+			fi
+		fi
+
 		#GETTING INFORMATION ABOUT LXC INTERFACES IN BRIDGES
 
 		if [[ "$LXC_DIR" != "" ]]; then
@@ -506,8 +533,11 @@ case "$CMD" in
 
 			# Creating bond-ifaces
 			if [[ "$D1Q_EXISTS" == 0 ]]; then #make all
-				echo "+$D1Q_IFACE" > /sys/class/net/bonding_masters
-				echo "$MODE" > /sys/class/net/"$D1Q_IFACE"/bonding/mode
+				echo "+$D1Q_IFACE" > /sys/class/net/bonding_masters 2>/dev/null
+
+				if [[ -d /sys/class/net/"$D1Q_IFACE"/bonding ]]; then
+					echo "$MODE" > /sys/class/net/"$D1Q_IFACE"/bonding/mode
+				fi
 
 				for SLAVE in "${!SLAVES_VARIABLE}"; do
 					ip link set dev "$SLAVE" down  #enslaved int should be shutted down