Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 336 lines (310 sloc) 9.41 KB
#!/bin/bash
#
# Runs GemStone scripts that used to be invoked as individual commands
#
# Copyright 2009-2010 GemStone Systems, Inc. All rights reserved.
COMMAND="`basename $0`"
usage() {
cat <<ENDHELP
Usage:
$COMMAND {start|start-debug|start-bench|stop|restart|status|topaz|topaz-debug|
squeak|force-reload|version|help}
To control the MagLev server:
maglev start - Start MagLev server processes
maglev start-debug - Start MagLev server processes with verbose output
maglev start-bench - Start MagLev server with performance optimizations
maglev stop - Stop MagLev server processes
maglev restart - Restart MagLev server processes
maglev status - Display MagLev server status
maglev version - Display MagLev version number
maglev force-reload - Stop MagLev server, replace with empty repository!!!
To execute other MagLev commands:
maglev topaz - Enter a Topaz shell
maglev topaz-debug - Enter a Topaz shell useful for debugging
maglev squeak - Start optional Squeak development environment
maglev startnetldi - Start MagLev NetLDI (not normally needed)
maglev stopnetldi - Stop MagLev NetLDI process (not normally needed)
maglev vsd - Start Visual Statistics Display monitoring tool
maglev help - Display this text
ENDHELP
}
# Detect operating system
PLATFORM="`uname -sm | tr ' ' '-'`"
# Macs with Core i7 use the same software as older Macs
[ $PLATFORM = "Darwin-x86_64" ] && PLATFORM="Darwin-i386"
# Environment variable settings
if [ -z "$MAGLEV_HOME" ]; then
if [ -x $PWD/gemstone/bin/startstone ]; then
# echo "using $PWD as MAGLEV_HOME"
export MAGLEV_HOME=$PWD
else
echo "$COMMAND: [Warning] \$MAGLEV_HOME is not set."
tree=$(cd `dirname "$0"/` ; cd .. ; pwd)
if [ -d "${tree}/gemstone" ]; then
export MAGLEV_HOME="${tree}"
echo "Assuming ${MAGLEV_HOME}"
else
echo "$COMMAND: [Error] Neither $PWD nor $tree are a valid MAGLEV_HOME directory"
echo "To fix this, set a valid MAGLEV_HOME in your .bashrc"
exit 1
fi
fi
fi
# Set environment variables unless they already exist
[ -z "$STONENAME" ] && STONENAME=maglev
[ -z "$GEMSTONE" ] && export GEMSTONE=$MAGLEV_HOME/gemstone
[ -z "$GEMSTONE_GLOBAL_DIR" ] && export GEMSTONE_GLOBAL_DIR=$MAGLEV_HOME
[ -z "$GEMSTONE_LOGDIR" ] && export GEMSTONE_LOGDIR=$MAGLEV_HOME/log/$STONENAME
[ -z "$GEMSTONE_LOG" ] && export GEMSTONE_LOG=$GEMSTONE_LOGDIR/$STONENAME.log
[ -z "$GEMSTONE_DATADIR" ] && export GEMSTONE_DATADIR=$MAGLEV_HOME/data/$STONENAME
[ -z "$GEMSTONE_BACKUPDIR" ] && export GEMSTONE_BACKUPDIR=$MAGLEV_HOME/backups
[ -z "$GEMSTONE_SYS_CONF" ] && export GEMSTONE_SYS_CONF=$MAGLEV_HOME/etc/system.conf
# Only use $MAGLEV_HOME/etc/.topazini if normal .topazini doesn't exist
if [[ -e .topazini || -e $HOME/.topazini ]]; then
TOPAZ_CMD="$GEMSTONE/bin/topaz -q -l "
TOPAZDEBUG_CMD="$GEMSTONE/bin/topaz -l "
else
TOPAZ_CMD="$GEMSTONE/bin/topaz -q -I $MAGLEV_HOME/etc/.topazini -l "
TOPAZDEBUG_CMD="$GEMSTONE/bin/topaz -I $MAGLEV_HOME/etc/.topazini -l "
fi
# Check options
while getopts 'hv' OPTION
do
case $OPTION in
h)
usage
exit
;;
v)
echo "`grep ^maglev $MAGLEV_HOME/version.txt | cut -f1 -d[`[`uname -sm`]"
exit
;;
?)
usage
exit
;;
esac
done
shift $(($OPTIND - 1))
# Commands
startserver() {
$GEMSTONE/bin/startstone $STONENAME | grep Info]:.*[\\\'\\\"]$STONENAME
$GEMSTONE/bin/waitstone $STONENAME &>/dev/null
# echo "MagLev server \"$STONENAME\" started"
}
startserver-debug() {
$GEMSTONE/bin/startstone -z $MAGLEV_HOME/etc/system-debug.conf $STONENAME
$GEMSTONE/bin/waitstone $STONENAME
# echo "MagLev server \"$STONENAME\" started in verbose mode"
}
startserver-bench() {
$GEMSTONE/bin/startstone -z $MAGLEV_HOME/etc/system-benchmark.conf $STONENAME | grep Info]:.*[\\\'\\\"]$STONENAME
$GEMSTONE/bin/waitstone $STONENAME &>/dev/null
# echo "MagLev server \"$STONENAME\" started with performance optimizations"
}
ensurePrimsLoaded() {
$TOPAZ_CMD << EOF > /dev/null
set gemstone $STONENAME
login
obj RubyPrimsLoaded
quit
EOF
result=$?
if [ "$result" -ne 0 ] ; then
echo "Loading kernel. It may take a few seconds..."
logfile="$MAGLEV_HOME/log/maglev/allprims.log"
$TOPAZ_CMD << EOF > $logfile
set gemstone $STONENAME
iferr 1 exit 3
input $MAGLEV_HOME/src/smalltalk/ruby/allprims.topaz
exit 0
EOF
result=$?
if [ "$result" -ne 0 ] ; then
echo "FAILED LOADING PRIMS: $result See $logfile"
fi
$MAGLEV_HOME/bin/maglev-ruby $MAGLEV_HOME/src/kernel/extensions.rb
fi
}
stopserver() {
$GEMSTONE/bin/stopstone $STONENAME DataCurator swordfish -i 1>/dev/null
stopnetldi
}
status() {
echo "MAGLEV_HOME = $MAGLEV_HOME"
$GEMSTONE/bin/gslist -clv
}
version() {
echo "`grep ^maglev $MAGLEV_HOME/version.txt | cut -f1 -d[`[`uname -sm`]"
}
topaz() {
if [ -z "`which rlwrap > /dev/null 2>&1`" ]; then
$TOPAZ_CMD $@
else
rlwrap $TOPAZ_CMD $@
fi
}
topaz-debug() {
if [ -z "`which rlwrap > /dev/null 2>&1`" ]; then
$TOPAZDEBUG_CMD $@
else
rlwrap $TOPAZDEBUG_CMD $@
fi
}
initialize() {
# Directory creations necessary because a new "git clone" doesn't have them
# create GEMSTONE_LOGDIR if it doesn't exist
if [ ! -d $GEMSTONE_LOGDIR ]; then
mkdir -p $GEMSTONE_LOGDIR
chmod 750 $GEMSTONE_LOGDIR
fi
# create GEMSTONE_GLOBAL_DIR/locks if it doesn't exist
if [ ! -d $GEMSTONE_GLOBAL_DIR/locks ]; then
mkdir -p $GEMSTONE_GLOBAL_DIR/locks
chmod 750 $GEMSTONE_GLOBAL_DIR/locks
fi
# create GEMSTONE_DATADIR if it doesn't exist
if [ ! -d $GEMSTONE_DATADIR ]; then
mkdir -p $GEMSTONE_DATADIR/extent
mkdir -p $GEMSTONE_DATADIR/tranlog
chmod 750 $GEMSTONE_DATADIR $GEMSTONE_DATADIR/extent $GEMSTONE_DATADIR/tranlog
fi
# create GEMSTONE_BACKUPDIR if it doesn't exist
if [ ! -d $GEMSTONE_BACKUPDIR ]; then
mkdir -p $GEMSTONE_BACKUPDIR
chmod 750 $GEMSTONE_BACKUPDIR
fi
# grab a virgin repository if no repository exists
if [ ! -e $GEMSTONE_DATADIR/extent/extent0.ruby.dbf ]; then
# In case this is called before "rake maglev:build" - e.g. in RVM
if [ -e $MAGLEV_HOME/bin/extent0.ruby.dbf ]; then
cp -p $MAGLEV_HOME/bin/extent0.ruby.dbf $GEMSTONE_DATADIR/extent/
chmod 660 $GEMSTONE_DATADIR/extent/extent0.ruby.dbf
fi
fi
}
destroy() {
rm -f $MAGLEV_HOME/data/$STONENAME/extent/*.dbf
rm -f $MAGLEV_HOME/data/$STONENAME/tranlog/*.dbf
rm -f $MAGLEV_HOME/log/$STONENAME/*
# The locks should go away by themselves
# rm -f $MAGLEV_HOME/locks/$STONENAME..lck $MAGLEV_HOME/locks/$STONENAME\@*
}
startnetldi() {
$GEMSTONE/bin/startnetldi -g -a $USER | grep Info].*server
}
stopnetldi() {
$GEMSTONE/bin/stopnetldi | grep Info].*[Ss]erver
}
squeak() {
# If you use Squeak for development and debugging
case "$PLATFORM" in
Darwin-i386)
if [ -e /Applications/GemTools-MagLev.app ]; then
startnetldi
open /Applications/GemTools-MagLev.app
else
echo "[Error] Cannot open /Applications/GemTools-MagLev.app"
echo "as that file does not exist. To fix this, download and unzip"
echo "http://seaside.gemstone.com/squeak/GemTools-MagLev.zip"
echo "then move GemTools-MagLev.app to /Applications"
exit 1
fi
;;
Linux-x86_64)
if [ -e $MAGLEV_HOME/../GemTools-MagLev.app/GemTools.sh ]; then
startnetldi
bash "$MAGLEV_HOME/../GemTools-MagLev.app/GemTools.sh"
else
echo "[Error] Cannot open \$MAGLEV_HOME/../GemTools-MagLev.app/GemTools.sh"
echo "as that file does not exist. To fix this, download and unzip"
echo "http://seaside.gemstone.com/squeak/GemTools-MagLev.zip"
echo "then move GemTools-MagLev.app to \$MAGLEV_HOME/../"
exit 1
fi
;;
*)
echo "[Error] "maglev squeak" only works on a Linux or Mac OS X"
echo "The result from \"uname -sm\" is \"`uname -sm`\""
exit 1
;;
esac
}
startvsd() {
export PATH=$GEMSTONE/bin:$PATH
$GEMSTONE/bin/vsd &
}
mri() {
export DYLD_LIBRARY_PATH=$GEMSTONE/lib32
irb -I $MAGLEV_HOME/gci -rgci
}
# See what we were asked to do
case "$1" in
start)
initialize
startserver
ensurePrimsLoaded
;;
start-debug)
initialize
startserver-debug
ensurePrimsLoaded
;;
start-bench)
initialize
startserver-bench
ensurePrimsLoaded
;;
startnetldi)
startnetldi
;;
stopnetldi)
stopnetldi
;;
stop)
stopserver
;;
restart)
stopserver
startserver
ensurePrimsLoaded
;;
status)
status
;;
version)
version
;;
topaz)
shift
# pass params so we can execute 'maglev topaz -T200000'
topaz $@
;;
topaz-debug)
shift
# pass params so we can execute 'maglev topaz -T200000'
topaz-debug $@
;;
squeak)
squeak
;;
vsd)
startvsd
;;
mri)
mri
;;
force-reload)
stopserver
destroy
initialize
;;
help)
usage
;;
*)
echo "Usage: $COMMAND {start|start-debug|start-bench|stop|restart|status|topaz|topaz-debug|"
echo " squeak|force-reload|version|help}"
exit 1
;;
esac