Skip to content

Commit

Permalink
added --all option to 'cluster list' to list all cluster for all envi…
Browse files Browse the repository at this point in the history
…ronments. refs guedes#4
  • Loading branch information
fabriziomello committed Sep 23, 2012
1 parent 06dda6b commit 2af5c7a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 21 deletions.
53 changes: 40 additions & 13 deletions actions/cluster
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Usage: pgvm cluster <action> <args>
create Creates a new cluster (PGDATA)
remove Removes a cluster
rename Renames a cluster
list List all clusters
list List all clusters of current environment
list --all List all clusters of all environments
import Import a cluster from tarball
export Export a cluster to tarball
Expand Down Expand Up @@ -82,18 +83,40 @@ create()

list()
{
cluster_top_dir="$pgvm_home/clusters/$(current)"
clusters=$(find ${cluster_top_dir}/* -maxdepth 0 -type d -exec basename {} \; 2> /dev/null)

[[ -z "$clusters" ]] && echo "there is no clusters in current environment ($(current))" && exit 1
cluster_top_dir="$pgvm_home/clusters"
current_version=$(current)

if [ "$current_version" == "Please, install a PostgreSQL Version!" ]
then
echo $current_version
exit 1
fi

if [ "$1x" == "--allx" ]
then
versions=$(find ${cluster_top_dir}/* -maxdepth 0 -type d)
if [ "$versions" == "" ]
then
echo "there is no created clusters"
exit 1
fi
else
versions="$cluster_top_dir/$(current)"
fi

for top_dir in ${versions}
do
clusters=$(find ${top_dir}/* -maxdepth 0 -type d -exec basename {} \; 2> /dev/null)
cluster_version=$(basename $top_dir)

echo -e "cluster in current enviroment ($(current)):\n"
[[ -z "$clusters" ]] && echo "there is no clusters in current environment (${cluster_version})" && exit 1

max_length=$(echo $clusters | awk 'BEGIN { RS = " " } ; { print length() }' | sort -n | tail -1)
max_length=$(echo $clusters | awk 'BEGIN { RS = " " } ; { print length() }' | sort -n | tail -1)

for cluster in ${clusters}
do
printf "%3s %-${max_length}s is %-7s at port %-4s\n" "$is_current" "$cluster" "$(cluster_human_status $cluster)" "$(cluster_port $cluster)"
for cluster in ${clusters}
do
printf "%3s %-6s %-${max_length}s is %-7s at port %-4s\n" "$is_current" "$cluster_version" "$cluster" "$(cluster_human_status $cluster $cluster_version)" "$(cluster_port $cluster $cluster_version)"
done
done
}

Expand Down Expand Up @@ -163,16 +186,20 @@ cluster_ctl()
cluster_human_status()
{
cluster_name=$1
cluster_top_dir="$pgvm_home/clusters/$(current)"
cluster_version=$2
[[ -z "$cluster_version" ]] && cluster_version=$(current)
cluster_top_dir="$pgvm_home/clusters/$cluster_version"
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"
$pgvm_home/environments/$cluster_version/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_version=$2
[[ -z "$cluster_version" ]] && cluster_version=$(current)
cluster_top_dir="$pgvm_home/clusters/$cluster_version"
cluster_dir=${cluster_top_dir}/${cluster_name}

cluster_port=$(egrep "^\s*port\s*=" $cluster_dir/postgresql.conf)
Expand Down
13 changes: 5 additions & 8 deletions test/pgvm_comment_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ psql --version
#match=/^psql \(PostgreSQL\) 8.4.11$/


## testing clusters in 8,4.11
## testing clusters in 8.4.11

pgvm cluster create test
#status=0
Expand All @@ -113,8 +113,7 @@ pgvm cluster start test

pgvm cluster list
#status=0
#match=/^cluster in current enviroment \(8.4.11\):$/
#match=/^ test is online at port 5433$/
#match=/^ 8.4.11 test is online at port 5433$/

pgvm cluster create latin1_cluster --encoding=latin1 --locale=en_US
#status=0
Expand All @@ -140,8 +139,7 @@ pgvm cluster start my_cluster

pgvm cluster list
#status=0
#match=/^cluster in current enviroment \(9.2.0\):$/
#match=/^ my_cluster is online at port 5435$/
#match=/^ 9.2.0 my_cluster is online at port 5435$/

pgvm cluster create my_another_cluster
#status=0
Expand All @@ -153,9 +151,8 @@ pgvm cluster start my_another_cluster

pgvm cluster list
#status=0
#match=/^cluster in current enviroment \(9.2.0\):$/
#match=/^ my_another_cluster is online at port 5436$/
#match=/^ my_cluster is online at port 5435$/
#match=/^ 9.2.0 my_another_cluster is online at port 5436$/
#match=/^ 9.2.0 my_cluster is online at port 5435$/

## testing stopping cluster

Expand Down

0 comments on commit 2af5c7a

Please sign in to comment.