b1fca01996-11-12Per Hedbor #!/bin/sh
fd12951997-09-07Henrik Grubbström (Grubba) #
4dfffc1998-07-27Martin Stjernholm # $Id: start,v 1.44 1998/07/27 07:12:56 mast Exp $
b1fca01996-11-12Per Hedbor 
c6420b1998-06-02Henrik Grubbström (Grubba) VERSION=202; BETA=.b;
b1fca01996-11-12Per Hedbor  # Can be set with '--config-dir=DIR' DIR=../configurations/ LOGDIR=../logs/ FILES="default"
3e7d3b1998-03-20Per Hedbor program=base_server/roxenloader.pike
b1fca01996-11-12Per Hedbor 
3c31841998-03-01Per Hedbor # Enable threads (if available) on Solaris. # Most other OS's have thread bugs that cause them or Roxen to crash. if uname | grep 'SunOS' >/dev/null 2>&1; then if uname -r | grep '5\.[5-9]' >/dev/null 2>&1; then echo 'Solaris 2.5 or later detected. Enabling threads (if available).' DEFINES="$DEFINES -DENABLE_THREADS" fi fi
fd12951997-09-07Henrik Grubbström (Grubba) # Roxen will create files as the initial user, # which it expects to be able to read as the run-time user. umask 022
1c48181997-03-02Henrik Grubbström (Grubba) # Pike default Master-program
7cb64f1998-01-17Henrik Grubbström (Grubba) if [ "x$PIKE_MASTER" = "x" ]; then
133f9f1998-07-08Martin Stjernholm  if [ -d share/pike ]; then
196f041998-07-08Martin Stjernholm  # This is used with localinstall
133f9f1998-07-08Martin Stjernholm  DEFINES="$DEFINES -Ishare/pike/include" PIKE_MODULE_PATH="$PIKE_MODULE_PATH:share/pike/modules" fi if [ -f lib/master.pike ]; then
026abf1998-05-10Henrik Grubbström (Grubba)  DEFINES="$DEFINES -mlib/master.pike -Ilib/include" PIKE_MODULE_PATH="$PIKE_MODULE_PATH:lib/modules"
53dbe81998-03-01Per Hedbor  elif [ -f lib/pike/master.pike ]; then
026abf1998-05-10Henrik Grubbström (Grubba)  DEFINES="$DEFINES -mlib/pike/master.pike -Ilib/pike/include" PIKE_MODULE_PATH="$PIKE_MODULE_PATH:lib/pike/modules"
4fed401997-04-16Henrik Grubbström (Grubba)  fi
95721d1998-05-11Martin Stjernholm  export PIKE_MODULE_PATH
7cb64f1998-01-17Henrik Grubbström (Grubba) else # This is usefull when using several different Pikes.
f9e2061998-04-19Henrik Grubbström (Grubba)  # Specify include and module paths with # PIKE_INCLUDE_PATH and PIKE_MODULE_PATH # they are handled automatically by the master, # so no need to do it here.
7cb64f1998-01-17Henrik Grubbström (Grubba)  DEFINES="$DEFINES -m$PIKE_MASTER"
d0ee181997-03-01Henrik Grubbström (Grubba) fi
1c48181997-03-02Henrik Grubbström (Grubba)  # Extra module-path
d0ee181997-03-01Henrik Grubbström (Grubba) if [ -d etc/modules ]; then
cf1e7c1997-04-19Henrik Grubbström (Grubba)  DEFINES="$DEFINES -Metc/modules"
1c48181997-03-02Henrik Grubbström (Grubba) fi # Extra include-path if [ -d etc/include ]; then
cf1e7c1997-04-19Henrik Grubbström (Grubba)  DEFINES="$DEFINES -Ietc/include"
1c48181997-03-02Henrik Grubbström (Grubba) fi # Extra include-path (2) if [ -d base_server ]; then
cf1e7c1997-04-19Henrik Grubbström (Grubba)  DEFINES="$DEFINES -Ibase_server"
d0ee181997-03-01Henrik Grubbström (Grubba) fi
b1fca01996-11-12Per Hedbor 
4d14291998-04-28Henrik Grubbström (Grubba) # Extra program-path DEFINES="$DEFINES -P`pwd`"
7e1aee1997-08-10Henrik Grubbström (Grubba) # Extra kludge for HPUX # HPUX doesn't like group 60001(nobody) if uname | grep 'HP-UX' >/dev/null 2>&1; then echo 'WARNING: Applying kludge for HPUX. (see base_server/privs.pike)' DEFINES="$DEFINES -DHPUX_KLUDGE" fi
d0ee181997-03-01Henrik Grubbström (Grubba) pike=pike if [ -x bin/pike ] ; then pike=bin/pike; fi
53dbe81998-03-01Per Hedbor if [ -x bin/roxen ] ; then pike=bin/roxen; fi
d8f3ff1998-06-18Henrik Grubbström (Grubba) if [ "x$PIKE" = "x" ]; then :; else if [ -x "$PIKE" ]; then pike="$PIKE"; fi fi
b1fca01996-11-12Per Hedbor 
c6420b1998-06-02Henrik Grubbström (Grubba) gdb=no
b1fca01996-11-12Per Hedbor rotate () { b=5; for a in 4 3 2 1 ; do mv -f $1.$a $1.$b 2> /dev/null; b=$a; done }
d0ee181997-03-01Henrik Grubbström (Grubba) start_roxen() {
c6420b1998-06-02Henrik Grubbström (Grubba)  args="-DROXEN $DEBUG $DEFINES $pass $program --config-dir=$DIR" if [ "x$gdb" = "xno" ]; then
d8634c1998-07-09Martin Stjernholm  echo "PIKE_MODULE_PATH=$PIKE_MODULE_PATH"
c6420b1998-06-02Henrik Grubbström (Grubba)  echo Executing $pike $args $@ $pike $args $@ else echo Executing gdb $pike $args $@ echo >.gdbinit handle SIGPIPE nostop noprint pass
16f1481998-07-09Henrik Grubbström (Grubba)  echo >>.gdbinit handle SIGUSR1 nostop noprint pass echo >>.gdbinit handle SIGUSR2 nostop noprint pass
c6420b1998-06-02Henrik Grubbström (Grubba)  echo >>.gdbinit run $args $@ gdb $pike rm .gdbinit fi
d0ee181997-03-01Henrik Grubbström (Grubba) }
b1fca01996-11-12Per Hedbor ####### END PREAMBLE ## Parse all arguments.
82f5191997-03-02Per Hedbor ## GNU-style, long options only, except for -D, simply passed on. parse_args() { while [ ! c"$1" = "c" ] ; do
b1fca01996-11-12Per Hedbor  case $1 in
4019f81997-03-01Per Hedbor  -D*) DEFINES="$DEFINES $1" ;;
82f5191997-03-02Per Hedbor # Used by the 'install' script
b1fca01996-11-12Per Hedbor  --log-dir=*) LOGDIR=`echo $1 | sed -e 's/--log-dir=//'` ;; --config-dir=*) DIR=`echo $1 | sed -e 's/--config-dir=//'`
6a85661997-04-10Henrik Grubbström (Grubba)  FILES=`echo $1 | sed -e's/--config-dir=//' -e's/\.//g' -e's./..g' -e 's.-..g'`
b1fca01996-11-12Per Hedbor  ;;
8a788c1998-07-22David Hedbor  '--debug'|'--with-debug'|'--enable-debug')
59f64b1997-01-27Per Hedbor  debug=1 ;;
8a788c1998-07-22David Hedbor  '--fd-debug'|'--with-fd-debug'|'--enable-fd-debug')
cc4fdd1998-03-26Per Hedbor  DEFINES="-DFD_DEBUG $DEFINES" ;;
8a788c1998-07-22David Hedbor  '--threads'|'--with-threads'|'--enable-threads')
3c31841998-03-01Per Hedbor  DEFINES="-DENABLE_THREADS $DEFINES" ;;
8a788c1998-07-22David Hedbor  '--no-threads'|'--without-threads'|'--disable-threads')
3c31841998-03-01Per Hedbor  DEFINES="`echo $DEFINES | sed -e 's/-DENABLE_THREADS//'`" ;; '--profile') DEFINES="-DPROFILE $DEFINES" ;;
8a788c1998-07-22David Hedbor  '--keep-alive'|'--with-keep-alive'|'--enable-keep-alive')
3c31841998-03-01Per Hedbor  DEFINES="-DKEEP_ALIVE $DEFINES" ;;
a8135b1996-11-12Per Hedbor  '--once') once=1 ;;
c6420b1998-06-02Henrik Grubbström (Grubba)  '--gdb') gdb=gdb once=1 ;;
3e7d3b1998-03-20Per Hedbor  '--program') program="$2" shift ;;
b1fca01996-11-12Per Hedbor  '--version')
c0ca361997-05-07Henrik Grubbström (Grubba)  echo Roxen Challenger 1.`expr $VERSION / 100`$BETA`expr $VERSION % 100`
b1fca01996-11-12Per Hedbor  exit 0 ;; '--help'|'-?')
82f5191997-03-02Per Hedbor  tput 'bold' 2>/dev/null cat << EOF
c6420b1998-06-02Henrik Grubbström (Grubba) Syntax: $0 [--version] [--config-dir=DIR] [--log-dir=DIR] [-DDEFINE] [--threads] [--no-threads] [--profile] [--keep-alive] [--once] [--gdb] [--program=PROGRAM] [--help]
3c31841998-03-01Per Hedbor This command will start the Roxen server.
82f5191997-03-02Per Hedbor If the configuration dir is set, a different set of debuglogfiles will be used. The environment variable ROXEN_ARGS can be used to specify the default arguments. EOF tput 'rmso' 2>/dev/null
b1fca01996-11-12Per Hedbor  exit 0 ;; *) pass="$pass $1"
5e87b41997-04-09Henrik Grubbström (Grubba)  ;;
b1fca01996-11-12Per Hedbor  esac shift
82f5191997-03-02Per Hedbor  done } ####### END PREAMBLE parse_args $@
b1fca01996-11-12Per Hedbor 
82f5191997-03-02Per Hedbor if [ ! "X$ROXEN_ARGS" = "X" ]; then echo $$: Using $ROXEN_ARGS from ROXEN_ARGS. parse_args $ROXEN_ARGS fi
d1ff621997-07-24Marcus Comstedt if [ ! "X$pass" = "X" ] ; then set -- $pass ;fi
b1fca01996-11-12Per Hedbor 
82f5191997-03-02Per Hedbor echo $$: Starting the Roxen Challenger World Wide Web server.
b1fca01996-11-12Per Hedbor  ./mkdir -p $LOGDIR/debug/
59f64b1997-01-27Per Hedbor if [ -z "$debug" ] ; then
fc2fcf1997-04-13Per Hedbor  DEBUG="-DMODULE_DEBUG";
59f64b1997-01-27Per Hedbor else
4dfffc1998-07-27Martin Stjernholm  DEBUG="-DDEBUG -DMODULE_DEBUG"
59f64b1997-01-27Per Hedbor fi
a8135b1996-11-12Per Hedbor if [ -z "$once" ] ; then
13c5481998-07-02Henrik Grubbström (Grubba)  cat << oo Using configuration from $DIR, storing the debug log in $LOGDIR/debug/$FILES.1 You can use the configuration interface in the server to get debug info. oo # Try to get rid of some fd's. # Some /bin/sh's have problems detaching otherwise. exec >/dev/null exec 2>/dev/null exec </dev/null
9c353a1997-08-23Henrik Grubbström (Grubba)  (while : ; do echo $$: "Server restart at `date`" echo $$: "Debug log in $LOGDIR/debug/$FILES.1" rotate $LOGDIR/debug/$FILES
82f5191997-03-02Per Hedbor 
9c353a1997-08-23Henrik Grubbström (Grubba)  start_roxen 2>>$LOGDIR/debug/$FILES.1 1>&2
82f5191997-03-02Per Hedbor 
7cb64f1998-01-17Henrik Grubbström (Grubba)  exitcode="$?"
b1fca01996-11-12Per Hedbor 
7cb64f1998-01-17Henrik Grubbström (Grubba)  if [ "$exitcode" -eq "0" ] ; then # Clean shutdown. echo $$: "Roxen shutdown." exit 0 fi if [ "$exitcode" -lt "0" ] ; then # Signal death. echo $$: "Roxen died of signal $exitcode. Restarting..." else # Restart. Sleep a few seconds before restarting. echo $$: Roxen died. Restarting in 5 seconds... sleep 5
b1fca01996-11-12Per Hedbor  fi
9c353a1997-08-23Henrik Grubbström (Grubba)  done
b1fca01996-11-12Per Hedbor 
9c353a1997-08-23Henrik Grubbström (Grubba)  echo $$: Not Reached "famous last words"
b1fca01996-11-12Per Hedbor 
9c353a1997-08-23Henrik Grubbström (Grubba)  ) < /dev/null > $LOGDIR/debug/start_$FILES.output 2>&1 &
82f5191997-03-02Per Hedbor 
a8135b1996-11-12Per Hedbor else
82f5191997-03-02Per Hedbor  echo $$: "Server restart at `date`"
4019f81997-03-01Per Hedbor  start_roxen
a8135b1996-11-12Per Hedbor fi
fc2fcf1997-04-13Per Hedbor