📄 monetdb
字号:
#!/bin/bash# The contents of this file are subject to the MonetDB Public License# Version 1.1 (the "License"); you may not use this file except in# compliance with the License. You may obtain a copy of the License at# http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html## Software distributed under the License is distributed on an "AS IS"# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the# License for the specific language governing rights and limitations# under the License.## The Original Code is the MonetDB Database System.## The Initial Developer of the Original Code is CWI.# Portions created by CWI are Copyright (C) 1997-2007 CWI.# All Rights Reserved.#See the MonetDB Version 5 documentation for detailsfunction usage(){ echo "Usage: monetdb [command] [options] [script]" echo "Primary command:" echo " --status Show the server status [default]" echo " --start Server(s) is (are) started" echo " --stop Server(s) is (are) stopped" echo " --databases Show the known databases " echo " --checkpoint Create the checkpoint for a database " echo " --recover Restore a database to an earlier date" echo " --log Show the server management log" echo "" echo "Secondary options:" echo " --dbname=<database_name>" echo " --dbfarm=<directory>" echo " --dbinit=<stmt> Server prepare statement" echo " --config=<config_file> Configuration file" echo " --debug=<number> Trace server actions[0]" echo " --daemon=yes|no Run in background [no]" echo " --set <option>=<value> Set environment value" echo " --ascii Use ascii dump for the database [default=no]" echo " --help This list of options"}ASCII=""DBFARM=$MONETDB5_PREFIX/var/MonetDB5/dbfarm# First perform some sanity checksif [ "$MONETDB5_PREFIX" = "" ]then echo "The MONETDB5_PREFIX environment variable has not been set" echo "It should point to where you have installed the build directory" exitfiACTION="--status"case "$1" in "--start" | "--stop" | "--status" ) ACTION=$1 shift ;; "--databases" ) ACTION=$1 shift ;; "--dump" ) ACTION=checkpoint ASCII="--ascii=yes" shift ;; "--checkpoint" ) ACTION=$1 shift ;; "--recover" ) ACTION=$1; shift ;; "--log" ) ACTION=$1 shift ;; "--help" ) usage exit ;; * ) ;;esac# massage the argument list to prepare for callingARGS=""DBNAME=""STARTUP=""DELAY=""while [ $# -gt 0 ]do case "$1" in "--dump" ) ASCII="--ascii=yes" ;; "--ascii="* ) ASCII="$1" ;; "--dbfarm="* ) DBFARM="${1#--dbfarm=}" ;; "--dbname="* ) DBNAME="${1#--dbname=}" ;; "--delay="*) DELAY="${1#--delay=}" ARGS="$ARGS $1" ;; "--dbinit="* ) tail="${1#--dbinit=}" STARTUP=/tmp/mserver5.startup$$ echo $tail > $STARTUP ;; * ) ARGS="$ARGS $1" ;; esac shiftdone#echo "ARGS $ARGS"# check if the database farm existsif [ ! -d $DBFARM ]then echo "Creation of missing database storage area '$DBFARM'" mkdir -p $DBFARMfiif [ ! -d $DBFARM ]then echo "Database storage area '$DBFARM' is in accessible"fifunction getPID (){ active="" if [ -f $DBFARM/$1/.gdk_lock ] then pid=`sed -e "s/.*PID=//" -e "s/ .*//" -e 2q $DBFARM/$1/.gdk_lock` if [ "$pid" != "" ] then active=`ps --no-heading --format pid -p $pid` fi fi echo $active}function getTIME (){ if [ -z "$DELAY" ] then echo `sed -e "s/.*TIME=//" -e "s/\@.*//" -e 2q $DBFARM/$1/.gdk_lock` else echo 300 fi}function ping_mserver(){ # test lifeness of a specific server on the default port. # this is a database/scenario specific script # which should be created upon restart port=`cat $DBFARM/$1/.mal.port` echo "Ping $1 on port " $port answer=`mclient -lsql -p $port` echo "result" $answer # not complete yet!}function start_mserver(){ # make sure the configuration file is in place if [ ! -f $1/.monetdb.conf ] then cp $MONETDB5_PREFIX/etc/monetdb5.conf $1/.monetdb.conf fi pid=`getPID $1` #echo "start server $1 $pid" if [ "$pid" = "" ] then if [ "$STARTUP" != "" ] then cp "$STARTUP" $1/.mserver5.dbinit fi if [ -f $1/.mserver5.dbinit ] then STARTUP=$DBFARM/$1/.mserver5.dbinit fi if [ "$ARGS" = "" ] then if [ -f $1/.mserver5.args ] then ARGS=`cat $1/.mserver5.args` else echo > $1/.mserver5.args fi fi # use previous arguments if needed echo -n "Starting database server '$1'... " CONFIG="--config=$DBFARM/$1/.monetdb.conf" # make sure you can find strange errors echo "START" `date +"%F %T"` >>$DBFARM/$DBNAME/mserver5.log $MONETDB5_PREFIX/bin/mserver5 --dbfarm=$DBFARM --set daemon=yes --set monet_welcome=no --dbname=$1 $CONFIG $ARGS $STARTUP 2>&1 >> $DBFARM/$DBNAME/mserver5.log & pid="$!" if [ -z "$pid" ] then echo `date +"%F %T"` " FAILED $1 $ARGS" >>monetdb.log echo "FAILED" else echo `date +"%F %T"` " START $1 $ARGS" >>monetdb.log echo "ok" fi # start the guardian for this server as well if [ -n "$DELAY" ] then echo $DELAY >$1/.mguardian.delay fi $MONETDB5_PREFIX/bin/mguardian --start --dbfarm=$DBFARM --dbname=$1 else if [ -n "$DELAY" ] then echo $DELAY >$1/.mguardian.delay if [ -f $i/.mguardian.sleep ] then #wakeup the mguardian process pid=`cat $i/.mguardian.sleep` kill -HUP $pid fi echo "mguardian delay for '$1' reset" else echo "mserver5 for '$1' already running" fi fi}function stop_mserver(){ pid=`getPID $1` if [ -n "$pid" ] then stopped=`expr $stopped + 1 ` # disable the guardian first echo "STOP " `date +"%F %T"` >>$DBFARM/$DBNAME/mserver5.log $MONETDB5_PREFIX/bin/mguardian --stop $DBFARM/$1 kill -TERM $pid echo `date +"%F %T"` " STOP $1" >>monetdb.log if [ "`ps -p $pid -o comm=`" == "mserver5" ]; then # give it some time to wrap up echo -n "Stopping database server '$DBFARM/$1'... " sleep 5 if [ "`ps -p $pid -o comm=`" == "mserver5" ]; then echo "FAILED" else echo "ok" fi else echo "Stopping database server '$DBFARM/$1'... ok" fi fi}function show_status_hdr(){ echo "DBNAME SERVER GUARD DELAY STARTED"}function show_status(){ if [ -f $1/.gdk_lock ] then pid=`getPID $1` if [ -n "$pid" ] then if [[ $header = 0 ]] then show_status_hdr header=1 fi if [ -f $1/.mguardian.pid ] then guard=`cat $1/.mguardian.pid` active=`ps --no-heading --format pid -p $guard` if [ -z "$active" ] then guard="killed" fi else guard=missing fi if [ -f $1/.mserver5.dbinit ] then dbinit=`cat $1/.mserver5.dbinit` fi if [ -f $1/.mguardian.delay ] then delay=`cat $1/.mguardian.delay` else delay=unknown fi if [ -z "$delay" ] then delay=`grep delay $1/.monetdb.conf |sed -e "s/\t.*//" -e "s/delay=//"` fi start=`getTIME $1` echo "$1 $pid $guard $delay $start $dbinit" fi fi}# Initialization of the database directory should# ideally involve copying a template# Avoid creating database as a result from typosfunction create_database (){ echo "The database can be initialized to accept SQL or MAL connections." echo "The latter prohibits SQL sessions unless an authorized user " echo "has explicitly loaded the SQL module and started its scenario." echo "" read -p "Do you want to create the database '$1' for SQL sessions ? [yes/no]" answer if [ "$answer" = "yes" ] then mkdir $1 cp $MONETDB5_PREFIX/etc/monetdb5.conf $1/.monetdb.conf echo "include sql;sql.start();" > $1/.mserver5.dbinit echo "Database '$1' initialized for SQL sessionsi." return fi read -p "Do you want to create the database '$1' for MAL sessions ? [yes/no]" answer if [ "$answer" = "yes" ] then mkdir $1 cp $MONETDB5_PREFIX/etc/monetdb5.conf $1/.monetdb.conf echo "Database '$1' initialized" echo "" echo "To accept SQL sessions in the future start the server" echo 'once with the argument --dbinit="include sql;sql.start();"' echo "Subsequence server starts use the last setting." echo "" fi}# switch to dbfarmcd $DBFARMDBLIST=`ls`# check for an overruling database nameif [ -n "$DBNAME" ]then if [ ! -d $DBNAME ] then create_database $DBNAME fi DBLIST=$DBNAMEfi#echo "DBLIST $DBLIST"case "$ACTION" in "--databases" ) for i in $DBLIST do if [ -d "$i" ] then if [ -f $i/.mal.port ] then malport=`cat $i/.mal.port` fi echo "database $i $malport" fi done;; "--start" ) started=0 for i in $DBLIST do if [ -d $i ] then started=`expr $started + 1` start_mserver $i fi done if [ $started = 0 ] then echo "No server started" fi ;; "--stop" ) stopped=0 for i in $DBLIST do if [ -d $i ] then stop_mserver $i fi done if [ $stopped = 0 ] then # make sure there are no leftover processes killall mguardian >& /dev/null didkillg=$! killall mserver5 >& /dev/null didkillm=$! [[ $didkillg < 0 || $didkillm < 0 ]] && echo "No server stopped" fi ;; "--status" ) header=0 for i in $DBLIST do if [ -d $i ] then show_status $DBFARM/$i header=1 fi done if [ $header = 0 ] then echo "No server running " fi ;; "--checkpoint" ) for i in $DBLIST do if [ -d $i ] then pid=`getPID $i` if [ -n "$pid" ] then stop_mserver $i mchkpnt $ASCII --dbname=$i start_mserver $i else mchkpnt $ASCII --dbname=$i fi fi done ;; "--recover" ) for i in $DBLIST do if [ -d $i ] then pid=`getPID $i` if [ -n "$pid" ] then stop_mserver $i mrecover $ASCII --dbname=$i start_mserver $i else mrecover $ASCII --dbname=$i fi fi done ;; "--log" ) if [ -n "$DBNAME" ] then more $DBFARM/$DBNAME/mserver5.log else more $DBFARM/monetdb.log fi ;; * ) ;;esac#remove any leftoversrm -rf /tmp/.mserver5.*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -