Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • DM/dm-docs
  • hammonds/dm-docs
  • hparraga/dm-docs
3 results
Show changes
Commits on Source (94)
Showing
with 1116 additions and 0 deletions
var
# The top level makefile. Targets like "all" and "clean"
# are defined in the RULES file.
TOP = .
SUBDIRS = src
include $(TOP)/tools/make/RULES_DM
#!/bin/sh
# Run ant
if [ -z $DM_ROOT_DIR ]; then
cd `dirname $0` && myDir=`pwd`
setupFile=$myDir/../../setup.sh
if [ ! -f $setupFile ]; then
echo "Cannot find setup file: $setupFile"
exit 1
fi
source $setupFile
fi
DM_HOST_ARCH=`uname | tr [A-Z] [a-z]`-`uname -m`
export JAVA_HOME=$DM_SUPPORT_DIR/java/$DM_HOST_ARCH
export ANT_HOME=$DM_SUPPORT_DIR/ant
export PATH=$ANT_HOME/bin:$PATH
ant $@
File added
This diff is collapsed.
File added
This diff is collapsed.
File added
Release 20140930 (09/30/2014)
=============================
- Implemented first version of Web Portal UI: contains login page, and
users/experiment type management pages
- Developed project infrastructure tools: build scripts, web app configuration
and deployment scripts
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_PASSWORD=
DM_DB_ADMIN_HOSTS="127.0.0.1 bluegill1.aps.anl.gov gaeaimac.aps.anl.gov visa%.aps.anl.gov"
DM_DB_CHARACTER_SET=utf8
DM_DB_SCRIPTS_DIR=
DM_CONTEXT_ROOT=dm
# 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
# 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
#!/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
#! /bin/sh
### BEGIN INIT INFO
# Provides: glassfish
# Required-Start: $remote_fs $network $syslog
# Required-Stop: $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts GlassFish
# Description: Starts GlassFish application server
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Set root to default if needed.
MY_DIR=`dirname $0` && cd $MY_DIR && MY_DIR=`pwd`
if [ -z "${DM_ROOT_DIR}" ]; then
DM_ROOT_DIR=$MY_DIR/../..
fi
# Source environment file.
DM_USER=`id -nu`
DM_HOST=`hostname -s`
DM_ENV_FILE=${DM_ROOT_DIR}/setup.sh
if [ ! -f ${DM_ENV_FILE} ]; then
echo "Environment file ${DM_ENV_FILE} does not exist."
exit 2
fi
. ${DM_ENV_FILE} > /dev/null
export AS_JAVA=$DM_SUPPORT_DIR/java/$DM_HOST_ARCH
DM_GLASSFISH_DIR=$DM_SUPPORT_DIR/glassfish/$DM_HOST_ARCH
DERBY_DIR=$DM_SUPPORT_DIR/glassfish/$DM_HOST_ARCH/javadb/bin
DM_DAEMON_NAME=glassfish
DM_DAEMON_CONTROL_CMD=$DM_GLASSFISH_DIR/bin/asadmin
DM_DAEMON_START_ARGS="start-domain domain1"
DM_DAEMON_STOP_ARGS="stop-domain domain1"
DM_DAEMON_STATUS_CMDS="uptime list-domains list-applications list-jdbc-resources"
start() {
echo -n $"Starting ${DM_DAEMON_NAME}: "
# Check if we're a privileged user
if [ `id -u` = 0 -a ${DM_USER} != "root" ]; then
su -m -c "${DM_DAEMON_CONTROL_CMD} ${DM_DAEMON_START_ARGS}" ${DM_USER}
else
${DM_DAEMON_CONTROL_CMD} ${DM_DAEMON_START_ARGS}
fi
RETVAL=$?
[ $RETVAL -eq 0 ] && success $"${DM_DAEMON_NAME} startup" || failure $"${DM_DAEMON_NAME} startup"
echo
}
stop() {
echo -n $"Stopping ${DM_DAEMON_NAME}: "
# Check if we're a privileged user
if [ `id -u` = 0 -a ${DM_USER} != "root" ]; then
su -m -c "${DM_DAEMON_CONTROL_CMD} ${DM_DAEMON_STOP_ARGS}" ${DM_USER}
else
${DM_DAEMON_CONTROL_CMD} ${DM_DAEMON_STOP_ARGS}
fi
RETVAL=$?
[ $RETVAL -eq 0 ] && success $"${DM_DAEMON_NAME} shutdown" || failure $"${DM_DAEMON_NAME} shutdown"
echo
}
status() {
# Check if we're a privileged user
if [ `id -u` = 0 -a ${DM_USER} != "root" ]; then
for cmd in ${DM_DAEMON_STATUS_CMDS}; do
su -m -c "${DM_DAEMON_CONTROL_CMD} ${cmd}" ${DM_USER}
done
else
for cmd in ${DM_DAEMON_STATUS_CMDS}; do
${DM_DAEMON_CONTROL_CMD} ${cmd}
done
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
#!/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`
PGGROUP=`groups $PGUSER | cut -f3 -d ' '`
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:$PGGROUP $PGDATA || exit 1
mkdir -p $PGRUNDIR && chown -R $PGUSER:$PGGROUP $PGRUNDIR || exit 1
mkdir -p $PGLOGDIR && chown -R $PGUSER:$PGGROUP $PGLOGDIR || exit 1
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:$PGGROUP "$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:$PGGROUP "$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:$PGGROUP "$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:$PGGROUP "$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
../src/python
\ No newline at end of file
#!/bin/sh
#
# Script used for configuring DM webapp
# Deployment configuration can be set in etc/$DM_DB_NAME.deploy.conf file
#
# Usage:
#
# $0 [DM_DB_NAME]
#
MY_DIR=`dirname $0` && cd $MY_DIR && MY_DIR=`pwd`
if [ -z "${DM_ROOT_DIR}" ]; then
DM_ROOT_DIR=$MY_DIR/..
fi
DM_ENV_FILE=${DM_ROOT_DIR}/setup.sh
if [ ! -f ${DM_ENV_FILE} ]; then
echo "Environment file ${DM_ENV_FILE} does not exist."
exit 2
fi
. ${DM_ENV_FILE} > /dev/null
# Use first argument as db name, if provided
DM_DB_NAME=${DM_DB_NAME:=dm}
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
DM_HOST_ARCH=`uname | tr [A-Z] [a-z]`-`uname -m`
GLASSFISH_DIR=$DM_SUPPORT_DIR/glassfish/$DM_HOST_ARCH
JAVA_HOME=$DM_SUPPORT_DIR/java/$DM_HOST_ARCH
export AS_JAVA=$JAVA_HOME
ASADMIN_CMD=$GLASSFISH_DIR/bin/asadmin
DM_DB_HOST=${DM_DB_HOST:=localhost}
DM_DB_PORT=${DM_DB_PORT:=11136}
DM_DB_USER=${DM_DB_USER:=dm}
DM_DB_PASSWORD=${DM_DB_PASSWORD:=dm}
DM_DB_POOL=postgresql_${DM_DB_NAME}_DbPool
DM_DATA_SOURCE=${DM_DB_NAME}_DataSource
DM_DOMAIN=domain1
# copy db driver
echo "Copying db driver"
rsync -ar $DM_ROOT_DIR/src/java/DmWebPortal/lib/postgresql-9.3-1102.jdbc41.jar $GLASSFISH_DIR/glassfish/domains/${DM_DOMAIN}/lib/ext
# restart server
echo "Restarting glassfish"
$ASADMIN_CMD stop-domain ${DM_DOMAIN}
$ASADMIN_CMD start-domain ${DM_DOMAIN}
# create JDBC connection pool
echo "Creating JDBC connection pool $DM_DB_POOL"
$ASADMIN_CMD create-jdbc-connection-pool --datasourceclassname org.postgresql.ds.PGSimpleDataSource --restype javax.sql.DataSource --property user=${DM_DB_USER}:password=${DM_DB_PASSWORD}:driverClass="org.postgresql.Driver":portNumber=${DM_DB_PORT}:databaseName=${DM_DB_NAME}:serverName=${DM_DB_HOST}:url="jdbc\:postgresql\://${DM_DB_HOST}\:${DM_DB_PORT}/${DM_DB_NAME}" ${DM_DB_POOL}
# create JDBC resource associated with this connection pool
echo "Creating JDBC resource $DM_DATA_SOURCE"
$ASADMIN_CMD create-jdbc-resource --connectionpoolid ${DM_DB_POOL} ${DM_DATA_SOURCE}
# test the connection settings
echo "Testing connection"
$ASADMIN_CMD ping-connection-pool $DM_DB_POOL || exit 1
#!/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="\
experiment_type \
user_info \
role_type \
user_system_role \
policy_type \
allowed_policy_type
"
for dbTable in $DM_DB_TABLES; do
dbFile=populate_$dbTable.sql
if [ -f $dbFile ]; then
echo "Populating $dbTable using $dbFile script"
execute ${PG_DIR}/bin/psql -U $DM_DB_USER -h $DM_DB_HOST -p $DM_DB_PORT -d $DM_DB_NAME -f $dbFile || exit 1
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
#!/bin/sh
#
# Script used for deploying DM webapp
# Deployment configuration can be set in etc/$DM_DB_NAME.deploy.conf file
#
# Usage:
#
# $0 [DM_DB_NAME]
#
MY_DIR=`dirname $0` && cd $MY_DIR && MY_DIR=`pwd`
if [ -z "${DM_ROOT_DIR}" ]; then
DM_ROOT_DIR=$MY_DIR/..
fi
DM_ENV_FILE=${DM_ROOT_DIR}/setup.sh
if [ ! -f ${DM_ENV_FILE} ]; then
echo "Environment file ${DM_ENV_FILE} does not exist."
exit 2
fi
. ${DM_ENV_FILE} > /dev/null
# Use first argument as db name, if provided
DM_DB_NAME=${DM_DB_NAME:=dm}
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
DM_HOST_ARCH=`uname | tr [A-Z] [a-z]`-`uname -m`
DM_CONTEXT_ROOT=${DM_CONTEXT_ROOT:=dm}
GLASSFISH_DIR=$DM_SUPPORT_DIR/glassfish/$DM_HOST_ARCH
DM_DEPLOY_DIR=$GLASSFISH_DIR/glassfish/domains/domain1/autodeploy
DM_DIST_DIR=$DM_ROOT_DIR/src/java/DmWebPortal/dist
DM_BUILD_WAR_FILE=DmWebPortal.war
DM_WAR_FILE=$DM_CONTEXT_ROOT.war
JAVA_HOME=$DM_SUPPORT_DIR/java/$DM_HOST_ARCH
if [ ! -f $DM_DIST_DIR/$DM_BUILD_WAR_FILE ]; then
echo "$DM_BUILD_WAR_FILE not found in $DM_DIST_DIR."
exit 1
fi
# Modify war file for proper context/persistence settings and
# repackage it into new war
echo "Repackaging war file for context root $DM_CONTEXT_ROOT"
cd $DM_DIST_DIR
rm -rf $DM_CONTEXT_ROOT
mkdir -p $DM_CONTEXT_ROOT
cd $DM_CONTEXT_ROOT
jar xf ../$DM_BUILD_WAR_FILE
configFile=WEB-INF/glassfish-web.xml
cmd="cat $configFile | sed 's?<context-root.*?<context-root>${DM_CONTEXT_ROOT}</context-root>?g' > $configFile.2 && mv $configFile.2 $configFile"
eval $cmd
configFile=WEB-INF/classes/META-INF/persistence.xml
cmd="cat $configFile | sed 's?<jta-data-source.*?<jta-data-source>${DM_DB_NAME}_DataSource</jta-data-source>?g' > $configFile.2 && mv $configFile.2 $configFile"
eval $cmd
jar cf ../$DM_WAR_FILE *
export AS_JAVA=$JAVA_HOME
ASADMIN_CMD=$GLASSFISH_DIR/bin/asadmin
# copy war file
echo "Copying war file $DM_DIST_DIR/$DM_WAR_FILE to $DM_DEPLOY_DIR"
rm -f $DM_DEPLOY_DIR/${DM_WAR_FILE}_*
cp $DM_DIST_DIR/$DM_WAR_FILE $DM_DEPLOY_DIR
# wait on deployment
echo "Waiting on war deployment..."
WAIT_TIME=30
cd $DM_DEPLOY_DIR
t=0
while [ $t -lt $WAIT_TIME ]; do
sleep 1
deploymentStatus=`ls -c1 ${DM_WAR_FILE}_* 2> /dev/null | sed 's?.*war_??g'`
if [ ! -z "$deploymentStatus" ]; then
break
fi
t=`expr $t + 1`
done
echo "Deployment Status: $deploymentStatus"
#!/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