From 50d04b7be79e5b047cc4e577caf3d450cc4b0b77 Mon Sep 17 00:00:00 2001 From: "Dickson S. Guedes" Date: Mon, 6 Aug 2012 00:12:59 -0300 Subject: [PATCH] fixing some 'cluster' behavior, refs #4 --- actions/cluster | 51 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/actions/cluster b/actions/cluster index 66abfbe..265aca3 100644 --- a/actions/cluster +++ b/actions/cluster @@ -88,30 +88,36 @@ list() echo -e "cluster in current enviroment ($(current)):\n" + max_length=$(echo $clusters | awk 'BEGIN { RS = " " } ; { print length() }' | sort -n | tail -1) + for cluster in ${clusters} do - echo "$cluster" + printf "%3s %-${max_length}s is %-7s at port %-4s\n" "$is_current" "$cluster" "$(cluster_human_status $cluster)" "$(cluster_port $cluster)" done } start() { + [[ -z "$1" ]] && usage && exit 1 + + echo "starting cluster $1@$(current)" cluster_ctl start $1 } stop() { + [[ -z "$1" ]] && usage && exit 1 + + echo "stopping cluster $1@$(current)" cluster_ctl stop $1 } -cluster_ctl() +status() { - action=$1 - cluster_name=$2 - cluster_top_dir="$pgvm_home/clusters/$(current)" - cluster_dir=${cluster_top_dir}/${cluster_name} + [[ -z "$1" ]] && usage && exit 1 - $pgvm_home/environments/current/bin/pg_ctl -D $cluster_dir $action + echo "checking status of cluster $1@$(current)" + cluster_ctl status $1 } use() @@ -131,3 +137,34 @@ remove() echo -n "removing cluster '$cluster'" } + +cluster_ctl() +{ + action=$1 + cluster_name=$2 + cluster_top_dir="$pgvm_home/clusters/$(current)" + cluster_dir=${cluster_top_dir}/${cluster_name} + + $pgvm_home/environments/current/bin/pg_ctl --silent -w -D $cluster_dir $action || exit 1 +} + +cluster_human_status() +{ + cluster_name=$1 + cluster_top_dir="$pgvm_home/clusters/$(current)" + cluster_dir=${cluster_top_dir}/${cluster_name} + + $pgvm_home/environments/current/bin/pg_ctl -D $cluster_dir status 1>/dev/null 2>/dev/null && echo "online" || echo "offline" +} + +cluster_port() +{ + cluster_name=$1 + cluster_top_dir="$pgvm_home/clusters/$(current)" + cluster_dir=${cluster_top_dir}/${cluster_name} + + cluster_port=$(egrep "^\s*port\s*=" $cluster_dir/postgresql.conf) + [[ -z "$cluster_port" ]] && cluster_port=$(egrep "^#\s*port\s*=" $cluster_dir/postgresql.conf) + + echo $cluster_port | awk '{ printf $3"\n" ;}' | tail -1 +}