de23632002-02-05Per Hedbor #!/bin/sh DEFINES="" ARGS=""
0b590d2002-04-15Per Hedbor once=0
c316672003-06-05Martin Nilsson if [ "x$PIKE" = "x" ]; then PIKE=pike fi
de23632002-02-05Per Hedbor  if [ -f @DIR@/CVS/Entries ] ; then VERSION="cvs-@VERSION@" else VERSION="@VERSION@" fi
0b590d2002-04-15Per Hedbor LOG='@DIR@/logs/server-debug'
6458f32003-12-15Peter Bortas DEFLOG="$LOG" PIDFILE="$HOME/.aido/pid" DEFPIDFILE="$PIDFILE"
0b590d2002-04-15Per Hedbor 
de23632002-02-05Per Hedbor while [ ! c"$1" = "c" ] ; do case "$1" in
bd1b6a2002-02-24Per Hedbor  -D*|-d*|-t*)
de23632002-02-05Per Hedbor  DEFINES="$DEFINES $1" ;;
0b590d2002-04-15Per Hedbor  '--once') once=1 ;;
8d42e82003-05-30Andreas Sigfridsson  '--kill'|'--stop')
6458f32003-12-15Peter Bortas  if [ -f $PIDFILE ]; then PID=`cat $PIDFILE`
66466d2003-05-31Martin Stjernholm  kill $PID && wait $PID 2>/dev/null
8d42e82003-05-30Andreas Sigfridsson  fi exit 0 ;; '--restart')
6458f32003-12-15Peter Bortas  #FIXME: Doesn't use last sessions options. if [ -f $PIDFILE ]; then PID=`cat $PIDFILE`
1c4f522003-05-31Martin Stjernholm  kill -HUP $PID
8d42e82003-05-30Andreas Sigfridsson  fi exit 0 ;;
2e53e72003-03-09Per Hedbor  '--nossl'|'--no-sll') DEFINES="-DNOSSL $DEFINES" ;;
de23632002-02-05Per Hedbor  '--debug'|'--with-debug'|'--enable-debug') DEBUG=1 DEFINES="-DVP_DEBUG $DEFINES" ;; '--version')
6458f32003-12-15Peter Bortas  echo "AIDO MediaPlayer backend server $VERSION" exit 0 ;;
0b590d2002-04-15Per Hedbor  '--log=*') LOG=`echo $1 | sed -e 's/--log=//'` ;;
6458f32003-12-15Peter Bortas  '--pid-file=*') PIDFILE=`echo $1 | sed -e 's/--pid-file=//'` ;;
de23632002-02-05Per Hedbor  '--help'|'-?')
6458f32003-12-15Peter Bortas  sed -e "s/\\.B/`tput 'bold' 2>/dev/null`/g" -e "s/B\\./`tput 'sgr0' 2>/dev/null`/g" << EOF
de23632002-02-05Per Hedbor This command will start the AIDO MediaPlayer backend server (version $VERSION). Installation directory: @DIR@ Options: .B--versionB.: Output version information .B--help -?B.: This information. .B--offlineB.: Indicate that there is no network connection available. Disables metaserver access. .B--debugB.: Output more debug information
2e53e72003-03-09Per Hedbor  .B--no-sslB.: Run without SSL-support. A normal HTTP-port will opened instead of a HTTPS-port.
0b590d2002-04-15Per Hedbor  .B--onceB.: Run the server only once, in the foreground. The default behaviour is to run it in a loop in the background.
e2bfc02003-06-01Andreas Sigfridsson  .B--kill --stopB.: Kill the running server, without restarting it .B--restartB.: Kill the running server, restarting it afterwards
0b590d2002-04-15Per Hedbor  .B--log=fileB.: Use the specified file as the debug log.
6458f32003-12-15Peter Bortas  default is $DEFLOG .B--pid-file=fileB.: Use the specified file as the PID file. default is $DEFPIDFILE
de23632002-02-05Per Hedbor  EOF tput 'rmso' 2>/dev/null exit 0 ;; *) ARGS="$ARGS $1" ;; esac shift done cd "@DIR@/programs/server" ARGS="$DEFINES -M../../pike-modules main.pike $ARGS"
0b590d2002-04-15Per Hedbor 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/server"
520d3b2003-01-21Martin Nilsson  pikeversion=`$PIKE --version 2>&1 | head -1`
b4c0812002-12-29Peter Bortas  echo "Pike version: $pikeversion."
520d3b2003-01-21Martin Nilsson  echo exec $PIKE "$ARGS"
0b590d2002-04-15Per Hedbor  fi
8d42e82003-05-30Andreas Sigfridsson  $PIKE $ARGS & AIDO_PID=$! wait $AIDO_PID AIDO_PID=""
0b590d2002-04-15Per Hedbor }
de23632002-02-05Per Hedbor 
8d42e82003-05-30Andreas Sigfridsson signal_exit() { trap "" 2 15 if [ "x$AIDO_PID" != "x" ]; then
66466d2003-05-31Martin Stjernholm  kill $AIDO_PID && wait $AIDO_PID 2>/dev/null
8d42e82003-05-30Andreas Sigfridsson  fi exit } signal_hup() { if [ "x$AIDO_PID" != "x" ]; then
66466d2003-05-31Martin Stjernholm  kill $AIDO_PID
8d42e82003-05-30Andreas Sigfridsson  fi } AIDO_PID=""
0b590d2002-04-15Per Hedbor if [ x$once = 'x0' ] ; then
6458f32003-12-15Peter Bortas  if [ -f $PIDFILE ]; then PID=`cat $PIDFILE`
1c4f522003-05-31Martin Stjernholm  if kill -0 $PID 2>/dev/null ; then echo Server already running with PID $PID. exit 1 fi fi
0b590d2002-04-15Per Hedbor  echo Starting server in the background. (
8d42e82003-05-30Andreas Sigfridsson  trap signal_exit 2 15 trap signal_hup 1
0b590d2002-04-15Per Hedbor  while : ; do rotate_log ; start_server > $LOG 2>&1 < /dev/null done
1c4f522003-05-31Martin Stjernholm  ) >/dev/null 2>&1 &
6458f32003-12-15Peter Bortas  #FIXME: Check that dirname $PIDFILE exists.
66466d2003-05-31Martin Stjernholm  test -d $HOME/.aido || mkdir $HOME/.aido
6458f32003-12-15Peter Bortas  echo $! >$PIDFILE
0b590d2002-04-15Per Hedbor else
8d42e82003-05-30Andreas Sigfridsson  trap signal_exit 2 15
6458f32003-12-15Peter Bortas  echo $$ >$PIDFILE
0b590d2002-04-15Per Hedbor  start_server
e5ea7d2002-04-23Marcus Comstedt fi