highlight js

2013年9月18日水曜日

AutoScalingでAZ毎に設定変えるshellメモ。

自分用メモ 起動時に、AZ毎用に用意してあるコンフィグをコピって来る感じのshell。
#!/bin/sh
# chkconfig: 2345 99 10
# description: ec2 start setup conf

name='ec2-start-setup'

case "$1" in
 start)
    ;;
 stop)
       ;;
  *) break ;;
esac

start() {
    echo -n "Starting $name: "

    ipaddr=`LANG=C /sbin/ifconfig | grep 'inet addr' | grep -v 127.0.0.1 | awk '{print $2;}' | cut -d: -f2`
    echo "$ipaddr"

    zoneip=`echo $ipaddr | cut -d "." -f 1-3`
    #zoneip='10.0.1'
    echo "$zoneip"

    if test "$zoneip" = '10.0.0' ; then
     echo "case AZ-A"

     `cp hogehoge-az-a hogehoge`
     null=`restart しちゃったりとか`

    else
     echo "case AZ-C"

     `cp hogehoge-az-c hogehoge`
     null=`restart しちゃったりとか`
    fi
}

stop() {
    echo -n "none "
}

case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    *)
    echo "Usage: $prog {start|stop}"
    exit 1
    ;;
esac
exit $?