07c3f12004-10-11Petter Larsson #!/bin/sh if [ "x$PIKE" = "x" ]; then PIKE=pike fi if [ -f @DIR@/CVS/Entries ] ; then VERSION="cvs-@VERSION@" else VERSION="@VERSION@" fi DB='"mysql://root@localhost/aido_md"'
1008c92004-10-24Peter Bortas DEFINES="-V7.4"
07c3f12004-10-11Petter Larsson ARGS="" once=0 LOG='@DIR@/logs/metaserver-debug' DEFLOG="$LOG" PIDFILE="$HOME/.aido/metaserver.pid" DEFPIDFILE="$PIDFILE" while [ ! c"$1" = "c" ] ; do case "$1" in -D*|-d*|-t*) DEFINES="$DEFINES $1" ;; '--once') once=1 ;; '--kill'|'--stop') if [ -f $PIDFILE ]; then PID=`cat $PIDFILE` echo Killing metaserver with PID $PID kill $PID && wait $PID 2>/dev/null fi exit 0 ;; '--restart') #FIXME: Doesn't use last sessions options. if [ -f $PIDFILE ]; then PID=`cat $PIDFILE` echo Restarting metaserver with PID $PID in the background. kill -HUP $PID fi exit 0 ;; '--version') echo "AIDO MetaServer $VERSION" exit 0 ;;
1008c92004-10-24Peter Bortas  --log=*)
07c3f12004-10-11Petter Larsson  LOG=`echo $1 | sed -e 's/--log=//'` ;;
1008c92004-10-24Peter Bortas  --pid-file=*)
07c3f12004-10-11Petter Larsson  PIDFILE=`echo $1 | sed -e 's/--pid-file=//'` ;;
1008c92004-10-24Peter Bortas  --database=*) DB=`echo $1 | sed -e 's/--database=//'` ;;
07c3f12004-10-11Petter Larsson  '--help'|'-?') sed -e "s/\\.B/`tput 'bold' 2>/dev/null`/g" -e "s/B\\./`tput 'sgr0' 2>/dev/null`/g" << EOF This command will start the AIDO MetaServer (version $VERSION). Installation directory: @DIR@ Options: .B--versionB.: Output version information .B--help -?B.: This information. .B--onceB.: Run the server only once, in the foreground. The default behaviour is to run it in a loop in the background. .B--kill --stopB.: Kill the running server, without restarting it .B--restartB.: Kill the running server, restarting it afterwards .B--log=fileB.: Use the specified file as the debug log. default is $DEFLOG .B--pid-file=fileB.: Use the specified file as the PID file. default is $DEFPIDFILE
1008c92004-10-24Peter Bortas  .B--database=URLB.: Use specified database URL. default is $DB
07c3f12004-10-11Petter Larsson EOF tput 'rmso' 2>/dev/null exit 0 ;; *) ARGS="$ARGS $1" ;; esac shift done cd "@DIR@/programs"
1008c92004-10-24Peter Bortas ARGS="$DEFINES -DSQL_URL="'"'"$DB"'"'" -M../pike-modules metaserver.pike $ARGS"
07c3f12004-10-11Petter Larsson  rotate_log() { mv -f "$LOG.old" "$LOG.older" 2>/dev/null mv -f "$LOG" "$LOG.old" 2>/dev/null } start_server() { if [ ! x$DEBUG = x ] ; then echo cd "@DIR@/programs/" pikeversion=`$PIKE --version 2>&1 | head -1` echo "Pike version: $pikeversion." echo exec $PIKE "$ARGS" fi $PIKE $ARGS & AIDO_PID=$! wait $AIDO_PID AIDO_PID="" } signal_exit() { trap "" 2 15 if [ "x$AIDO_PID" != "x" ]; then kill $AIDO_PID && wait $AIDO_PID 2>/dev/null fi exit } signal_hup() { if [ "x$AIDO_PID" != "x" ]; then kill $AIDO_PID fi } AIDO_PID="" if [ x$once = 'x0' ] ; then if [ -f $PIDFILE ]; then PID=`cat $PIDFILE` if kill -0 $PID 2>/dev/null ; then echo MetaServer already running with PID $PID. exit 1 fi fi echo Starting MetaServer in the background. ( trap signal_exit 2 15 trap signal_hup 1 while : ; do rotate_log ; start_server > $LOG 2>&1 < /dev/null done ) >/dev/null 2>&1 & #FIXME: Check that dirname $PIDFILE exists. test -d $HOME/.aido || mkdir $HOME/.aido echo $! >$PIDFILE else trap signal_exit 2 15 echo $$ >$PIDFILE start_server fi