summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2018-03-07 07:03:57 +0100
committerSuren A. Chilingaryan <csa@suren.me>2018-03-07 07:03:57 +0100
commit6bc3a3ac71e11fb6459df715536fec373c123a97 (patch)
treec99a4507012fd853ffa2622e35fa26f3bd3804e3 /scripts
parent69adb23c59e991ddcabf5cfce415fd8b638dbc1a (diff)
downloadands-6bc3a3ac71e11fb6459df715536fec373c123a97.tar.gz
ands-6bc3a3ac71e11fb6459df715536fec373c123a97.tar.bz2
ands-6bc3a3ac71e11fb6459df715536fec373c123a97.tar.xz
ands-6bc3a3ac71e11fb6459df715536fec373c123a97.zip
Streamlined networking, OpenShift recovery, Ganesha
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/gluster.sh85
-rw-r--r--scripts/opts.sh9
2 files changed, 94 insertions, 0 deletions
diff --git a/scripts/gluster.sh b/scripts/gluster.sh
new file mode 100755
index 0000000..02a0a3f
--- /dev/null
+++ b/scripts/gluster.sh
@@ -0,0 +1,85 @@
+#! /bin/bash
+
+. opts.sh
+
+[ $? -ne 0 -o -z "$gpod" ] && { echo "No storage pods are running..." ; exit 1 ; }
+[ -z "$1" ] && { echo "Usage: $0 <info|heal|migrate> <vol|all> [src] [dst]" ; exit 1 ; }
+action=$1
+shift
+
+
+function info {
+ vol=$1
+
+ status=$(gluster volume info databases | grep -P 'Status' | awk '{ print $2 }' | tr -d '\r\n')
+ bricks=$(gluster volume info "$vol" | grep -P 'Number of Bricks' | awk '{ print $NF }' | tr -d '\r\n')
+ avail=$(gluster volume status "$vol" detail | grep Brick | wc -l)
+ online=$(gluster volume status "$vol" detail | grep Online | grep Y | wc -l)
+
+ echo "Volume $vol: $status (Bricks: $bricks, Available: $avail, Online: $online)"
+}
+
+function heal {
+ vol=$1
+
+ distributed=0
+ gluster volume info "$vol" | grep "Type:" | grep -i "Distribute" &> /dev/null
+ [ $? -eq 0 ] && distributed=1
+
+ echo "Healing volume $vol"
+ echo "-------------------"
+ gluster volume heal "$vol" full
+ gluster volume heal "$vol" info
+
+ if [ $distributed -eq 1 ]; then
+ echo "Rebalancing distributed volume $vol"
+ gluster volume rebalance "$vol" fix-layout start
+ fi
+
+
+ gluster volume status "$vol"
+}
+
+function migrate {
+ vol=$1
+ src=$2
+ dst=$3
+
+ [ -z "$src" -o -z "$dst" ] && { echo "Source and destination servers are required" ; exit 1 ; }
+
+ src_brick=$(gluster volume info $vol | grep -P '^Brick\d+:' | awk '{ print $2 }' | grep -P "^$src" | tr -d '\r\n' )
+ dst_brick=${src_brick/$src/$dst}
+
+ [ -z "$src_brick" -o -z "$dst_brick" ] && return 0
+
+ echo "Volume $vol: migrating failed brick"
+ echo " from $src_brick"
+ echo " to $dst_brick"
+ echo "Press enter to continue"
+ read
+ [ $? -ne 0 ] && exit
+
+ gluster volume replace-brick $vol "$src_brick" "$dst_brick" commit force
+ heal $vol
+}
+
+
+
+#
+# heal $1
+
+
+if [ -n "$1" -a "$1" != "all" ]; then
+ eval "$action" "$@"
+else
+ [ "$1" == "all" ] && shift
+
+ vols=$(gluster volume info | grep -P '^Volume Name' | awk '{ print $NF }' | tr '\r\n' ' ')
+ for vol in $vols; do
+ [[ "$vol" =~ [0-9] ]] && continue
+ [[ "$vol" =~ ^vol_ ]] && continue
+ [[ "$vol" =~ ^heketi ]] && continue
+
+ eval "$action" "$vol" "$@"
+ done
+fi
diff --git a/scripts/opts.sh b/scripts/opts.sh
new file mode 100644
index 0000000..d484efc
--- /dev/null
+++ b/scripts/opts.sh
@@ -0,0 +1,9 @@
+function get_gluster_pod {
+ oc -n glusterfs get pods -l 'glusterfs=storage-pod' | grep Running | awk '{ print $1 }' | head -n 1
+}
+
+gpod=$(get_gluster_pod)
+
+function gluster {
+ oc -n glusterfs rsh po/$gpod gluster "$@"
+}