#!/bin/sh count=1500 pidfile=/var/run/mpd.pid trap 'killall mpd5 >/dev/null 2>&1; exit 1' SIGINT SIGHUP wait_up() { limit=$1 c=`ifconfig | grep '^ng.*UP' | wc -l` prev=$c steady=0 while [ $c -lt $limit ] && [ $steady -lt 5 ] || [ $c -eq 0 ] do sleep 1 c=`ifconfig | grep '^ng.*UP' | wc -l` echo established: $c if [ $prev = $c ]; then steady=$(($steady+1)) else steady=0 fi prev=$c done } clean() { local i ngctl ls | awk '/iface|vjc|tee|ppp / {print $2}' >/tmp/list while read i do ngctl shutdown $i: 2>/dev/null done < /tmp/list } wait_notex() { c=`ngctl list 2>/dev/null | grep -cE 'Name: ng[0-9]'` while [ $c -gt $1 ] do if ps -acx | grep -q mpd; then echo still not destroyed: $c else clean fi c=`ngctl list 2>/dev/null | grep -cE 'Name: ng[0-9]'` sleep 1 done } stop_mpd() { pwait `cat $pidfile 2>/dev/null` 2>/dev/null & killall mpd5 >/dev/null 2>&1 wait_notex 0 killall -QUIT mpd5 2>/dev/null wait clean } echo cleaning... stop_mpd echo generating config... ./generate $count i=1 while : do echo starting $i: `date` was=$(date '+%s') mpd5 -b wait_up $count now=$(date '+%s') echo $(( $count/($now-$was) )) sess/sec\; stopping $i: `date` stop_mpd i=$(($i+1)) done