etcd

etcd 0.5.0-alpha.4版本中

先用普通方式启用一边。
/bin/etcd -initial-advertise-peer-urls http://your_ip:7001 -advertise-client-urls http://your_ip:4001 -listen-peer-urls http://0.0.0.0:7001 -listen-client-urls http://0.0.0.0:4001 &

 

 

#!/bin/bash  
  
if [ -z $1 ]; then  
        echo "Usage: c run <image name>:<version>"  
        echo "       c stop <container name>"  
        exit 1  
fi  
  
if [ -z $ETCD_HOST ]; then  
  ETCD_HOST="10.250.0.186:4001"  
fi  
  
if [ -z $ETCD_PREFIX ]; then  
  ETCD_PREFIX="app/servers"  
fi  
  
if [ -z $CPORT ]; then  
  CPORT="8069"  
fi  
  
if [ -z $FORREST_IP ]; then  
  FORREST_IP=`ifconfig eth0| grep "inet addr" | head -1 | cut -d : -f2 | awk '{print $1}'`  
fi  
  
function launch_container {  
        echo "Launching $1 on $FORREST_IP ..."  
  
        CONTAINER_ID=`docker run -d -p :8069 $1`  
        PORT=`docker inspect $CONTAINER_ID|grep "\"Ports\"" -A 50|grep "\"$CPORT/tcp\"" -A 3| grep HostPort|cut -d '"' -f4|head -1`  
        NAME=`docker inspect $CONTAINER_ID | grep Name | cut -d '"' -f4 | sed "s/\///g"|sed -n 2p`  
  
        echo "Announcing to $ETCD_HOST..."  
        curl -XPUT "http://$ETCD_HOST/v2/keys/$ETCD_PREFIX/$NAME" -d value="$FORREST_IP:$PORT"  
  
        echo "$1 running on Port $PORT with name $NAME"  
}  
  
function stop_container {  
        echo "Stopping $1..."  
        CONTAINER_ID=`docker ps -a| grep $1 | awk '{print $1}'`  
        echo "Found container $CONTAINER_ID"  
        docker stop $CONTAINER_ID  
  echo http://$ETCD_HOST/v2/keys/$ETCD_PREFIX/$1  
        curl -XDELETE http://$ETCD_HOST/v2/keys/$ETCD_PREFIX/$1 &> /dev/null  
        echo "Stopped."  
}  
  
  
if [ $1 = "run" ]; then  
  launch_container $2  
else  
  stop_container $2  
fi  

 

posted @ 2014-12-02 20:13  hdu2012  阅读(539)  评论(0编辑  收藏  举报