Author: justi9
Date: 2009-07-22 14:51:08 -0400 (Wed, 22 Jul 2009)
New Revision: 3517
Added:
mgmt/trunk/mint/bin/mint-database
Log:
A new tool for administering mint's postgresql database
Copied: mgmt/trunk/mint/bin/mint-database (from rev 3516,
mgmt/trunk/cumin/bin/cumin-database-destroy)
===================================================================
--- mgmt/trunk/mint/bin/mint-database (rev 0)
+++ mgmt/trunk/mint/bin/mint-database 2009-07-22 18:51:08 UTC (rev 3517)
@@ -0,0 +1,63 @@
+#!/bin/bash -e
+
+if [[ "$EUID" != "0" ]]; then
+ echo "This script must be run as root"
+ exit 2
+fi
+
+function check-basics {
+ # Is it installed?
+ # Is it initialized?
+ # Is it running?
+
+ which rpm > /dev/null
+ rpm -q postgresql-server
+
+ test -d /var/lib/pgsql/data || {
+ echo "The database is not initialized; run '/sbin/service postgresql
start'"
+ exit 1
+ }
+
+ /sbin/service postgresql status || {
+ echo "The database is not running; run '/sbin/service postgresql
start'"
+ exit 1
+ }
+}
+
+case "$1" in
+ check)
+ check-basics
+
+ # Is it configured to be accessible?
+ # Is it accessible?
+ # Does it have a schema loaded?
+
+ su - postgres -c "psql -c '\q'" || {
+ echo "The database is not accessible"
+ exit 1
+ }
+
+ echo "The database is ready"
+ ;;
+ create)
+ check-basics
+ su - postgres -c "createuser --superuser cumin || :"
+ su - postgres -c "createdb --owner=cumin cumin || :"
+ echo "The database is created"
+ ;;
+ destroy)
+ check-basics
+ su - postgres -c "dropdb cumin || :"
+ su - postgres -c "dropuser cumin || :"
+ echo "The database is destroyed"
+ ;;
+ *)
+ echo "Configure and check the mint database"
+ echo "Usage: mint-database COMMAND"
+ echo "Commands:"
+ echo " check Check the database"
+ echo " create Create the mint user and database"
+ echo " destroy Discard the mint user, database, and all data"
+ exit 1
+ ;;
+esac
Show replies by date