Skip to content

Commit

Permalink
Add Postgresql Service to permit Stop/Start/Restart Action
Browse files Browse the repository at this point in the history
Improve DropDB by restart Postgresql Clusters
  • Loading branch information
slardiere committed Oct 5, 2011
1 parent a17b19e commit 68c6444
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion staging-client.sh
Expand Up @@ -40,7 +40,14 @@ function dropdb() {
if [ $? -ne 0 ]; then
outcode=1
fi

nbsession=`psql -U postgres -At -c "select count( * ) from pg_stat_activity where datname='${dbname}'"`
if [ "$outcode" -ne 0 ] || [ "$nbsession" -ne 0 ]; then
service stop postgresql
sleep 2
service start postgresql
sleep 5
fi

# Drop Database
psql -U postgres -c "drop database $dbname ; " > /dev/null 2>&1
if [ $? -ne 0 ]; then
Expand Down Expand Up @@ -137,6 +144,22 @@ function service() {
esac
;;

"postgresql")
OIFS=$IFS
IFS="$(echo -e "\n\r")"
for cluster in `pg_lsclusters -h|awk '{print $1 " " $2}'`
do
IFS=" " read -r version name <<< "$cluster"
if [ "$action" = "stop" ]; then
switch="--force"
else
switch=""
fi
/usr/bin/pg_ctlcluster $version $name $action $switch
done
IFS=$OIFS
;;

*)
echo "Unknown service to restart: $service" >&2
$(exit 3)
Expand Down

0 comments on commit 68c6444

Please sign in to comment.