User Mode Linux: скрипт для управления виртуальным свичом

Материал из Linux Wiki
Перейти к навигацииПерейти к поиску
#!/bin/bash
#===============================================================================
#
#          FILE:  switch.sh
# 
#         USAGE:  ./switch.sh start|stop
# 
#   DESCRIPTION:  UML Switch start-stop script
# 
#       OPTIONS:  ---
#  REQUIREMENTS:  uml-utilities
#          BUGS:  no known
#         NOTES:  ---
#        AUTHOR:   rain (linuxiod.rain@gmail.com)
#       COMPANY:  
#       VERSION:  1.0
#       CREATED:  17.09.2007 18:02:48 EEST
#      REVISION:  ---
#===============================================================================

case "$1" in
start)

start_sw () {
if [ ! -z "`/sbin/ifconfig tap0 | grep -o UP`" ]
			then uml_switch -tap tap0 -daemon &
		else	echo "Interface not ready" && exit 1
fi
}

if [ -S /tmp/uml.ctl ]
	then
	if [ -O /tmp/uml.ctl ]
	then
		if [ -z "`fuser /tmp/uml.ctl`" ]
			then start_sw
		else echo "Switch already running"
		fi
	fi
else start_sw
fi
;;

stop)
if [ -S /tmp/uml.ctl ]
then	if [ -O /tmp/uml.ctl ]
		then fuser -k /tmp/uml.ctl
	else echo "Can't stop switch: you are not owner of /tmp/uml.ctl"
	fi
fi
;;

*)
echo "Usage:
./switch.sh start|stop
"
;;
esac