Skip to content

Commit

Permalink
fixing some 'cluster' behavior, refs #4
Browse files Browse the repository at this point in the history
  • Loading branch information
guedes committed Aug 6, 2012
1 parent 1c9df18 commit 50d04b7
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions actions/cluster
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}

0 comments on commit 50d04b7

Please sign in to comment.