-
-
Save l15k4/0c09160d45f178a08f63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
SERVER_CNT_NAME=$1 | |
CLIENT_CNT_NAME=$2 | |
GFS_VOLUME_NAME=$3 | |
COREOS_PRIVATE_IPV4=$4 | |
GLUSTER_NODE_IPS=($(/usr/bin/etcdctl ls /services/glusterfs | xargs -I {} /usr/bin/etcdctl get {} | tr '\n' ' ')) | |
echo "Probing gluster peers at ip addresses ${GLUSTER_NODE_IPS[*]}..." | |
function probePeer { | |
IP=$1 | |
echo "Probing peer $IP ..." | |
/usr/bin/docker exec $SERVER_CNT_NAME gluster peer probe $IP || { | |
echo "Failed to probe peer ${ip}, error status $?" | |
exit 1 | |
} | |
} | |
( for ip in "${GLUSTER_NODE_IPS[@]}"; do probePeer $ip; done ) | |
[[ "$?" -eq 1 ]] && { | |
echo "Cannot probe all ${GLUSTER_NODE_IPS[*]} peers which is probably networking problem !!!" | |
exit 1 | |
} | |
echo "Peers found, checking whether $GFS_VOLUME_NAME volume exists ..." | |
/usr/bin/docker exec $SERVER_CNT_NAME gluster volume info $GFS_VOLUME_NAME || { | |
GLUSTER_BRICK_ADDRESSES=$(/usr/bin/etcdctl ls /services/glusterfs | xargs -I {} /usr/bin/etcdctl get {} | xargs -I {} echo "{}:/media/gfs/${GFS_VOLUME_NAME}" | tr '\n' ' ') | |
echo "Creating volume $GFS_VOLUME_NAME ... using brick addresses $GLUSTER_BRICK_ADDRESSES" | |
/usr/bin/docker exec $SERVER_CNT_NAME gluster volume create $GFS_VOLUME_NAME replica 2 $GLUSTER_BRICK_ADDRESSES force && { | |
/usr/bin/docker exec $SERVER_CNT_NAME gluster volume start $GFS_VOLUME_NAME | |
} | |
} | |
[[ "$?" -eq 0 ]] && { | |
sleep 5 | |
echo "Mounting gfs volume ..." | |
/usr/bin/docker run \ | |
--privileged=true \ | |
--name $CLIENT_CNT_NAME \ | |
-e GLUSTERFS_HOST=$(/usr/bin/etcdctl get /services/glusterfs/${COREOS_PRIVATE_IPV4}) \ | |
-e GFS_VOLUME_NAME=$GFS_VOLUME_NAME \ | |
-v /media/gfs \ | |
gwiq/glusterfs-client | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment