b1fca01996-11-12Per Hedbor #!/bin/sh
fd12951997-09-07Henrik Grubbström (Grubba) #
39ed8c2000-08-31Fredrik Noring # $Id: start,v 1.124 2000/08/31 11:35:00 noring Exp $ ### If --silent-start is given as the first argument, ### nothing will be printed to stdout by the script. if [ "x$1" = "x--silent-start" ] then SILENT_START="y" shift fi
67549e1999-09-05Per Hedbor 
05783b1999-09-11Martin Stjernholm pre="`echo \" $$ \" | sed -e 's/\(.........\)\(.*\)/\1/g'` :"
b796b51998-11-18Per Hedbor 
ff3b9a2000-08-09Per Hedbor dp() {
39ed8c2000-08-31Fredrik Noring  if [ "x$SILENT_START" = "xy" ] then :; else echo "$pre" "$@" 2>&1 fi
ff3b9a2000-08-09Per Hedbor }
a01fd92000-08-09Per Hedbor # Breaks on linux when using symlinks. dn="`dirname $0`" case "$dn" in ""|".") ;; *)
ff3b9a2000-08-09Per Hedbor  dp "Changing current directory to '$dn' (now `pwd`)"
a01fd92000-08-09Per Hedbor  cd $dn
ff3b9a2000-08-09Per Hedbor  dp "Got new directory as `pwd`"
a01fd92000-08-09Per Hedbor  ;; esac
0a4af81998-11-28Per Hedbor 
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
7c6da61998-11-01Henrik Grubbström (Grubba) extra_args=""
f292242000-03-24Henrik Grubbström (Grubba) VARDIR=../var/ LOCALDIR=../local/ # Make LOCALDIR an absolute path
a7b8d72000-03-24Henrik Grubbström (Grubba) if test -d $LOCALDIR/.; then
4bcae62000-03-24Henrik Grubbström (Grubba)  LOCALDIR=`cd $LOCALDIR; pwd`
64209f2000-03-24Henrik Grubbström (Grubba) else :; fi
49fff32000-01-27Henrik Grubbström (Grubba) 
423fdd2000-04-01Henrik Grubbström (Grubba) if test -d $VARDIR/.; then :; else
ff3b9a2000-08-09Per Hedbor  dp "Creating directory $VARDIR"
423fdd2000-04-01Henrik Grubbström (Grubba)  mkdir $VARDIR || exit 1 fi
77868d2000-03-13Per Hedbor roxen_version() {
bb19782000-03-29Henrik Grubbström (Grubba)  VERSION="`sed <etc/include/version.h -e '/__roxen_version__/s/[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\)[^0-9]*/\1/p' -n | head -1`" BUILD="`sed <etc/include/version.h -e '/__roxen_build__/s/[^0-9]*\([0-9][0-9]*\)[^0-9]*/\1/p' -n | head -1`"
77868d2000-03-13Per Hedbor  echo $VERSION.$BUILD }
348d6c2000-08-30Martin Stjernholm fullpath() { ( IFS=: for path in $PATH ; do if [ -x "$path/$1" ] ; then full="$path/$1" break fi done test "x$full" != "x" && echo $full ) }
f292242000-03-24Henrik Grubbström (Grubba) pcdir="$VARDIR/`roxen_version`/precompiled/`uname -m`.`uname -r`"
9b1a122000-02-04Per Hedbor old_roxen_defines="$pcdir/old_roxen_defines" ./mkdir -p $pcdir
577d4c2000-04-03Per Hedbor chmod 1777 $pcdir
b1fca01996-11-12Per Hedbor 
14fd211998-11-28Henrik Grubbström (Grubba) # Default verbosity level. verbose=1
48eeb61999-08-06Peter Bortas # Do not default to using a relative path. roxendir="`pwd`"
1f66ab1998-11-22Henrik Grubbström (Grubba) 
d25ab72000-03-30Leif Stensson # Locate Pike binary.
348d6c2000-08-30Martin Stjernholm pike=`fullpath pike`
c90cc91999-04-22Per Hedbor if [ -x bin/pike ] ; then pike=$roxendir/bin/pike; fi if [ -x bin/roxen ] ; then pike=$roxendir/bin/roxen; fi
f292242000-03-24Henrik Grubbström (Grubba) if [ -x $LOCALDIR/bin/pike ] ; then pike=$LOCALDIR/bin/pike; fi if [ -x $LOCALDIR/bin/roxen ] ; then pike=$LOCALDIR/bin/roxen; fi
c90cc91999-04-22Per Hedbor if [ "x$PIKE" = "x" ]; then :; else
0224d42000-07-10Henrik Grubbström (Grubba)  if [ -x "$PIKE" ]; then pike="$PIKE";
348d6c2000-08-30Martin Stjernholm  else pikepath=`fullpath "$PIKE"` if [ "x$pikepath" != "x" ]; then pike="$pikepath"; else dp "$PIKE is not executable - ignored."; fi fi
c90cc91999-04-22Per Hedbor fi
3b1fab2000-02-17Per Hedbor  if [ x"$pike" = "x" ] ; then
ff3b9a2000-08-09Per Hedbor  dp "No pike binary found. Aborting."
3b1fab2000-02-17Per Hedbor  exit 1 fi if [ ! -f "$pike" ] ; then
ff3b9a2000-08-09Per Hedbor  dp "No pike binary found. Aborting."
3b1fab2000-02-17Per Hedbor  exit 1 fi
d25ab72000-03-30Leif Stensson # If environment file doesn't exist, try to create it. if
07030c2000-03-31Leif Stensson  test ! -f $LOCALDIR/environment && test -f bin/buildenv.pike
d25ab72000-03-30Leif Stensson then $pike bin/buildenv.pike fi # Set up environment if test -f $LOCALDIR/environment; then . $LOCALDIR/environment fi # Make sure $CLASSPATH contains the servlet stuff
9e12262000-08-02Marcus Comstedt CLASSPATH=java/classes${CLASSPATH:+:}$CLASSPATH for jar in java/classes/*.jar; do CLASSPATH="$jar:$CLASSPATH" done
d25ab72000-03-30Leif Stensson export CLASSPATH
b1e9fe1998-11-28Henrik Grubbström (Grubba) ####### BEGIN ARGUMENT PARSING
b1fca01996-11-12Per Hedbor 
2b19eb1999-08-20Per Hedbor 
491abc2000-08-17Per Hedbor DEFINES="$DEFINES -DRAM_CACHE"
2b19eb1999-08-20Per Hedbor 
c90cc91999-04-22Per 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
ff3b9a2000-08-09Per Hedbor # if [ $verbose -gt 0 ] ; then # dp "Solaris 2.5 or later detected. Using threads by default." # fi
72a4502000-03-10Martin Stjernholm  DEFINES="$DEFINES -DENABLE_THREADS"
c90cc91999-04-22Per Hedbor  fi fi
43583b1999-05-25Henrik Grubbström (Grubba) gdb=no
c90cc91999-04-22Per Hedbor 
08cf191999-09-06Per Hedbor remove_old_dot_o_files () {
ff3b9a2000-08-09Per Hedbor  dp "Removing old .o files ($1)"
9b1a122000-02-04Per Hedbor  find $pcdir -name '*.o' | xargs rm -f
08cf191999-09-06Per Hedbor }
b1fca01996-11-12Per Hedbor ## Parse all arguments.
82f5191997-03-02Per Hedbor ## GNU-style, long options only, except for -D, simply passed on.
7541211999-10-08Per Hedbor ARGS=""
82f5191997-03-02Per Hedbor parse_args() { while [ ! c"$1" = "c" ] ; do
b1fca01996-11-12Per Hedbor  case $1 in
4019f81997-03-01Per Hedbor  -D*) DEFINES="$DEFINES $1" ;;
08cf191999-09-06Per Hedbor  -l*)
0272d31999-11-03Henrik Grubbström (Grubba)  ARGS="$ARGS $1"
08cf191999-09-06Per Hedbor  ;;
82f5191997-03-02Per Hedbor # Used by the 'install' script
a413051998-08-10Per Hedbor  --truss) pike="truss $pike" ;;
df56361999-08-30Per Hedbor  --truss-c) pike="truss -c $pike" ;;
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  ;;
7c6da61998-11-01Henrik Grubbström (Grubba)  --pid-file=*) extra_args="$extra_args $1" ;;
8a788c1998-07-22David Hedbor  '--debug'|'--with-debug'|'--enable-debug')
59f64b1997-01-27Per Hedbor  debug=1 ;;
8edfa31998-08-20Per Hedbor  '--without-debug') debug=-1 ;;
8a788c1998-07-22David Hedbor  '--fd-debug'|'--with-fd-debug'|'--enable-fd-debug')
cc4fdd1998-03-26Per Hedbor  DEFINES="-DFD_DEBUG $DEFINES" ;;
491abc2000-08-17Per Hedbor  '--without-ram-cache'|'--disable-ram-cache') DEFINES="`echo $DEFINES | sed -e 's/-DRAM_CACHE//g'`" ;; '--without-ram-cache-stat'|'--disable-ram-cache-stat') DEFINES="`-DRAM_CACHE_ASUME_STATIC_CONTENT`" ;;
67549e1999-09-05Per Hedbor  '--dump-debug'|'--with-dump-debug'|'--enable-dump-debug') DEFINES="-DDUMP_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')
72a4502000-03-10Martin Stjernholm  DEFINES="`echo $DEFINES | sed -e 's/-DENABLE_THREADS//g'`"
3c31841998-03-01Per Hedbor  ;;
2b19eb1999-08-20Per Hedbor  '--no-keep-alive'|'--without-keep-alive'|'--disable-keep-alive')
72a4502000-03-10Martin Stjernholm  DEFINES="`echo $DEFINES | sed -e 's/-DKEEP_ALIVE//g'`"
2b19eb1999-08-20Per Hedbor  ;;
8edfa31998-08-20Per Hedbor  '--with-profile'|'--profile')
3c31841998-03-01Per Hedbor  DEFINES="-DPROFILE $DEFINES" ;;
8edfa31998-08-20Per Hedbor  '--with-file-profile'|'--file-profile') DEFINES="-DPROFILE -DFILE_PROFILE $DEFINES" ;;
8a788c1998-07-22David Hedbor  '--keep-alive'|'--with-keep-alive'|'--enable-keep-alive')
3c31841998-03-01Per Hedbor  DEFINES="-DKEEP_ALIVE $DEFINES" ;;
14fd211998-11-28Henrik Grubbström (Grubba)  '--quiet'|'-q') verbose=0 ;; '--verbose'|'-v') verbose=2 debug=1 ;;
2213981999-09-05Per Hedbor  '--remove-dumped')
77868d2000-03-13Per Hedbor  remove_dumped=1;
2213981999-09-05Per Hedbor  ;;
a8135b1996-11-12Per Hedbor  '--once') once=1 ;;
cbced91998-11-06Marcus Comstedt # Misspelling --once might give undesirable results, so let's accept # some "creative" spellings... :-) '--onve'|'--onec'|'--onev') once=1 ;;
c6420b1998-06-02Henrik Grubbström (Grubba)  '--gdb') gdb=gdb once=1 ;;
3e7d3b1998-03-20Per Hedbor  '--program') program="$2"
0a4af81998-11-28Per Hedbor  once=1
3e7d3b1998-03-20Per Hedbor  shift ;;
b796b51998-11-18Per Hedbor  '--cd') cd_to="$2"
b1e9fe1998-11-28Henrik Grubbström (Grubba)  # Use the absolute path... roxendir="`pwd`"
0a4af81998-11-28Per Hedbor  once=1
b796b51998-11-18Per Hedbor  shift ;;
bcdd9d1999-12-13Per Hedbor  -r*|-d*|-t*|-l*|-w*)
7541211999-10-08Per Hedbor  # Argument passed along to Pike. ARGS="$ARGS $1" ;; -D*|-M*|-I*|-P*)
61c0ca1998-11-28Henrik Grubbström (Grubba)  # Argument passed along to Pike. DEFINES="$DEFINES $1" ;;
b1fca01996-11-12Per Hedbor  '--version')
6a57751999-08-06Henrik Grubbström (Grubba)  if [ -f base_server/roxen.pike ]; then
77868d2000-03-13Per Hedbor  echo "Roxen `roxen_version`"
6a57751999-08-06Henrik Grubbström (Grubba)  exit 0 else echo 'base_server/roxen.pike not found!' exit 1 fi
b1fca01996-11-12Per Hedbor  ;; '--help'|'-?')
ac54c71999-09-10Martin Stjernholm  sed -e "s/\\.B/`tput 'bold' 2>/dev/null`/g" -e "s/B\\./`tput 'sgr0' 2>/dev/null`/g" << EOF
8edfa31998-08-20Per Hedbor .BThis command will start the Roxen serverB.. The environment variable .BROXEN_ARGSB. can be used to specify
82f5191997-03-02Per Hedbor the default arguments.
8edfa31998-08-20Per Hedbor  .BArguments:B.
c083c21998-09-19Henrik Grubbström (Grubba)  .B--versionB.: Output version information.
8edfa31998-08-20Per Hedbor 
aa5b941998-11-28Henrik Grubbström (Grubba)  .B--help -?B.: This information.
2213981999-09-05Per Hedbor  .B--remove-dumpedB.: Remove all dumped code, thus forcing a recompile.
aa5b941998-11-28Henrik Grubbström (Grubba)  .B--verbose -vB.: Enable more verbose messages. .B--quiet -qB.: Disable most of the messages.
8edfa31998-08-20Per Hedbor 
c083c21998-09-19Henrik Grubbström (Grubba)  .B--log-dir=DIRB.: Set the log directory. Defaults to .B../logsB..
8edfa31998-08-20Per Hedbor 
aa5b941998-11-28Henrik Grubbström (Grubba)  .B--config-dir=DIRB.: Use an alternate configuration directory.
c083c21998-09-19Henrik Grubbström (Grubba)  Defaults to .B../configurationB..
8edfa31998-08-20Per Hedbor 
39ed8c2000-08-31Fredrik Noring  .B--silent-startB.: Inhibits output to stdout. If used, this argument must be the first one.
491abc2000-08-17Per Hedbor  .B--without-ram-cacheB.: Do not use an in-RAM cache to speed things up. Saves RAM at the cost of speed. .B--without-ram-cache-statB.: Disable the stat that is usualy done for files in the ram cache to ensure that they are not changed before they are sent. Improves performance at the cost of constant aggrevation if the site is edited. Useful for truly static sites.
c083c21998-09-19Henrik Grubbström (Grubba)  .B--with-threadsB.: If threads are available, use them.
8edfa31998-08-20Per Hedbor 
e6a1712000-02-02Per Hedbor  .B--without-threadsB.: Even if threads are enabled by default,
c083c21998-09-19Henrik Grubbström (Grubba)  disable them.
8edfa31998-08-20Per Hedbor 
c083c21998-09-19Henrik Grubbström (Grubba)  .B--with-profileB.: Store runtime profiling information on a directory basis. This information is not saved on permanent storage, it is only available until the next server restart This will enable a new 'action' in the
a6ef1f2000-03-28Johan Sundström  administration interface
8edfa31998-08-20Per Hedbor 
e6a1712000-02-02Per Hedbor  .B--with-file-profileB.: Like .B--with-profileB., but save information
c083c21998-09-19Henrik Grubbström (Grubba)  for each and every file.
8edfa31998-08-20Per Hedbor 
e6a1712000-02-02Per Hedbor  .B--with-keep-aliveB.: Enable keep alive in the HTTP protocol module. This is the default. Some clients might have problems
2b19eb1999-08-20Per Hedbor  with keep-alive.
e6a1712000-02-02Per Hedbor  .B--without-keep-aliveB.: Disable keep alive in the HTTP protocol module. Some clients might have
2b19eb1999-08-20Per Hedbor  problems with keep-alive.
8edfa31998-08-20Per Hedbor 
c083c21998-09-19Henrik Grubbström (Grubba)  .B--onceB.: Run the server only once, in the foreground. This is very useful when debugging.
8edfa31998-08-20Per Hedbor 
c083c21998-09-19Henrik Grubbström (Grubba)  .B--gdbB.: Run the server in gdb. Implies .B--onceB..
8edfa31998-08-20Per Hedbor 
c083c21998-09-19Henrik Grubbström (Grubba)  .B--programB.: Start a different program with the roxen
e6a1712000-02-02Per Hedbor  Pike. As an example, .B./start --program bin/install.pikeB. will start the installation program normally
c083c21998-09-19Henrik Grubbström (Grubba)  started with .B./installB.
8edfa31998-08-20Per Hedbor 
c083c21998-09-19Henrik Grubbström (Grubba)  .B--with-debugB.: Enable debug
8edfa31998-08-20Per Hedbor 
c083c21998-09-19Henrik Grubbström (Grubba)  .B--without-debugB.: Disable all debug
e6a1712000-02-02Per Hedbor 
c083c21998-09-19Henrik Grubbström (Grubba)  .B--with-fd-debugB.: Enable FD debug.
8edfa31998-08-20Per Hedbor 
67549e1999-09-05Per Hedbor  .B--with-dump-debugB.: Enable dump debug.
c083c21998-09-19Henrik Grubbström (Grubba)  .B--trussB.: (Solaris only). Run the server under
e6a1712000-02-02Per Hedbor  truss, shows .BallB. system calls. This is extremely noisy, and is not intented for
c083c21998-09-19Henrik Grubbström (Grubba)  anything but debug.
8edfa31998-08-20Per Hedbor 
67549e1999-09-05Per Hedbor  .B--truss-cB.: (Solaris only). Run the server under truss -c, shows times for all system calls
e6a1712000-02-02Per Hedbor  on exit. This is not intented for anything
67549e1999-09-05Per Hedbor  but debug. Slows the server down.
c083c21998-09-19Henrik Grubbström (Grubba)  .B--pid-file=<file>B.: Store the roxen and startscript pids in this file. Defaults to .B/tmp/roxen_$UIDB.
e6a1712000-02-02Per Hedbor 
8edfa31998-08-20Per Hedbor  .BArguments passed to pike:B.
c083c21998-09-19Henrik Grubbström (Grubba)  .B-DDEFINEB.: Define the symbol .BDEFINEB..
8edfa31998-08-20Per Hedbor 
61c0ca1998-11-28Henrik Grubbström (Grubba)  .B-d<level>B.: Set the runtime Pike debug to level.
e6a1712000-02-02Per Hedbor  This only works if Pike is compiled
c083c21998-09-19Henrik Grubbström (Grubba)  with debug.
8edfa31998-08-20Per Hedbor 
bcdd9d1999-12-13Per Hedbor  .B-rtB.: Enable runtime typechecking. Things will run more slowly, but it is very useful while developing code. Enabled when starting roxen with --debug .B-rTB.: Enable strict types.
e6a1712000-02-02Per Hedbor  Same as adding #pragma strict-types
bcdd9d1999-12-13Per Hedbor  to all files. This enables more strict type-checking, things that are normally permitted (such as calling a mixed value, or assigning a typed object variable with an untyped object) will generate warnings. Useful for module and roxen core developers, but not so useful for the occasional pike-script-writer. Enabled when starting roxen with --debug
c083c21998-09-19Henrik Grubbström (Grubba)  .B-s<size>B.: Set the stack size.
8edfa31998-08-20Per Hedbor 
61c0ca1998-11-28Henrik Grubbström (Grubba)  .B-M<path>B.: Add the path to the Pike module path. .B-I<path>B.: Add the path to the Pike include path.
8edfa31998-08-20Per Hedbor 
61c0ca1998-11-28Henrik Grubbström (Grubba)  .B-P<path>B.: Add the path to the Pike program path.
8edfa31998-08-20Per Hedbor 
9e8fac2000-02-08Martin Stjernholm  .B-dtB.: Turn off tail recursion optimization.
adae241998-09-18Per Hedbor 
61c0ca1998-11-28Henrik Grubbström (Grubba)  .B-tB.: Turn on Pike level tracing.
8edfa31998-08-20Per Hedbor 
e6a1712000-02-02Per Hedbor  .B-t<level>B.: Turn on more Pike tracing. This only
61c0ca1998-11-28Henrik Grubbström (Grubba)  works if Pike is compiled with debug.
8edfa31998-08-20Per Hedbor 
0272d31999-11-03Henrik Grubbström (Grubba)  .B-wB.: Turn on Pike warnings.
8edfa31998-08-20Per Hedbor  .BEnvironment variables:B.
e6a1712000-02-02Per Hedbor  .BLANGB.: Used to determine the default locale
a6ef1f2000-03-28Johan Sundström  in the administration interface and logs.
c083c21998-09-19Henrik Grubbström (Grubba)  .BROXEN_CONFIGDIRB.: Same as .B--config-dir=... B. .BROXEN_PID_FILEB.: Same as .B--pid-file=... B. .BROXEN_LANGB.: The default language for all language
7de5181998-11-22Per Hedbor  related tags. Defaults to 'en' for english.
8edfa31998-08-20Per Hedbor 
82f5191997-03-02Per Hedbor 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 }
ff3b9a2000-08-09Per Hedbor if [ ! "X$ROXEN_ARGS" = "X" ]; then parse_args $ROXEN_ARGS fi
82f5191997-03-02Per Hedbor parse_args $@
b1fca01996-11-12Per Hedbor 
ff3b9a2000-08-09Per Hedbor # The work has already been done above, but the debug printout is better # to have _after_ parse_args (consider --help and --version)
82f5191997-03-02Per Hedbor if [ ! "X$ROXEN_ARGS" = "X" ]; then
14fd211998-11-28Henrik Grubbström (Grubba)  if [ $verbose -gt 0 ]; then
ff3b9a2000-08-09Per Hedbor  dp "Used $ROXEN_ARGS from ROXEN_ARGS."
14fd211998-11-28Henrik Grubbström (Grubba)  else :; fi
82f5191997-03-02Per Hedbor fi
ff3b9a2000-08-09Per Hedbor  if uname | grep 'SunOS' >/dev/null 2>&1; then if uname -r | grep '5\.[5-9]' >/dev/null 2>&1; then if [ $verbose -gt 0 ] ; then dp "Solaris 2.5 or later was detected. Threads enabled by default." fi fi fi
d1ff621997-07-24Marcus Comstedt if [ ! "X$pass" = "X" ] ; then set -- $pass ;fi
b1fca01996-11-12Per Hedbor 
b1e9fe1998-11-28Henrik Grubbström (Grubba) ####### END ARGUMENT PARSING ####### BEGIN PIKE OPTIONS # Roxen will create files as the initial user, # which it expects to be able to read as the run-time user. umask 022
2587671999-04-24Martin Stjernholm if [ "x$PIKE_NO_DEFAULT_PATHS" = "x" ]; then # Pike default Master-program if [ "x$PIKE_MASTER" = "x" ]; then if [ -f lib/master.pike ]; then
348d6c2000-08-30Martin Stjernholm  DEFINES="$DEFINES -m$roxendir/lib/master.pike"
2587671999-04-24Martin Stjernholm  elif [ -f lib/pike/master.pike ]; then
348d6c2000-08-30Martin Stjernholm  DEFINES="$DEFINES -m$roxendir/lib/pike/master.pike"
2587671999-04-24Martin Stjernholm  fi else # This is useful when using several different Pikes. # 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. DEFINES="$DEFINES -m$PIKE_MASTER"
b1e9fe1998-11-28Henrik Grubbström (Grubba)  fi fi # Extra module-path if [ -d etc/modules ]; then DEFINES="$DEFINES -M$roxendir/etc/modules" fi # Extra include-path if [ -d etc/include ]; then DEFINES="$DEFINES -I$roxendir/etc/include" fi
f292242000-03-24Henrik Grubbström (Grubba) if [ -d $LOCALDIR/include ]; then DEFINES="$DEFINES -I$LOCALDIR/include"
77868d2000-03-13Per Hedbor fi
b1e9fe1998-11-28Henrik Grubbström (Grubba) # Extra include-path (2) if [ -d base_server ]; then DEFINES="$DEFINES -I$roxendir/base_server" fi
f292242000-03-24Henrik Grubbström (Grubba) if [ -d $LOCALDIR/base_server ]; then DEFINES="$DEFINES -I$LOCALDIR/base_server -P$LOCALDIR/base_server"
77868d2000-03-13Per Hedbor fi
b1e9fe1998-11-28Henrik Grubbström (Grubba) # Extra program-path DEFINES="$DEFINES -P`pwd`" # Support for adding local pike-modules
f292242000-03-24Henrik Grubbström (Grubba) if [ -d $LOCALDIR/etc/. ]; then
b1e9fe1998-11-28Henrik Grubbström (Grubba)  # Extra module-path
f292242000-03-24Henrik Grubbström (Grubba)  if [ -d $LOCALDIR/etc/modules/. ]; then DEFINES="$DEFINES -M$LOCALDIR/etc/modules"
b1e9fe1998-11-28Henrik Grubbström (Grubba)  fi # Extra include-path
f292242000-03-24Henrik Grubbström (Grubba)  if [ -d $LOCALDIR/etc/include ]; then DEFINES="$DEFINES -I$LOCALDIR/etc/include"
b1e9fe1998-11-28Henrik Grubbström (Grubba)  fi # Extra program-path
f292242000-03-24Henrik Grubbström (Grubba)  DEFINES="$DEFINES -P$LOCALDIR/etc"
b1e9fe1998-11-28Henrik Grubbström (Grubba) fi # Extra kludge for HPUX # HPUX doesn't like group 60001(nobody) if uname | grep 'HP-UX' >/dev/null 2>&1; then
14fd211998-11-28Henrik Grubbström (Grubba)  if [ $verbose -gt 0 ]; then
ff3b9a2000-08-09Per Hedbor  dp "WARNING: Applying kludge for HPUX. (see base_server/privs.pike)"
14fd211998-11-28Henrik Grubbström (Grubba)  else :; fi
b1e9fe1998-11-28Henrik Grubbström (Grubba)  DEFINES="$DEFINES -DHPUX_KLUDGE" fi
0272d31999-11-03Henrik Grubbström (Grubba)  case "x$debug" in "x")
d12de01999-12-21Per Hedbor  DEBUG="-DMODULE_DEBUG "
bcdd9d1999-12-13Per Hedbor  ARGS="$ARGS -w"
0272d31999-11-03Henrik Grubbström (Grubba)  ;; "x-1") DEBUG="" ;; "x1")
9e8fac2000-02-08Martin Stjernholm  DEBUG="-DDEBUG -DMODULE_DEBUG"
0272d31999-11-03Henrik Grubbström (Grubba)  ARGS="$ARGS -w" ;; esac DEFINES="$DEBUG $DEFINES"
b1e9fe1998-11-28Henrik Grubbström (Grubba) ####### END PIKE OPTIONS
38e43b1998-09-12Henrik Grubbström (Grubba)  # # Some useful functions # rotate () { b=5; for a in 4 3 2 1 ; do mv -f $1.$a $1.$b 2> /dev/null; b=$a; done }
0259c42000-08-31Martin Stjernholm signal_exit() { dp "Start script terminated." if [ "x$ROXEN_PID" != "x" ]; then kill $ROXEN_PID 2>/dev/null while kill -0 $ROXEN_PID 2>/dev/null; do sleep 1 done fi dp "Roxen shutdown." exit 0 }
38e43b1998-09-12Henrik Grubbström (Grubba) start_roxen() {
77868d2000-03-13Per Hedbor  if [ x$remove_dumped = x1 ] ; then remove_old_dot_o_files "user request" fi
e6a1712000-02-02Per Hedbor  if [ "x$DIR" != "x../configurations/" ] ; then
7541211999-10-08Per Hedbor  args="$DEFINES $ARGS $program --config-dir=$DIR $pass"
b796b51998-11-18Per Hedbor  else
7541211999-10-08Per Hedbor  args="$DEFINES $ARGS $program $pass"
b796b51998-11-18Per Hedbor  fi
e6a1712000-02-02Per Hedbor  if [ x$cd_to != x ] ; then
b796b51998-11-18Per Hedbor  cd $cd_to fi
38e43b1998-09-12Henrik Grubbström (Grubba)  if [ "x$gdb" = "xno" ]; then
14fd211998-11-28Henrik Grubbström (Grubba)  if [ $verbose -gt 0 ]; then
0dbd692000-02-17Martin Stjernholm  if [ $verbose -gt 1 -o -z "$once" ] ; then
ff3b9a2000-08-09Per Hedbor  dp "Executing $pike $args $@"|sed -e "s!`pwd`!.!g"
9245702000-02-16Per Hedbor  else
ff3b9a2000-08-09Per Hedbor  dp "Using '$pike'"|sed -e "s!`pwd`!.!g"
9245702000-02-16Per Hedbor  fi fi
0259c42000-08-31Martin Stjernholm  trap signal_exit 2 15 trap "" 1 if [ "x$once" = "x" ]; then $pike $args "$@" 2>>$LOGDIR/debug/$FILES.1 1>&2 & ROXEN_PID=$! dp "Roxen server pid $ROXEN_PID." wait $! 2>/dev/null 1>&2 exitcode="$?" ROXEN_PID="" else $pike $args "$@" 2>&1 fi
38e43b1998-09-12Henrik Grubbström (Grubba)  else echo >.gdbinit handle SIGPIPE nostop noprint pass echo >>.gdbinit handle SIGUSR1 nostop noprint pass echo >>.gdbinit handle SIGUSR2 nostop noprint pass
72a4502000-03-10Martin Stjernholm  echo >>.gdbinit handle SIGLWP nostop noprint pass
348d6c2000-08-30Martin Stjernholm  firstline=`head -1 "$pike" 2>/dev/null` if expr "x$firstline" : 'x#! */.*' >/dev/null; then
0259c42000-08-31Martin Stjernholm  # Looks like a script. gdb will not grok it, so we try passing
348d6c2000-08-30Martin Stjernholm  # --gdb to it instead (which works in the special case of the
0259c42000-08-31Martin Stjernholm  # bin/pike script that is built by the top level Makefile in the
348d6c2000-08-30Martin Stjernholm  # Pike source tree). dp "Executing $pike --gdb $args $@" $pike --gdb $args "$@" else dp "Executing gdb $pike $args $@" echo >>.gdbinit run $args $@ gdb $pike fi
38e43b1998-09-12Henrik Grubbström (Grubba)  rm .gdbinit fi }
0259c42000-08-31Martin Stjernholm 
38e43b1998-09-12Henrik Grubbström (Grubba) # # Now do the stuff #
2213981999-09-05Per Hedbor PIKEVERSION=`$pike --version 2>&1`
e6a1712000-02-02Per Hedbor if [ "$program" = "base_server/roxenloader.pike" ] ; then
49fff32000-01-27Henrik Grubbström (Grubba)  if [ "`cat $old_roxen_defines 2>/dev/null`" != "$PIKEVERSION $DEFINES" ] ; then
7aad022000-02-14Martin Stjernholm  remove_old_dot_o_files "defines or pike version changed"
7541211999-10-08Per Hedbor  fi
49fff32000-01-27Henrik Grubbström (Grubba)  echo "$PIKEVERSION $DEFINES" > $old_roxen_defines
7541211999-10-08Per Hedbor fi
2213981999-09-05Per Hedbor 
a8135b1996-11-12Per Hedbor if [ -z "$once" ] ; then
14fd211998-11-28Henrik Grubbström (Grubba)  if [ $verbose -gt 0 ]; then
ff3b9a2000-08-09Per Hedbor  dp "Starting the Roxen World Wide Web server."
14fd211998-11-28Henrik Grubbström (Grubba)  else :; fi ./mkdir -p $LOGDIR/debug/
0a4af81998-11-28Per Hedbor 
14fd211998-11-28Henrik Grubbström (Grubba)  if [ $verbose -gt 0 ]; then
0259c42000-08-31Martin Stjernholm  dp "Using configuration from $DIR, storing the debug log in $LOGDIR/debug/$FILES.1." dp "You can use the administration interface in the server to get debug info."
14fd211998-11-28Henrik Grubbström (Grubba)  else :; fi
13c5481998-07-02Henrik Grubbström (Grubba) 
0259c42000-08-31Martin Stjernholm  if ( ( # Do not use the prefix since it contains the pid of the script # we were forked from and not the one of this fork, which is # confusing. Can't rebuild $pre from $$ here, since some sh's # seems to cache it, causing it to be wrong here. pre="" exec 3>&- while : ; do if test -d "$LOGDIR/debug/."; then :; else # Avoid infinite loop if the debug directory is deleted. # Thanks to Emils Klotins <emils@dot.lv> for reporting it. if ./mkdir -p "$LOGDIR/debug/"; then :; else dp "Failed to create log directory $LOGDIR/debug/." exit 1 fi
12017a2000-06-05Emils Klotins  fi
49fff32000-01-27Henrik Grubbström (Grubba) 
0259c42000-08-31Martin Stjernholm  dp "Server start at `date`" dp "Debug log in $LOGDIR/debug/$FILES.1" rotate $LOGDIR/debug/$FILES start_roxen $extra_args
49fff32000-01-27Henrik Grubbström (Grubba) 
0259c42000-08-31Martin Stjernholm  if [ "$exitcode" -eq "0" ] ; then # Clean shutdown. dp "Roxen shutdown." exit 0 fi if [ "$exitcode" -lt "0" ] ; then # Signal death. dp "Roxen died of signal $exitcode. Restarting..." else dp "Roxen down. Restarting." fi done ) & dp "Forked start script, pid $!." >&3 ) 3>&1 </dev/null >$LOGDIR/debug/start_$FILES.output 2>&1; then :
49fff32000-01-27Henrik Grubbström (Grubba)  else
ff3b9a2000-08-09Per Hedbor  dp 'Failed to spawn subshell. -- Permission problem?'
49fff32000-01-27Henrik Grubbström (Grubba)  exit 1 fi
0259c42000-08-31Martin Stjernholm  # Try to get rid of some fd's. # Some /bin/sh's have problems detaching otherwise. exec >/dev/null exec </dev/null
a8135b1996-11-12Per Hedbor else
0259c42000-08-31Martin Stjernholm  start_roxen $extra_args
a8135b1996-11-12Per Hedbor fi