kvmtool.sh
changeset 22 f10fa2b7fc44
parent 21 9fac1b9871d9
equal deleted inserted replaced
21:9fac1b9871d9 22:f10fa2b7fc44
     4 
     4 
     5 
     5 
     6 ME=${0##*/}
     6 ME=${0##*/}
     7 NODE=$(uname -n)
     7 NODE=$(uname -n)
     8 KVMTAB=/etc/kvmtab
     8 KVMTAB=/etc/kvmtab
     9 KVM_OPTS_BUILTIN='-drive file=/dev/drbd$ID,cache=none,aio=native,if=virtio,index=0,boot=on
     9 KVM_OPTS_BUILTIN='-drive file=/dev/drbd$ID,cache=none,aio=native,if=virtio,index=0
    10 	-boot c
    10 	-boot order=c
    11 	-m 512
    11 	-m 512
    12 	-net nic,macaddr=$MAC,model=virtio
    12 	-net nic,macaddr=$MAC,model=virtio
    13 	-net tap,ifname=tap$ID,script=no' 
    13 	-net tap,ifname=tap$ID,script=no
       
    14 	-k de' 
    14 
    15 
    15 function die() { echo $0: "$@" >&2; exit 1; }
    16 function die() { echo $0: "$@" >&2; exit 1; }
    16 
    17 
    17 function machine() {
    18 function machine() {
    18 
    19 
    64 	stop)
    65 	stop)
    65 	    echo "stopping (k)vm-$NAME"
    66 	    echo "stopping (k)vm-$NAME"
    66 	    echo system_powerdown | nc 0 $MONITOR
    67 	    echo system_powerdown | nc 0 $MONITOR
    67 	    ip link set tap$ID down
    68 	    ip link set tap$ID down
    68 	    brctl delif br0 tap$ID
    69 	    brctl delif br0 tap$ID
       
    70 	    # 'device is held open by someone' :(
       
    71 	    sleep 1
    69 	    echo "switch drbd$ID into secondary role"
    72 	    echo "switch drbd$ID into secondary role"
    70 	    drbdadm secondary drbd$ID
    73 	    drbdadm secondary drbd$ID
    71 	    ;;
    74 	    ;;
    72 	restart)
    75 	restart)
    73 	    $0 stop $NAME
    76 	    $0 stop $NAME
   104 		    ;;
   107 		    ;;
   105     esac
   108     esac
   106 done
   109 done
   107 
   110 
   108 
   111 
   109 # When called as "kvmtool", just try to start
   112 # "kvmtool start" or "kvmtool start all" will try to start
   110 # all the vm's we find in /etc/kvmtab, except, there 
   113 # all the vm's we find in /etc/kvmtab; if called "kvmtool start <vm>" it
   111 # are more parameters on the command line
   114 # will try to start the the vm called 'vm'
   112 if [[ "$ME" == *$ME ]]; then
   115 if [[ "$ME" == *$ME ]]; then
   113     cmd="$1"; shift
   116     cmd="$1"; shift
   114 
   117 
   115     if test $# = 0; then
   118     if test $# = 0  || ( test $# = 1 && test $1 = 'all' ); then
   116 	vms=$(egrep "^[[:alnum:]_-]+[[:space:]]+$NODE\b" $KVMTAB | tr -s '\t ' ' ' | cut -f1 -d' ')
   119 	vms=$(egrep "^[[:alnum:]_-]+[[:space:]]+$NODE\b" $KVMTAB | tr -s '\t ' ' ' | cut -f1 -d' ')
   117     else
   120     else
   118 	vms="$@"
   121 	vms="$@"
   119     fi
   122     fi
   120 fi
   123 fi
   141     kvmtool-MACHINE {start|stop|restart}
   144     kvmtool-MACHINE {start|stop|restart}
   142 
   145 
   143 =head1 DESCRIPTION
   146 =head1 DESCRIPTION
   144 
   147 
   145 This small tool helps to start the virtual machines known in F</etc/kvmtab>.
   148 This small tool helps to start the virtual machines known in F</etc/kvmtab>.
   146 If just called as C<kvmtool start> it starts all machines that should run on the 
   149 If just called as C<kvmtool start> or C<kvmtool start all> it starts all
   147 current host. If called as C<kvmtool start xxx>, it tries to start machine C<xxx>, but
   150 machines that should run on the current host. If called as C<kvmtool start
   148 this may fail, if the F<kvmtab> lists this machine for another host.
   151 xxx>, it tries to start machine C<xxx>, but this may fail, if the F<kvmtab>
       
   152 lists this machine for another host.
   149 
   153 
   150 =head1 OPTIONS
   154 =head1 OPTIONS
   151 
   155 
   152 Currently there are no options at all. The only exceptions are B<-h>|B<--help>
   156 Currently there are no options at all. The only exceptions are B<-h>|B<--help>
   153 and B<-m>|B<--man>.
   157 and B<-m>|B<--man>.