diff --git a/etc/dm.fsService.log.conf b/etc/dm.fsService.log.conf new file mode 100644 index 0000000000000000000000000000000000000000..7d8355d18053837af5ade03ef3aa677772af2878 --- /dev/null +++ b/etc/dm.fsService.log.conf @@ -0,0 +1,45 @@ +# Logging Configuration File +# +# +# Available sections: +# [LoggerLevels] : lists regular levelregex to match against loggers. +# [ConsoleLogging] : configures logging onto screen +# [FileLogging] : configures logging into local file + +# The root key describes the root +# logger level which is the default level for all loggers. + +# Level regular expressions (levelregex) are matched top down with the first +# match setting the effective level. If no matches are found, default applies. + +# Available logger levels: debug, info, warn, error, critical + +# In order for a message to be emitted by a specific handler the level of +# the message must be greater than or equal to both the logger level and +# the handler level. +# + +# Example: Debug level for DbManager, info for everything else +# +# [LoggerLevels] +# levelregex: ^.*$=info +# ^DbManager$=debug +# + +[LoggerLevels] +root=error +levelregex: ^.*$=debug + +#[ConsoleLogging] +#handler=ConsoleLoggingHandler(sys.stdout,) +#level=debug +#format=%(asctime)s,%(msecs)003d %(levelname)s %(filename)s:%(lineno)d %(process)d: %(message)s +#dateformat=%Y-%m-%d %H:%M:%S + +# Custom log files can be setup here using config section [FileLogging<name>] +[FileLogging] +handler=TimedRotatingFileLoggingHandler('/home/sveseli/Work/DM/dev/var/log/dm.fsService.log') +level=debug +format=%(asctime)s,%(msecs)003d %(levelname)s %(filename)s:%(lineno)d %(process)d: %(message)s +dateformat=%Y-%m-%d %H:%M:%S + diff --git a/etc/dm.log.conf b/etc/dm.log.conf new file mode 100644 index 0000000000000000000000000000000000000000..190a06810ae7fc71cd4338a949c1df27b3f3c8da --- /dev/null +++ b/etc/dm.log.conf @@ -0,0 +1,45 @@ +# Logging Configuration File +# +# +# Available sections: +# [LoggerLevels] : lists regular levelregex to match against loggers. +# [ConsoleLogging] : configures logging onto screen +# [FileLogging] : configures logging into local file + +# The root key describes the root +# logger level which is the default level for all loggers. + +# Level regular expressions (levelregex) are matched top down with the first +# match setting the effective level. If no matches are found, default applies. + +# Available logger levels: debug, info, warn, error, critical + +# In order for a message to be emitted by a specific handler the level of +# the message must be greater than or equal to both the logger level and +# the handler level. +# + +# Example: Debug level for DbManager, info for everything else +# +# [LoggerLevels] +# levelregex: ^.*$=info +# ^DbManager$=debug +# + +[LoggerLevels] +root=error +levelregex: ^.*$=debug + +[ConsoleLogging] +handler=ConsoleLoggingHandler(sys.stdout,) +level=debug +format=%(asctime)s,%(msecs)003d %(levelname)s %(filename)s:%(lineno)d %(process)d: %(message)s +dateformat=%Y-%m-%d %H:%M:%S + +# Custom log files can be setup here using config section [FileLogging<name>] +[FileLogging] +handler=TimedRotatingFileLoggingHandler('/home/sveseli/Work/DM/dev/var/log/dm.log') +level=debug +format=%(asctime)s,%(msecs)003d %(levelname)s %(filename)s:%(lineno)d %(process)d: %(message)s +dateformat=%Y-%m-%d %H:%M:%S + diff --git a/etc/init.d/dm-fs-service b/etc/init.d/dm-fs-service new file mode 100755 index 0000000000000000000000000000000000000000..980a88501a338352bf854cc5f9f280494686c7b5 --- /dev/null +++ b/etc/init.d/dm-fs-service @@ -0,0 +1,139 @@ +#!/bin/sh + +# +# dm-fs-service +# +# Starts the DM FileSystem Service +# +# chkconfig: 345 98 98 +# description: controls DM FileSystem Service + +### BEGIN INIT INFO +# Provides: dm-fs-service +# Required-Start: $local_fs dm-postgresql +# Required-Stop: $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: controls DM FileSystem Service +### END INIT INFO + +# Source function library. +. /etc/rc.d/init.d/functions + +# For SELinux we need to use 'runuser' not 'su' +SU=su +if [ -x /sbin/runuser ]; then + SU=runuser +fi + +# Check if we are root before running command +runCommand() { + _cmd="$@" + echo "COMMAND: $_cmd" + if [ `id -u` = 0 ]; then + $SU -l $DM_USER -c "_$cmd" + else + eval "$_cmd" + fi +} + +# Set defaults for configuration variables +if [ -z $DM_ROOT_DIR ]; then + myDir=`dirname $0` + currentDir=`pwd` && cd $myDir/../.. + export DM_ROOT_DIR=`pwd` + cd $currentDir +fi +DM_SETUP_FILE=$DM_ROOT_DIR/setup.sh +if [ ! -f $DM_SETUP_FILE ]; then + echo "Setup file $DM_SETUP_FILE does not exist." + exit 2 +fi +. $DM_SETUP_FILE > /dev/null + +mkdir -p ${DM_ROOT_DIR}/var/run +mkdir -p ${DM_ROOT_DIR}/var/log + +#DM_USER=dm +DM_USER=`whoami` +DM_PORT=22236 # 222-DM +DM_HOST=0.0.0.0 +DAEMON_CMD=${DM_ROOT_DIR}/lib/python/dm/fs_service/service/fsService.py +DAEMON_NAME="DmFsService" +PIDFILE=${DM_ROOT_DIR}/var/run/dm_fs_service.pid +DAEMON_ARGS="-d -p $PIDFILE --port $DM_PORT --host $DM_HOST --n-server-threads 12" +export DM_LOG_CONFIG_FILE=${DM_ROOT_DIR}/etc/dm.fsService.log.conf + +# Determine SSL flags: +# DM_SERVICE_PROTOCOL=https +# DM_SERVICE_SSL_CERT_FILE=<cert path> +# DM_SERVICE_SSL_KEY_FILE=<key path> +# DM_SSL_CA_CERT_FILE=<ca cert path> (enables checking client certificates) + +if [ "$DM_SERVICE_PROTOCOL" = "https" ]; then + if [ -z "$DM_SERVICE_SSL_CERT_FILE" ]; then + echo "Cannot start service using SSL: DM_SERVICE_SSL_CERT_FILE is not defined." && exit 2 + fi + if [ -z "$DM_SERVICE_SSL_KEY_FILE" ]; then + echo "Cannot start service using SSL: DM_SERVICE_SSL_KEY_FILE is not defined." && exit 2 + fi + DAEMON_ARGS="$DAEMON_ARGS -c $DM_SERVICE_SSL_CERT_FILE -k $DM_SERVICE_SSL_KEY_FILE" + + # Client certificate will be checked if DM_SSL_CA_CERT_FILE is provided. + if [ ! -z "$DM_SSL_CA_CERT_FILE" ]; then + DAEMON_ARGS="$DAEMON_ARGS -C $DM_SSL_CA_CERT_FILE" + fi +fi + +RETVAL=0 +start() { + # Check if service is already running + status -p $PIDFILE > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo -n $"Starting $DAEMON_NAME daemon: " + runCommand ${DAEMON_CMD} ${DAEMON_ARGS} + RETVAL=$? + [ $RETVAL -eq 0 ] && success $"$DAEMON_NAME startup" || failure $"$DAEMON_NAME startup" + echo + fi + return $RETVAL +} + +stop() { + status -p $PIDFILE > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo -n $"Stopping $DAEMON_NAME daemon: " + PID=`cat $PIDFILE` + kill $PID + RETVAL=$? + [ $RETVAL -eq 0 ] && rm -f $PIDFILE && success $"$DAEMON_NAME shutdown" || failure $"$DAEMON_NAME shutdown" + echo + fi + return $RETVAL +} + +restart() { + stop + start +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + restart + ;; + status) + status -p $PIDFILE "$DAEMON_NAME" + RETVAL=$? + ;; + *) + echo $"Usage: $0 {start|stop|status|restart}" + RETVAL=2 +esac + +exit $RETVAL diff --git a/etc/init.d/dm-postgresql b/etc/init.d/dm-postgresql new file mode 100755 index 0000000000000000000000000000000000000000..ee883962488a603061b95ada81a2649b85363c9a --- /dev/null +++ b/etc/init.d/dm-postgresql @@ -0,0 +1,263 @@ +#!/bin/sh + +# +# dm-postgresql +# +# Starts the PostgreSQL server used for DM software +# +# Modified from the original RHEL postgresql init.d script +# +# chkconfig: 345 97 97 +# description: controls Dm database server + +### BEGIN INIT INFO +# Provides: dm-postgresql +# Required-Start: $local_fs +# Required-Stop: $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: controls Dm database server +### END INIT INFO + +# PGVERSION is the full package version, e.g., 8.4.0 +PGVERSION=9.3.4 +# PGMAJORVERSION is major version, e.g., 8.4 (this should match PG_VERSION) +PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'` + +# Source function library. +. /etc/rc.d/init.d/functions + +# Get function listing for cross-distribution logic. +TYPESET=`typeset -f|grep "declare"` + +# Get config. +. /etc/sysconfig/network + +# Find the name of the script +# NAME=`basename $0` +NAME="DM Database" + +# For SELinux we need to use 'runuser' not 'su' +SU=su +if [ -x /sbin/runuser ]; then + SU=runuser +fi + +# Check if we are root before running command +runCommand() { + _cmd="$@" + if [ `id -u` = 0 ]; then + $SU -l $PGUSER -c "_$cmd" >> $PGSTARTUPLOG 2>&1 < /dev/null + else + eval "$_cmd" >> $PGSTARTUPLOG 2>&1 < /dev/null + fi +} + + +# Set defaults for configuration variables +if [ -z $DM_ROOT_DIR ]; then + myDir=`dirname $0` + currentDir=`pwd` && cd $myDir/../.. + export DM_ROOT_DIR=`pwd` + cd $currentDir +fi +DM_SETUP_FILE=$DM_ROOT_DIR/setup.sh +if [ ! -f $DM_SETUP_FILE ]; then + echo "Setup file $DM_SETUP_FILE does not exist." + exit 2 +fi +. $DM_SETUP_FILE > /dev/null + +PGROOT=$DM_SUPPORT_DIR/postgresql/$DM_HOST_ARCH +PGENGINE=$PGROOT/bin +#PGUSER=dm +PGUSER=`whoami` +PGPORT=11136 # 111-DM +PGDATA=$PGROOT/data + +PGRUNDIR=$DM_ROOT_DIR/var/run +PGLOGDIR=$DM_ROOT_DIR/var/log + +PGSTARTUPLOG=$PGLOGDIR/postgresql +PGPIDFILE=$PGRUNDIR/postmaster.pid +PGLOCKFILE=$PGRUNDIR/postmaster.lock + +mkdir -p $PGDATA && chown -R $PGUSER:$PGUSER $PGDATA +mkdir -p $PGRUNDIR && chown -R $PGUSER:$PGUSER $PGRUNDIR +mkdir -p $PGLOGDIR && chown -R $PGUSER:$PGUSER $PGLOGDIR + +export PGDATA +export PGPORT +export LD_LIBRARY_PATH=$PGROOT/lib + +# Check that networking is up. +# Pretty much need it for postmaster. +[ "${NETWORKING}" = "no" ] && exit 1 + +[ -f "$PGENGINE/postmaster" ] || exit 1 + +script_result=0 + +start() { + PSQL_START=$"Starting ${NAME} service: " + + # Make sure startup-time log file is valid + if [ ! -e "$PGSTARTUPLOG" -a ! -h "$PGSTARTUPLOG" ]; then + touch "$PGSTARTUPLOG" || exit 1 + chown $PGUSER:$PGUSER "$PGSTARTUPLOG" + chmod go-rwx "$PGSTARTUPLOG" + [ -x /sbin/restorecon ] && /sbin/restorecon "$PGSTARTUPLOG" + fi + + # Check for the PGDATA structure + if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]; then + # Check version of existing PGDATA + if [ x`cat "$PGDATA/PG_VERSION"` != x"$PGMAJORVERSION" ]; then + SYSDOCDIR="(Your System's documentation directory)" + echo + echo $"An old version of the database format was found." + echo $"You need to upgrade the data format before using PostgreSQL." + echo $"See $SYSDOCDIR/postgresql-$PGVERSION/README.rpm-dist for more information." + exit 1 + fi + + # No existing PGDATA! Warn the user to initdb it. + else + echo + echo "$PGDATA is missing. Use \"$0 initdb\" to initialize the cluster first." + echo_failure + echo + exit 1 + fi + + echo -n "$PSQL_START" + cmd="$PGENGINE/postmaster -p '$PGPORT' -D '$PGDATA' ${PGOPTS} &" + runCommand $cmd + sleep 2 + pid=`pidof -s "$PGENGINE/postmaster"` + if [ $pid ] && [ -f "$PGDATA/postmaster.pid" ]; then + success "$PSQL_START" + touch $PGLOCKFILE + head -n 1 "$PGDATA/postmaster.pid" > $PGPIDFILE + echo + else + failure "$PSQL_START" + echo + script_result=1 + fi +} + +stop() { + echo -n $"Stopping ${NAME} service: " + cmd="export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; $PGENGINE/pg_ctl stop -D '$PGDATA' -s -m fast" + runCommand $cmd + ret=$? + if [ $ret -eq 0 ]; then + echo_success + else + echo_failure + script_result=1 + fi + echo + rm -f $PGPIDFILE + rm -f $PGLOCKFILE +} + +restart() { + stop + start +} + +condrestart() { + [ -e $PGLOCKFILE ] && restart +} + +condstop() { + [ -e $PGLOCKFILE ] && stop +} + +reload() { + cmd="export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; $PGENGINE/pg_ctl reload -D '$PGDATA' -s" + runCommand $cmd +} + +initdb() { + if [ -f "$PGDATA/PG_VERSION" ]; then + echo -n "Data directory is not empty!" + echo_failure + echo + script_result=1 + else + echo -n $"Initializing database: " + if [ ! -e "$PGDATA" -a ! -h "$PGDATA" ]; then + mkdir -p "$PGDATA" || exit 1 + chown $PGUSER:$PGUSER "$PGDATA" + chmod go-rwx "$PGDATA" + fi + + # Clean up SELinux tagging for PGDATA + [ -x /sbin/restorecon ] && /sbin/restorecon "$PGDATA" + + # Make sure the startup-time log file is OK, too + if [ ! -e "$PGSTARTUPLOG" -a ! -h "$PGSTARTUPLOG" ]; then + touch "$PGSTARTUPLOG" || exit 1 + chown $PGUSER:$PGUSER "$PGSTARTUPLOG" + chmod go-rwx "$PGSTARTUPLOG" + [ -x /sbin/restorecon ] && /sbin/restorecon "$PGSTARTUPLOG" + fi + + # Initialize the database + cmd="$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident'" + runCommand $cmd + + # Create directory for postmaster log + mkdir -p "$PGDATA/pg_log" + chown $PGUSER:$PGUSER "$PGDATA/pg_log" + chmod go-rwx "$PGDATA/pg_log" + + if [ -f "$PGDATA/PG_VERSION" ]; then + echo_success + else + echo_failure + script_result=1 + fi + echo + fi +} + +# This script is slightly unusual in that the name of the daemon (postmaster) +# is not the same as the name of the subsystem (postgresql) + +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status postmaster + script_result=$? + ;; + restart) + restart + ;; + condrestart) + condrestart + ;; + condstop) + condstop + ;; + reload|force-reload) + reload + ;; + initdb) + initdb + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart|condstop|reload|force-reload|initdb}" + exit 1 +esac + +exit $script_result diff --git a/sbin/create_dm_db.sh b/sbin/create_dm_db.sh new file mode 100755 index 0000000000000000000000000000000000000000..b681273b68841d37bdeecf6e874e7cdcc45bafcc --- /dev/null +++ b/sbin/create_dm_db.sh @@ -0,0 +1,206 @@ +#!/bin/sh + +# +# Script used for creating DM database +# Deployment configuration can be set in etc/$DM_DB_NAME.deploy.conf file +# +# Usage: +# +# $0 [DM_DB_NAME [DM_DB_SCRIPTS_DIR]] +# + +DM_DB_NAME=dm +DM_DB_USER=dm +DM_DB_PASSWORD=dm +DM_DB_HOST=127.0.0.1 +DM_DB_PORT=11136 +DM_DB_ADMIN_USER=postgres +DM_DB_ADMIN_HOSTS="127.0.0.1 bluegill1.aps.anl.gov visa%.aps.anl.gov" +DM_DB_ADMIN_PASSWORD= +DM_DB_CHARACTER_SET=utf8 + + +CURRENT_DIR=`pwd` +MY_DIR=`dirname $0` && cd $MY_DIR && MY_DIR=`pwd` +cd $CURRENT_DIR + +if [ -z "${DM_ROOT_DIR}" ]; then + DM_ROOT_DIR=$MY_DIR/.. +fi +DM_SQL_DIR=$DM_ROOT_DIR/db +DM_RUN_DIR=$DM_ROOT_DIR/var/run +DM_ENV_FILE=${DM_ROOT_DIR}/setup.sh +if [ ! -f ${DM_ENV_FILE} ]; then + echo "Environment file ${DM_ENV_FILE} does not exist." + exit 1 +fi +. ${DM_ENV_FILE} > /dev/null + +# DM_SUPPORT_DIR should now be defined. +if [ -z "$DM_SUPPORT_DIR" ]; then + echo "Invalid environment file ${DM_ENV_FILE}: DM_SUPPORT_DIR is not defined." + exit 1 +fi +PG_DIR=$DM_SUPPORT_DIR/postgresql/$DM_HOST_ARCH +PG_CONTROL_SCRIPT=$DM_ROOT_DIR/etc/init.d/dm-postgresql +PG_DATA_DIR=$PG_DIR/data +PG_HBA_CONF=$PG_DATA_DIR/pg_hba.conf +DB_LOCK_FILE=${DM_RUN_DIR}/${DM_DB_NAME}.db.lock +DB_CREATE_SCRIPT=${DM_ROOT_DIR}/db/create_${DM_DB_NAME}_db.sql + +# Use first argument as db name, if provided +if [ ! -z "$1" ]; then + DM_DB_NAME=$1 +fi +echo "Using DB name: $DM_DB_NAME" + +# Look for deployment file in etc directory, and use it to override +# default entries +deployConfigFile=$DM_ROOT_DIR/etc/${DM_DB_NAME}.deploy.conf +if [ -f $deployConfigFile ]; then + echo "Using deployment config file: $deployConfigFile" + . $deployConfigFile +else + echo "Deployment config file $deployConfigFile not found, using defaults" +fi + +# Second argument overrides directory with db population scripts +DM_DB_SCRIPTS_DIR=${DM_DB_SCRIPTS_DIR:=$DM_SQL_DIR} +if [ ! -z "$2" ]; then + DM_DB_SCRIPTS_DIR=$2 +fi +if [ ! -d $DM_DB_SCRIPTS_DIR ]; then + echo "DB Scripts directory $DM_DB_SCRIPTS_DIR does not exist." + exit 1 +fi + +echo "Using DB scripts directory: $DM_DB_SCRIPTS_DIR" + +execute() { + msg="$@" + if [ ! -z "$DM_DB_ADMIN_PASSWORD" ]; then + sedCmd="s?$DM_DB_ADMIN_PASSWORD?\\*\\*\\*\\*\\*\\*?g" + echo "Executing: $@" | sed -e $sedCmd + else + echo "Executing: $@" + fi + eval "$@" +} + +createDb() { + if [ -f $DB_LOCK_FILE ]; then + echo "Database lock file $DB_LOCK_FILE already exists, will not proceed." + return 1 + fi + echo "Creating database $DM_DB_NAME" + ${PG_DIR}/bin/createdb -U $DM_DB_USER -h $DM_DB_HOST -p $DM_DB_PORT $DM_DB_NAME || return 1 + echo "Creating database schema for $DM_DB_NAME" + ${PG_DIR}/bin/psql -U $DM_DB_USER -h $DM_DB_HOST -p $DM_DB_PORT -d $DM_DB_NAME -f $DB_CREATE_SCRIPT || return 1 + touch $DB_LOCK_FILE +} + +createDbUser() { + _dbUser=$1 + shift 1 + _createFlags=$@ + + # create user + ${PG_DIR}/bin/createuser -h $DM_DB_HOST -p $DM_DB_PORT $_createFlags $_dbUser || return 1 +} + +modifyDbUserPassword() { + _dbUser=$1 + _dbPassword=$2 + _tmpFile=/tmp/$$.sql + echo "alter user $_dbUser with password '$_dbPassword';" > $_tmpFile + $PG_DIR/bin/psql -h $DM_DB_HOST -p $DM_DB_PORT -d postgres -f $_tmpFile + rm -f $_tmpFile +} + +# Check for failed earlier attempt +if [ -f $PG_HBA_CONF.orig ]; then + echo "File $PG_HBA_CONF.orig exists, refusing to proceed." + exit 1 +fi + +# Initialize db if needed +dbAction=restart +createDbRootUser=false +if [ ! -f $PG_HBA_CONF ]; then + $PG_CONTROL_SCRIPT initdb || exit 1 + dbAction=start + createDbRootUser=true +fi + +# Modify db permissions, restart db. +echo "Modifying db access permissions" +mv $PG_HBA_CONF $PG_HBA_CONF.orig +cat $PG_HBA_CONF.orig | sed 's?host.*all.*all.*127.*?host all all 127.0.0.1/32 trust?g' | sed 's?host.*all.*all.*::1/128.*?host all all ::1/128 trust?g' > $PG_HBA_CONF || exit 1 +echo "Restarting database server" +$PG_CONTROL_SCRIPT $dbAction + +# Create db root user if needed +sttyOrig=`stty -g` +if [ $createDbRootUser = "true" ]; then + # Read db password if needed + if [ -z "$DM_DB_ADMIN_PASSWORD" ]; then + stty -echo + read -p "Enter DB password for the $DM_DB_ADMIN_USER (DB root) user: " DM_DB_ADMIN_PASSWORD + echo + stty $sttyOrig + fi + + # Create postgres user + echo "Creating $DM_DB_ADMIN_USER" + createDbUser $DM_DB_ADMIN_USER -E -s || exit 1 + modifyDbUserPassword $DM_DB_ADMIN_USER $DM_DB_ADMIN_PASSWORD || exit 1 +fi + +# Read user db password if needed +if [ -z "$DM_DB_USER_PASSWORD" ]; then + stty -echo + read -p "Enter DB password for the $DM_DB_USER user: " DM_DB_USER_PASSWORD + echo + stty $sttyOrig +fi + +# Create db user +echo "Creating $DM_DB_USER" +createDbUser $DM_DB_USER -E -d || exit 1 +modifyDbUserPassword $DM_DB_USER $DM_DB_USER_PASSWORD || exit 1 + +# Create db +echo "Creating database: $DM_DB_NAME" +createDb || exit 1 + +# populate db +cd $CURRENT_DIR && cd $DM_DB_SCRIPTS_DIR +DM_DB_TABLES="\ +" +#for dbTable in $DM_DB_TABLES; do +# dbFile=populate_$dbTable.sql +# if [ -f $dbFile ]; then +# echo "Populating $dbTable using $dbFile script" +# execute $mysqlCmd $dbFile +# else +# echo "$dbFile not found, skipping $dbTable update" +# fi +#done + +# cleanup +echo "Restoring db access permissions" +if [ $createDbRootUser = "true" ]; then + # db was just created, enable password access + cat $PG_HBA_CONF.orig | sed 's?host.*all.*all.*127.*?host all all 127.0.0.1/32 md5?g' | sed 's?host.*all.*all.*::1/128.*?host all all ::1/128 md5?g' > $PG_HBA_CONF || exit 1 + rm -f $PG_HBA_CONF.orig +else + # no changes needed to original hba file + mv $PG_HBA_CONF.orig $PG_HBA_CONF +fi + +echo "Restarting database server" +$PG_CONTROL_SCRIPT restart + +echo "Database $DM_DN_NAME created successfully" +echo + diff --git a/sbin/destroy_all_dm_databases.sh b/sbin/destroy_all_dm_databases.sh new file mode 100755 index 0000000000000000000000000000000000000000..16c5d15be5f633de45a15c132bdd5b2f3a42ff5d --- /dev/null +++ b/sbin/destroy_all_dm_databases.sh @@ -0,0 +1,85 @@ +#!/bin/sh + +# +# Script used for destroying all DM databases +# +# Usage: +# +# $0 +# + +DM_DB_NAME=dm +DM_DB_USER=dm +DM_DB_PASSWORD=dm +DM_DB_HOST=127.0.0.1 +DM_DB_PORT=11136 +DM_DB_ADMIN_USER=postgres +DM_DB_ADMIN_HOSTS="127.0.0.1 bluegill1.aps.anl.gov visa%.aps.anl.gov" +DM_DB_ADMIN_PASSWORD= +DM_DB_CHARACTER_SET=utf8 + + +CURRENT_DIR=`pwd` +MY_DIR=`dirname $0` && cd $MY_DIR && MY_DIR=`pwd` +cd $CURRENT_DIR + +if [ -z "${DM_ROOT_DIR}" ]; then + DM_ROOT_DIR=$MY_DIR/.. +fi +DM_SQL_DIR=$DM_ROOT_DIR/db +DM_RUN_DIR=$DM_ROOT_DIR/var/run +DM_ENV_FILE=${DM_ROOT_DIR}/setup.sh +if [ ! -f ${DM_ENV_FILE} ]; then + echo "Environment file ${DM_ENV_FILE} does not exist." + exit 1 +fi +. ${DM_ENV_FILE} > /dev/null + +# DM_SUPPORT_DIR should now be defined. +if [ -z "$DM_SUPPORT_DIR" ]; then + echo "Invalid environment file ${DM_ENV_FILE}: DM_SUPPORT_DIR is not defined." + exit 1 +fi +PG_DIR=$DM_SUPPORT_DIR/postgresql/$DM_HOST_ARCH +PG_CONTROL_SCRIPT=$DM_ROOT_DIR/etc/init.d/dm-postgresql +PG_DATA_DIR=$PG_DIR/data +PG_HBA_CONF=$PG_DATA_DIR/pg_hba.conf +DB_CREATE_SCRIPT=${DM_ROOT_DIR}/db/create_${DM_DB_NAME}_db.sql + +# Ask user to verify this action +cd $DM_RUN_DIR +lockFileList=`ls -c1 *.db.lock 2> /dev/null` + +if [ -z $lockFileList ]; then + echo "There are no active databases" +else + dbNamelist="" + for lockFile in $lockFileList; do + dbName=`echo $lockFile | cut -f1 -d'.'` + dbNameList="$dbNameList $dbName" + done + echo "Found active databases: $dbNameList" + read -p "Proceed [y/N]? " proceedFlag + if [ "$proceedFlag" != "y" ]; then + echo "Active databases were not destroyed." + exit 1 + fi +fi + +# Stop db. +$PG_CONTROL_SCRIPT stop + +# Remove db data directory +echo "Removing database directory" +rm -rf $PG_DATA_DIR + +# Remove lock files. +if [ ! -z "$lockFileList" ]; then + echo "Removing lock files" + rm -f $lockFileList +fi + +echo "Cleanup done" +echo + +