-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
184 additions
and
113 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
|
||
|
||
print_help() { | ||
echo "Usage: $0 [OPTION]..." | ||
echo "" | ||
echo "Options:" | ||
echo " -w, --work <directory> working directory for gluster bricks" | ||
echo " -v, --volume <gluster volume> gluster volume to create" | ||
echo " -h, --help show this message" | ||
echo "" | ||
} | ||
|
||
# parse options | ||
while [ "${1+isset}" ]; do | ||
case "$1" in | ||
-v|--volume) | ||
GLUSTER_VOLUME=$2 | ||
shift 2 | ||
;; | ||
-w|--work) | ||
WORK_DIR=$2 | ||
shift 2 | ||
;; | ||
-h|--help) | ||
print_help | ||
exit | ||
;; | ||
*) | ||
echo "Error: Unknown option: $1" >&2 | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
if [ -z ${GLUSTER_VOLUME} ] | ||
then | ||
echo "I am error. No volume specified." | ||
echo "" | ||
print_help | ||
exit 1; | ||
fi | ||
|
||
if [ ! -z ${WORK_DIR} ] | ||
then | ||
echo "I am error. No temp directory set." | ||
echo "" | ||
print_help | ||
exit 1; | ||
fi | ||
|
||
NUMBER_OF_BRICKS=3 | ||
|
||
mkdir -p ${WORK_DIR}/rpm | ||
mkdir -p ${WORK_DIR}/bricks | ||
mkdir -p ${WORK_DIR}/blocks | ||
|
||
|
||
|
||
# Grap and extract the RPM | ||
#cd ${WORK_DIR}/rpm | ||
#wget ${GLUSTER_URL} | ||
#rpm2cpio *.rpm | cpio -idmv | ||
|
||
#create some loopback bricks | ||
|
||
createGlusterVolume(){ | ||
LOOP_BRICKS=( ) | ||
|
||
# TODO: Need to run a force on this command so it doesn't prompt | ||
|
||
GLUSTER_VOLUME_CMD="gluster volume create ${GLUSTER_VOLUME} " | ||
HOSTNAME=`hostname` | ||
|
||
for (( i = 0 ; i <= ${NUMBER_OF_BRICKS}; i++ )) | ||
do | ||
# Create an empty block device to use as loop back filesystem | ||
BLOCK=${WORK_DIR}/blocks/block${i} | ||
BRICK=${WORK_DIR}/bricks/brick${i} | ||
|
||
dd if=/dev/zero of=${BLOCK} bs=1024 count=30720 | ||
|
||
# find a free loopback device | ||
# LOOP_BRICKS[${i}]=${WORK_DIR}/bricks/brick${i} | ||
LB_BRICK=`losetup -f` | ||
LOOP_BRICKS[${i}]="${LB_BRICK}" | ||
|
||
|
||
echo "creating loopback file system on loopback: ${LB_BRICK} block: ${BLOCK}" | ||
losetup ${LB_BRICK} ${BLOCK} | ||
echo "Making loopback block brick on ${LB_BRICK}" | ||
# mkfs.xfs -m 1 -v ${BLOCK} | ||
mkfs -t ext4 -m 1 -v ${LB_BRICK} | ||
|
||
|
||
mkdir -p ${BRICK} | ||
mount -t ext4 $LB_BRICK $BRICK | ||
GLUSTER_VOLUME_CMD="${GLUSTER_VOLUME_CMD} ${HOSTNAME}:${BRICK}" | ||
done | ||
|
||
# Run the gluster command to create the volume | ||
|
||
|
||
echo "running: ${GLUSTER_VOLUME_CMD}" | ||
$GLUSTER_VOLUME_CMD | ||
gluster volume start ${GLUSTER_VOLUME} | ||
} | ||
|
||
createCleanupScript(){ | ||
# clean up after ourselfs | ||
# create an unmount script for the bricks | ||
echo "#!/bin/sh" > ${WORK_DIR}/cleanup.sh | ||
chmod +x ${WORK_DIR}/cleanup.sh | ||
|
||
echo "gluster volume stop ${GLUSTER_VOLUME}" >> ${WORK_DIR}/cleanup.sh | ||
echo "gluster volume delete ${GLUSTER_VOLUME}" >> ${WORK_DIR}/cleanup.sh | ||
# Unmount the bricks and loopback devices | ||
|
||
for (( i = 0 ; i <= ${NUMBER_OF_BRICKS}; i++ )) | ||
do | ||
# Create an empty block device to use as loop back filesystem | ||
BLOCK=${WORK_DIR}/blocks/block${i} | ||
BRICK=${WORK_DIR}/bricks/brick${i} | ||
echo "umount $BRICK" >> ${WORK_DIR}/cleanup.sh | ||
echo "losetup -d ${LOOP_BRICKS[$i]}" >> ${WORK_DIR}/cleanup.sh | ||
echo "rm -rf $BLOCK" >> ${WORK_DIR}/cleanup.sh | ||
echo "rm -rf $BRICK" >> ${WORK_DIR}/cleanup.sh | ||
|
||
done | ||
|
||
echo "rm -rf ${WORK_DIR}" >> ${WORK_DIR}/cleanup.sh | ||
} | ||
|
||
createGlusterVolume | ||
createCleanupScript | ||
echo "Cleanup script: ${WORK_DIR}/cleanup.sh" |
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
This file was deleted.
Oops, something went wrong.