Author: justi9
Date: 2010-05-11 16:42:38 -0400 (Tue, 11 May 2010)
New Revision: 3962
Modified:
mgmt/newdata/cumin/bin/cumin-database
mgmt/newdata/cumin/etc/sysvinit-cumin
Log:
Add a cumin-database install function that just does everything; make the init script
check that the database is installed
Modified: mgmt/newdata/cumin/bin/cumin-database
===================================================================
--- mgmt/newdata/cumin/bin/cumin-database 2010-05-11 14:39:05 UTC (rev 3961)
+++ mgmt/newdata/cumin/bin/cumin-database 2010-05-11 20:42:38 UTC (rev 3962)
@@ -5,147 +5,287 @@
exit 2
fi
+# A workaround for running this script from the devel environment
+
+if [[ -d cumin && -f etc/devel.profile ]]; then
+ source etc/devel.profile &> /dev/null
+fi
+
pgdata="/var/lib/pgsql/data"
pglog="${pgdata}/pg_log"
pghbaconf="${pgdata}/pg_hba.conf"
dbname="cumin"
+function format-output {
+ while read line; do
+ echo " | $line"
+ done
+}
+
+function run {
+ echo " | \$ $1"
+
+ if [[ "$2" ]]; then
+ su - postgres -c "$1" | format-output 2>&1
+ else
+ $1 | format-output 2>&1
+ fi
+
+ return ${PIPESTATUS[0]}
+}
+
function check-environment {
which rpm > /dev/null
- rpm -q postgresql-server > /dev/null
+
+ rpm -q postgresql-server &> /dev/null || {
+ echo "Error: postgresql-server is not installed"
+ echo "Hint: Run 'yum install postgresql-server'"
+ return 1
+ }
}
-function check-server {
- # Is it installed?
- # Is it initialized?
- # Is it running?
-
- test -d "$pgdata" || {
- echo "The database is not configured. Run 'cumin-database
configure'."
- exit 1
+function check-started {
+ /sbin/service postgresql status &> /dev/null || {
+ echo "Error: The database is not running"
+ echo "Hint: Run 'cumin-database start'"
+ return 1
}
+}
- /sbin/service postgresql status > /dev/null || {
- echo "The database is not running. Run 'cumin-database
start'."
- exit 1
+function check-initialized {
+ if [[ ! -d "$pgdata" ]]; then
+ echo "Error: The database is not initialized"
+ echo "Hint: Run 'cumin-database initialize'"
+ return 1
+ fi
+}
+
+function check-configured {
+ grep "$dbname" "$pghbaconf" &> /dev/null || {
+ echo "Error: The database is not configured"
+ echo "Hint: Run 'cumin-database configure'"
+ return 1
}
}
-function check-access {
+function check-created {
psql -d cumin -U cumin -h localhost -c '\q' &> /dev/null || {
- echo "The database is not accessible. Run 'cumin-database
create'"
- exit 1
+ echo "Error: The database is not created"
+ echo "Hint: Run 'cumin-database create'"
+ return 1
}
}
-function format-output {
- while read line; do
- echo " | $line"
+function confirm-install {
+ cat <<EOF
+WARNING
+
+This script installs a cumin database into the system postgresql
+instance.
+
+ * It will stop and start the postgresql service.
+
+ * It will initialize the postgresql database cluster if it isn't
+ already initialized.
+
+ * It will alter postgresql configuration files.
+
+If you already have a custom-configured postgresql install, you may
+not want to proceed.
+
+If there are clients that depend on the running postgresql service,
+you probably don't want to proceed.
+
+If, however, none of these changes affect your existing deployment, it
+is safe to proceed.
+
+Enter 'yes' to proceed or Ctrl-C to cancel:
+EOF
+ while read word; do
+ if [[ "$word" == "yes" ]]; then
+ break
+ fi
+
+ echo "Enter 'yes' to proceed or Ctrl-C to cancel:"
done
+
+ install
}
-function run {
- echo " | \$ $1"
+function install {
+ check-environment || exit 1
- if [[ "$2" ]]; then
- su - postgres -c "$1" | format-output 2>&1
- else
- $1 | format-output 2>&1
- fi
+ check-initialized &> /dev/null || initialize
- return ${PIPESTATUS[0]}
+ check-configured &> /dev/null || configure
+
+ check-started &> /dev/null || start > /dev/null
+
+ check-created &> /dev/null || create
}
-case "$1" in
- start)
- run "/sbin/service postgresql start"
- echo "The database server is started."
- ;;
- stop)
- run "/sbin/service postgresql stop"
- echo "The database server is stopped."
- ;;
- configure)
- check-environment
+function start {
+ check-environment || exit 1
+ check-initialized || exit 1
- if grep ${dbname} ${pghbaconf} &> /dev/null; then
- echo "The database server appears to have been configured
already."
- exit 1
- fi
+ /sbin/service postgresql start
+}
- if /sbin/service postgresql status > /dev/null; then
- echo "The database server is running. To proceed with"
- echo "configuration, it must be stopped."
- exit 1
- fi
+function stop {
+ check-environment || exit 1
+ check-initialized || exit 1
- if [[ ! -d "$pgdata" ]]; then
- run "initdb --pgdata='$pgdata' --auth='ident
sameuser'" postgres
- run "mkdir '$pglog'" postgres
- run "chmod 700 '$pglog'" postgres
+ /sbin/service postgresql stop
+}
- /sbin/restorecon -R "$pgdata"
- fi
+function initialize {
+ check-environment || exit 1
+
+ if check-initialized &> /dev/null; then
+ echo "Error: The database server is already initialized"
+ exit 1
+ fi
- python <<EOF
+ if check-started &> /dev/null; then
+ echo "Error: The database server is running"
+ echo "Hint: Run 'cumin-database stop'"
+ exit 1
+ fi
+
+ run "initdb --pgdata='$pgdata' --auth='ident sameuser'"
postgres
+ run "mkdir '$pglog'" postgres
+ run "chmod 700 '$pglog'" postgres
+
+ /sbin/restorecon -R "$pgdata"
+}
+
+function configure {
+ check-environment || exit 1
+ check-initialized || exit 1
+
+ if check-configured &> /dev/null; then
+ echo "Error: The database server is already configured"
+ exit 1
+ fi
+
+ python <<EOF
from cumin.database import modify_pghba_conf
modify_pghba_conf('${pghbaconf}', '${dbname}', 'cumin')
EOF
+}
- echo "The database server is configured."
- ;;
- check)
- echo -n "Checking environment ... "
- check-environment && echo "OK"
+function create {
+ check-environment || exit 1
+ check-started || exit 1
+ check-configured || exit 1
- echo -n "Checking server ........ "
- check-server && echo "OK"
+ if check-created &> /dev/null; then
+ echo "Error: The database is already created"
+ exit 1
+ fi
- echo -n "Checking access ........ "
- check-access && echo "OK"
+ run "createuser --superuser ${dbname}" postgres
+ run "createdb --owner=${dbname} ${dbname}" postgres
- # check-data
+ cumin-admin create-schema > /dev/null
+ # cumin-admin add-role user
+ # cumin-admin add-role admin
+}
- echo "The database is ready."
- ;;
- create)
- check-environment
- check-server
+function drop {
+ check-environment || exit 1
+ check-started || exit 1
- run "createuser --superuser ${dbname}" postgres
- run "createdb --owner=${dbname} ${dbname}" postgres
+ run "dropdb ${dbname}" postgres
+ run "dropuser ${dbname}" postgres
+}
- check-access
+function confirm-annihilate {
+ check-environment || exit 1
- run "cumin-admin create-schema"
- # run "cumin-admin add-role user"
- # run "cumin-admin add-role admin"
+ echo "Really?"
- echo "The database is initialized."
- ;;
- drop)
- check-environment
- check-server
+ while read line; do
+ if [[ "$line" == "really" ]]; then
+ break
+ fi
- run "dropdb ${dbname}" postgres
- run "dropuser ${dbname}" postgres
+ echo "Not good enough"
+ done
- echo "The database is dropped."
+ run "/sbin/service postgresql stop" || :
+ run "rm -rf /var/lib/pgsql/data"
+}
+
+function usage {
+ cat <<EOF
+Control and configure the cumin database
+Usage: cumin-database COMMAND
+Commands:
+ check Check the cumin database
+ install Automated database install
+ start Start the database server
+ stop Stop the database server
+ initialize Create the main database cluster
+ configure Configure the main database cluster
+ create Create the user, database, and schema
+ drop Discard the database user, database, and all data
+EOF
+ exit 1
+}
+
+case "$1" in
+ check)
+ echo -n "Checking environment ........ "
+ check-environment && echo "OK"
+
+ echo -n "Checking initialization ..... "
+ check-initialized && echo "OK"
+
+ echo -n "Checking configuration ...... "
+ check-configured && echo "OK"
+
+ echo -n "Checking server ............. "
+ check-started && echo "OK"
+
+ echo -n "Checking database 'cumin' ... "
+ check-created && echo "OK"
+
+ echo "The database is ready"
;;
+ install)
+ confirm-install
+ echo "The database is installed"
+ ;;
+ start)
+ start
+ echo "The database server is started"
+ ;;
+ stop)
+ stop
+ echo "The database server is stopped"
+ ;;
+ initialize)
+ initialize
+ echo "The database server is initialized"
+ ;;
+ configure)
+ configure
+ echo "The database server is configured"
+ ;;
+ create)
+ create
+ echo "The database is created"
+ ;;
+ drop)
+ drop
+ echo "The database is dropped"
+ ;;
annihilate)
- run "rm -rf /var/lib/pgsql/data"
- echo "Ouch!"
+ confirm-annihilate
+ echo "You devastate me"
;;
*)
- echo "Control and configure the cumin database"
- echo "Usage: cumin-database COMMAND"
- echo "Commands:"
- echo " start Start the database server"
- echo " stop Stop the database server"
- echo " configure Configure the main database cluster"
- echo " check Check the cumin database"
- echo " create Create the user, database, and schema"
- echo " drop Discard the database user, database, and all
data"
- exit 1
+ usage
;;
esac
Modified: mgmt/newdata/cumin/etc/sysvinit-cumin
===================================================================
--- mgmt/newdata/cumin/etc/sysvinit-cumin 2010-05-11 14:39:05 UTC (rev 3961)
+++ mgmt/newdata/cumin/etc/sysvinit-cumin 2010-05-11 20:42:38 UTC (rev 3962)
@@ -8,8 +8,15 @@
#
# Sanity checks.
-[ -x /usr/bin/cumin ] || exit 0
+test -x /usr/bin/cumin || exit 1
+test -x /usr/bin/cumin-database || exit 1
+cumin-database check &> /dev/null || {
+ echo "Cumin's database is not yet installed"
+ echo "Run 'cumin-database install' as root"
+ exit 1
+}
+
# Source function library.
. /etc/rc.d/init.d/functions
@@ -20,7 +27,7 @@
RETVAL=0
start() {
- echo -n $"Starting Cumin daemon: "
+ echo -n $"Starting cumin: "
daemon --user cumin --check $servicename $processname \&
RETVAL=$?
echo
@@ -28,7 +35,7 @@
}
stop() {
- echo -n $"Stopping Cumin daemon: "
+ echo -n $"Stopping cumin: "
killproc $servicename -TERM
RETVAL=$?