b1fca01996-11-12Per Hedbor #!/bin/sh
fd12951997-09-07Henrik Grubbström (Grubba) #
9f87e62013-01-22Henrik Grubbström (Grubba) # $Id$
39ed8c2000-08-31Fredrik Noring  ### If --silent-start is given as the first argument, ### nothing will be printed to stdout by the script.
270fdc2000-12-30Per Hedbor if [ "x$1" = "x--silent-start" ] ; then SILENT_START="y" shift
39ed8c2000-08-31Fredrik Noring fi
67549e1999-09-05Per Hedbor 
196c3f2000-11-16Per Hedbor check_owner() { gargs=''
8cc1802001-01-03Per Hedbor  if [ -w / ] ; then
196c3f2000-11-16Per Hedbor  # Shall we change uid/gid? num=`grep --help 2>&1|grep gnu|wc -l` num=`echo $num` if [ x"$num" = x1 ] ; then gargs='-a' fi ugid=`grep $gargs "='User'>" $DIR/Global_Variables 2>/dev/null\ | sed -e 's/.*<str>//' -e 's,</str>.*,,'`
bb303c2014-01-24Henrik Grubbström (Grubba)  if [ ! "x$ugid" = x ] ; then
196c3f2000-11-16Per Hedbor  dp "Doing uid change to $ugid" oifs="$IFS";IFS=':';set $ugid;IFS="$oifs"
4fcfa32001-03-27Martin Stjernholm  if [ ! "x$2" = x ]; then
bddbb32004-08-11Henrik Grubbström (Grubba)  ok=`ls -lgd . 2>/dev/null | grep "$2" |wc -l`
4fcfa32001-03-27Martin Stjernholm  ok=`echo $ok` if [ "x$ok" = x1 ] ; then dp "The server directory is already readable by group $2" else
bddbb32004-08-11Henrik Grubbström (Grubba)  ok=`ls -ngd . 2>/dev/null | grep "$2" |wc -l` ok=`echo $ok` if [ "x$ok" = x1 ] ; then dp "The server directory is already readable by group $2" else chgrp -R "$2" . chmod -R g+r . fi
4fcfa32001-03-27Martin Stjernholm  fi fi
b7b6422003-03-03Martin Stjernholm  change_owner "$1" "$2" "$DIR" "$VARDIR" "$LOGDIR"
196c3f2000-11-16Per Hedbor  fi fi }
a01fd92000-08-09Per Hedbor # Breaks on linux when using symlinks.
4f10062003-07-11Jonas Wallden dn="`dirname "$0"`"
a01fd92000-08-09Per Hedbor case "$dn" in ""|".") ;; *)
270fdc2000-12-30Per Hedbor  # dp is not used here since we cannot source bin/functions before we # are in the correct directory, for quite obvious reasons...
4c638d2001-03-20Fredrik Noring  if [ ! "$dn" = "`pwd`" ] then
edd8572017-01-19Jonas Walldén  echo " : Changing current directory to '$dn' (now `pwd`)" >&2
21ae4e2001-10-19Henrik Grubbström (Grubba)  cd "$dn"
edd8572017-01-19Jonas Walldén  echo " : Got new directory as `pwd`" >&2
4c638d2001-03-20Fredrik Noring  fi
a01fd92000-08-09Per Hedbor  ;; esac
0a4af81998-11-28Per Hedbor 
270fdc2000-12-30Per Hedbor . bin/functions
b1fca01996-11-12Per Hedbor # Can be set with '--config-dir=DIR'
a3a0ec2001-03-17Martin Stjernholm DIR=../configurations
c071372005-12-21Fredrik Noring if [ ! "x$ROXEN_CONFIGDIR" = "x" ] then DIR="$ROXEN_CONFIGDIR" fi
a3a0ec2001-03-17Martin Stjernholm LOGDIR=../logs
c071372005-12-21Fredrik Noring if [ ! "x$ROXEN_LOGDIR" = "x" ] then LOGDIR="$ROXEN_LOGDIR" fi
b1fca01996-11-12Per Hedbor FILES="default"
3e7d3b1998-03-20Per Hedbor program=base_server/roxenloader.pike
a3a0ec2001-03-17Martin Stjernholm VARDIR=../var LOCALDIR=../local
c071372005-12-21Fredrik Noring if [ ! "x$ROXEN_DATADIR" = "x" ] then VARDIR="$ROXEN_DATADIR"/var LOCALDIR="$ROXEN_DATADIR"/local if [ -d "$ROXEN_DATADIR"/license ] then ROXEN_LICENSEDIR="$ROXEN_DATADIR"/license else ROXEN_LICENSEDIR="$DIR"/_license fi export ROXEN_DATADIR ROXEN_LICENSEDIR fi export LOCALDIR LOGDIR VARDIR
d7d5dd2001-08-10Marcus Wellhardh SELF_TEST_DIR=etc/test
f292242000-03-24Henrik Grubbström (Grubba)  # Make LOCALDIR an absolute path
a7b8d72000-03-24Henrik Grubbström (Grubba) if test -d $LOCALDIR/.; then
21ae4e2001-10-19Henrik 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"
a3a0ec2001-03-17Martin Stjernholm  ./mkdir -p $VARDIR/ || exit 1
423fdd2000-04-01Henrik Grubbström (Grubba) fi
348d6c2000-08-30Martin Stjernholm 
b654ea2000-10-02Jonas Wallden pcdir="$VARDIR/`roxen_version`/precompiled/`uname -m | tr ' ' '_' `.`uname -r`"
9b1a122000-02-04Per Hedbor old_roxen_defines="$pcdir/old_roxen_defines"
21ae4e2001-10-19Henrik Grubbström (Grubba) ./mkdir -p "$pcdir" || exit 1 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) 
1490152001-08-06Martin Stjernholm # No debug by default. debug=-1
9f87e62013-01-22Henrik Grubbström (Grubba) # Don't attempt to stop a running server by default. stop="" # Attempt to start the server by default. start=1
d25ab72000-03-30Leif Stensson # Locate Pike binary.
270fdc2000-12-30Per Hedbor find_pike
d25ab72000-03-30Leif Stensson 
270fdc2000-12-30Per Hedbor # Source environment setup_environment
d25ab72000-03-30Leif Stensson 
b1e9fe1998-11-28Henrik Grubbström (Grubba) ####### BEGIN ARGUMENT PARSING
b1fca01996-11-12Per Hedbor 
2b19eb1999-08-20Per Hedbor 
3800d22015-04-28Jonas Walldén DEFINES="$DEFINES -DRAM_CACHE -DHTTP_COMPRESSION"
d1799d2010-10-13Stefan Wallström 
43583b1999-05-25Henrik Grubbström (Grubba) gdb=no
b253412011-03-21Martin Stjernholm valgrind=
09ecee2003-01-13Martin Stjernholm truss=
c90cc91999-04-22Per Hedbor 
9ae44d2015-05-06Henrik Grubbström (Grubba) daemonize=yes
e85a532002-12-16Henrik Grubbström (Grubba) remove_dumped_passed=no
a5acf42015-05-06Henrik Grubbström (Grubba) 
49693b2018-04-17Pontus Östlund module_hot_reload=
5b94a52018-04-19Pontus Östlund module_hot_reload_conf=
49693b2018-04-17Pontus Östlund 
08cf191999-09-06Per Hedbor remove_old_dot_o_files () {
af3dd82001-01-01Martin Nilsson  dp "Removing old precompiled files ($1)"
74e3902000-12-30Per Hedbor  # This really cannot be done from here anymore -- pass on an option # to roxenloader instead.
e85a532002-12-16Henrik Grubbström (Grubba)  # Make sure that the argument isn't duplicated for every restart...
1626542002-12-16Henrik Grubbström (Grubba)  if [ "x$remove_dumped_passed" = "xyes" ]; then :; else
e85a532002-12-16Henrik Grubbström (Grubba)  pass="$pass --remove-dumped" remove_dumped_passed=yes fi
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=""
ce78ab2012-09-20Henrik Grubbström (Grubba) # # Descriptions of some of the state variables set during argument processing. # # Variable Default # Value Description # ----------------------------------------------------------------- # debug -1 # -1 No debug. # 0 Module debug (Pike warnings + -DMODULE_DEBUG). # 1 Full debug (Pike warnings + -DDEBUG -DMODULE_DEBUG). # keep_mysql "" # "" Shut down mysqld between restarts. # 1 Do not touch mysqld on restart.
846a912017-09-29Henrik Grubbström (Grubba) # 2 --mysql-only mode.
ce78ab2012-09-20Henrik Grubbström (Grubba) # once "" # "" Loop the program until it exits with success (0). # 1 Verbose --once mode. # 2 Quiet --once mode. # pass "" # - Arguments to pass to the Pike program. # passhelp "" # "" Roxen is being started. # 1 A custom program has been specified with --program. # pidfile "$DIR/_roxen_pid"/"" # Defaults to "" if Roxen is not being started. # "" Do not generate a pid file or associated lock files. # other Create a pid file and associated lock files. # program "base_server/roxen_loader.pike" # - The Pike program to start.
846a912017-09-29Henrik Grubbström (Grubba) # start 1 # "" Do not attempt to start the server. # 1 Attempt to start or restart the server. # stop "" # "" --stop or --restart not specified. # 1 --stop or --restart specified.
ce78ab2012-09-20Henrik Grubbström (Grubba) # verbose 1 # 0 Quiet mode. # 1 Default verbosity. # 2 Verbose mode. #
846a912017-09-29Henrik Grubbström (Grubba) stop_mysql() { # Kill roxen mysql if it's running... if [ -f "$DIR/_mysql/mysql_pid" ] ; then if kill -0 `cat "$DIR/_mysql/mysql_pid"` >/dev/null 2>&1; then dp "Stopping MySQL/MariaDB..." if kill `cat "$DIR/_mysql/mysql_pid"`; then dp "Ok." else dp "Failed to stop MySQL/MariaDB." fi else dp "MySQL/MariaDB does not appear to be running." fi fi }
4ba8452001-01-31Per Hedbor setup_for_tests() {
cfdc332001-07-02Martin Nilsson  # Kill roxen mysql if it's running...
21ae4e2001-10-19Henrik Grubbström (Grubba)  if [ -f "$VARDIR/test_config/_mysql/mysql_pid" ] ; then kill `cat "$VARDIR/test_config/_mysql/mysql_pid"`
cfdc332001-07-02Martin Nilsson  fi
b5b1252001-06-30Martin Stjernholm  self_test=y
d7d5dd2001-08-10Marcus Wellhardh  DEFINES="-DRUN_SELF_TEST -DSELF_TEST_DIR=\"$SELF_TEST_DIR\" $DEFINES"
322d182018-04-13Henrik Grubbström (Grubba)  DEFINES="$DEFINES \"-M$SELF_TEST_DIR/modules\""
21ae4e2001-10-19Henrik Grubbström (Grubba)  rm -rf "$VARDIR/test_config"* DIR="$VARDIR/test_config" if [ -f "$SELF_TEST_DIR/scripts/setup.pike" ] ; then
365dd22012-09-27Henrik Grubbström (Grubba)  eval "\"$pike\" $PIKEARGS $DEFINES \"$SELF_TEST_DIR/scripts/setup.pike\" \"$SELF_TEST_DIR\" \"$VARDIR\""
d7d5dd2001-08-10Marcus Wellhardh  fi
f7e74e2001-09-20Martin Nilsson  once=${once:-1} debug=1
ae264c2004-03-25Martin Stjernholm  #remove_dumped=1
4ba8452001-01-31Per Hedbor }
82f5191997-03-02Per Hedbor parse_args() { while [ ! c"$1" = "c" ] ; do
00b8b02001-02-02Fredrik Noring  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  ;;
a413051998-08-10Per Hedbor  --truss)
09ecee2003-01-13Martin Stjernholm  truss="truss"
a413051998-08-10Per Hedbor  ;;
df56361999-08-30Per Hedbor  --truss-c)
09ecee2003-01-13Martin Stjernholm  truss="truss -c" ;; --strace) truss="strace"
df56361999-08-30Per Hedbor  ;;
b1fca01996-11-12Per Hedbor  --log-dir=*) LOGDIR=`echo $1 | sed -e 's/--log-dir=//'`
c071372005-12-21Fredrik Noring  export LOGDIR
b1fca01996-11-12Per Hedbor  ;;
567dac2001-03-23Per Hedbor  --debug-log=*) DEBUGLOG=`echo $1 | sed -e's/--debug-log=//'` ;;
b1fca01996-11-12Per Hedbor  --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=*)
a3a0ec2001-03-17Martin Stjernholm  pidfile=`echo $1 | sed -e 's/--pid-file=//'`
7c6da61998-11-01Henrik Grubbström (Grubba)  ;;
cdd9912000-10-30Per Hedbor  '--with-security'|'--enable-security') DEFINES="$DEFINES -DSECURITY" ;;
3f240b2001-09-04Honza Petrous  '--with-snmp-agent'|'--enable-snmp-agent') DEFINES="$DEFINES -DSNMP_AGENT" ;;
cdd9912000-10-30Per Hedbor 
8a788c1998-07-22David Hedbor  '--debug'|'--with-debug'|'--enable-debug')
59f64b1997-01-27Per Hedbor  debug=1 ;;
8edfa31998-08-20Per Hedbor  '--without-debug') debug=-1 ;;
1490152001-08-06Martin Stjernholm  '--module-debug'|'--with-module-debug'|'--enable-module-debug') debug=0 ;;
8a788c1998-07-22David Hedbor  '--fd-debug'|'--with-fd-debug'|'--enable-fd-debug')
cc4fdd1998-03-26Per Hedbor  DEFINES="-DFD_DEBUG $DEFINES" ;;
5655dc2001-06-06Per Hedbor  '--strip-backslash'|'--without-backslash'|'--strip-back-slash') DEFINES="-DSTRIP_BSLASH $DEFINES" ;;
9a05452001-10-04Per Hedbor  '--offline') DEFINES="-DNO_DNS -DOFFLINE $DEFINES" ;;
491abc2000-08-17Per Hedbor  '--without-ram-cache'|'--disable-ram-cache') DEFINES="`echo $DEFINES | sed -e 's/-DRAM_CACHE//g'`" ;;
d1799d2010-10-13Stefan Wallström  '--without-http-compression'|'--disable-http-compression') DEFINES="`echo $DEFINES | sed -e 's/-DHTTP_COMPRESSION//g'`" ;;
491abc2000-08-17Per Hedbor  '--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')
e1f8142015-04-28Jonas Walldén  echo "Thread support not optional -- ignoring $1" >&2
3c31841998-03-01Per 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" ;;
9ae44d2015-05-06Henrik Grubbström (Grubba)  '--without-daemon'|'--without-deamonize') daemonize=no ;;
561af82006-07-17Henrik Grubbström (Grubba)  '--generations='*) GENERATIONS=`echo $1 | sed -e 's/--generations=//'`
2a0a982006-11-15Anders Johansson  if test "$GENERATIONS" -gt 1; then :; else
561af82006-07-17Henrik Grubbström (Grubba)  echo "Invalid number of log generations: $GENERATIONS" >&2 echo "Using default: 5" >&2 GENERATIONS=5 fi ;; '--generations') GENERATIONS="$2" shift
2a0a982006-11-15Anders Johansson  if test "$GENERATIONS" -gt 1; then :; else
561af82006-07-17Henrik Grubbström (Grubba)  echo "Invalid number of log generations: $GENERATIONS" >&2 echo "Using default: 5" >&2 GENERATIONS=5 fi ;;
49693b2018-04-17Pontus Östlund  --module-hot-reload=*) if test "x$module_hot_reload" = "x"; then DEFINES="-DMODULE_HOT_RELOAD $DEFINES" fi mod=`echo $1 | sed -e 's/--module-hot-reload=//'` module_hot_reload="$mod $module_hot_reload" ;;
5b94a52018-04-19Pontus Östlund  --module-hot-reload-conf=*) mod=`echo $1 | sed -e 's/--module-hot-reload-conf=//'` module_hot_reload_conf="$mod $module_hot_reload_conf" ;;
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  ;;
c071372005-12-21Fredrik Noring  '--stop')
9f87e62013-01-22Henrik Grubbström (Grubba)  stop="TERM"; start=""; ;; '--restart') stop="TERM"; start=1; ;; '--signal') stop="$2" shift start="";
c071372005-12-21Fredrik Noring  ;;
fb49032001-05-16Per Hedbor 
a8135b1996-11-12Per Hedbor  '--once')
42581f2001-08-13Martin Stjernholm  once=${once:-1}
1490152001-08-06Martin Stjernholm  debug=0
a8135b1996-11-12Per Hedbor  ;;
cbced91998-11-06Marcus Comstedt # Misspelling --once might give undesirable results, so let's accept # some "creative" spellings... :-)
fb49032001-05-16Per Hedbor  '--onve'|'--onec'|'--onev'|'--ocne')
42581f2001-08-13Martin Stjernholm  once=${once:-1}
1490152001-08-06Martin Stjernholm  debug=0
cbced91998-11-06Marcus Comstedt  ;;
b80b4c2001-07-09Martin Nilsson  '--keep-mysql') keep_mysql=1 ;;
846a912017-09-29Henrik Grubbström (Grubba)  '--mysql-only') keep_mysql=2 once=1 pass="$pass --mysql-only" ;;
c6420b1998-06-02Henrik Grubbström (Grubba)  '--gdb') gdb=gdb
42581f2001-08-13Martin Stjernholm  once=2
1490152001-08-06Martin Stjernholm  debug=0
c6420b1998-06-02Henrik Grubbström (Grubba)  ;;
b253412011-03-21Martin Stjernholm  --valgrind|--valgrind=*) valgrind="$1" once=2 debug=0 ;;
3e7d3b1998-03-20Per Hedbor  '--program') program="$2"
42581f2001-08-13Martin Stjernholm  once=2
409e9b2001-02-01Per Hedbor  passhelp=1
3504a32007-06-12Martin Jonsson  keep_mysql=1
3e7d3b1998-03-20Per Hedbor  shift
8941f62001-10-15Henrik Grubbström (Grubba)  shift # Pass any remaining arguments along to the program. while [ ! c"$1" = "c" ] ; do
21ae4e2001-10-19Henrik Grubbström (Grubba)  pass="$pass '`echo \"$1\" | sed -e \"s/'/'\\\"'\\\"'/g\"`'"
8941f62001-10-15Henrik Grubbström (Grubba)  shift done break
3e7d3b1998-03-20Per Hedbor  ;;
b796b51998-11-18Per Hedbor  '--cd') cd_to="$2"
b1e9fe1998-11-28Henrik Grubbström (Grubba)  # Use the absolute path... roxendir="`pwd`"
42581f2001-08-13Martin Stjernholm  once=${once:-1}
b796b51998-11-18Per Hedbor  shift ;;
2e1f942001-06-26Martin Stjernholm  --debug-without=*|-r*|-d*|-t*|-l*|-w*|-a*|-p*|--*-debug*)
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.
15f9cf2004-03-11Henrik Grubbström (Grubba)  DEFINES="$DEFINES \"$1\""
61c0ca1998-11-28Henrik Grubbström (Grubba)  ;;
5e873b2008-06-18Martin Stjernholm  --pikeargs=*) PIKEARGS="$PIKEARGS "`expr "$1" : '--pikeargs=\(.*\)'` ;;
b1fca01996-11-12Per Hedbor  '--version')
409e9b2001-02-01Per Hedbor  if [ "x$passhelp" = "x1" ] ; then pass="$pass --version" else
6a57751999-08-06Henrik Grubbström (Grubba)  if [ -f base_server/roxen.pike ]; then
fd87202000-09-01Martin Nilsson  echo "Roxen WebServer `roxen_version`"
6a57751999-08-06Henrik Grubbström (Grubba)  exit 0 else echo 'base_server/roxen.pike not found!' exit 1 fi
409e9b2001-02-01Per Hedbor  fi
b1fca01996-11-12Per Hedbor  ;;
d7d5dd2001-08-10Marcus Wellhardh  --self-test-dir=*)
5e873b2008-06-18Martin Stjernholm  SELF_TEST_DIR=`echo $1 | sed -e's/^--self-test-dir=//'`
d7d5dd2001-08-10Marcus Wellhardh  ;;
a0129c2000-11-11Martin Nilsson  '--self-test')
c22e4d2011-01-24Martin Stjernholm  do_setup_for_tests=1
4ba8452001-01-31Per Hedbor  ;; '--self-test-quiet') SILENT_START=y do_pipe="| grep ' |'"
c22e4d2011-01-24Martin Stjernholm  do_setup_for_tests=1
d1ccf92009-03-24Henrik Grubbström (Grubba)  debug=-1
4ba8452001-01-31Per Hedbor  ;; '--self-test-verbose') pass="$pass --tests-verbose=1"
c22e4d2011-01-24Martin Stjernholm  do_setup_for_tests=1
a0129c2000-11-11Martin Nilsson  ;;
b1fca01996-11-12Per Hedbor  '--help'|'-?')
409e9b2001-02-01Per Hedbor  if [ "x$passhelp" = "x1" ] ; then pass="$pass --help" else
ac54c71999-09-10Martin Stjernholm  sed -e "s/\\.B/`tput 'bold' 2>/dev/null`/g" -e "s/B\\./`tput 'sgr0' 2>/dev/null`/g" << EOF
fd87202000-09-01Martin Nilsson .BThis command will start the Roxen WebServerB..
8edfa31998-08-20Per Hedbor  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.
9a05452001-10-04Per Hedbor  .B--offlineB.: Indicate that there is no network connection available. Disables DNS and some other similar things.
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.
a3a0ec2001-03-17Martin Stjernholm  Defaults to .B../configurationsB..
567dac2001-03-23Per Hedbor  .B--debug-log=FILEB.: Use an alternate debuglog file. Defaults to .B../logs/debug/B.configdirname.B.1B..
8a79f82003-02-05Jonas Wallden  .B--pid-file=FILEB.: Store the Roxen and start script pids in this
a3a0ec2001-03-17Martin Stjernholm  file. Defaults to .B../configurations/_roxen_pidB..
8edfa31998-08-20Per Hedbor 
39ed8c2000-08-31Fredrik Noring  .B--silent-startB.: Inhibits output to stdout. If used, this argument must be the first one.
5655dc2001-06-06Per Hedbor  .B--strip-backslashB.: Replace all \\ characters in URIs with /
9ae44d2015-05-06Henrik Grubbström (Grubba)  .B--without-daemonB.: Do not detach from the started server. This is typically used with launchd.
30393a2002-04-16Martin Stjernholm  .B--without-ram-cacheB.: Do not use a protocol level RAM cache to speed
491abc2000-08-17Per Hedbor  things up. Saves RAM at the cost of speed.
30393a2002-04-16Martin Stjernholm  .B--without-ram-cache-statB.: Disable the stat that is usually done for files in the protocol cache to ensure that
a3a0ec2001-03-17Martin Stjernholm  they are not changed before they are sent.
491abc2000-08-17Per Hedbor  Improves performance at the cost of constant
a3a0ec2001-03-17Martin Stjernholm  aggravation if the site is edited. Useful for
491abc2000-08-17Per Hedbor  truly static sites.
d1799d2010-10-13Stefan Wallström  .B--without-http-compressionB.: Disable gzip compression for HTTP requests.
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 
561af82006-07-17Henrik Grubbström (Grubba)  .B--generations=NUMBERB.: Specify the number of generations for the log rotation. Default: 5.
a3a0ec2001-03-17Martin Stjernholm  .B--self-testB.: Runs a testsuite. .B--self-test-verboseB.: Runs a testsuite, report all tests. .B--self-test-quietB.: Runs a testsuite, only report errors.
d7d5dd2001-08-10Marcus Wellhardh  .B--self-test-dir=DIRB.: Use this self test directory instead of the default .Betc/testB. directory.
a0129c2000-11-11Martin Nilsson 
c083c21998-09-19Henrik Grubbström (Grubba)  .B--onceB.: Run the server only once, in the foreground.
1490152001-08-06Martin Stjernholm  This is very useful when debugging. Implies --module-debug.
8edfa31998-08-20Per Hedbor 
c071372005-12-21Fredrik Noring  .B--stopB.: Stop the server.
9f87e62013-01-22Henrik Grubbström (Grubba)  .B--restartB.: Stop the server, and then restart it. .B--signalB.: Send the specified signal to the running Roxen process.
adea562001-11-21Martin Stjernholm  .B--keep-mysqlB.: Do not shut down MySQL process when exiting
b80b4c2001-07-09Martin Nilsson  the start script. Useful during development or any other scenario where the start script is frequently terminated.
846a912017-09-29Henrik Grubbström (Grubba)  .B--mysql-onlyB.: Start the embedded MySQL process, but do not start the rest of Roxen. May be combined with --stop.
c083c21998-09-19Henrik Grubbström (Grubba)  .B--gdbB.: Run the server in gdb. Implies .B--onceB..
8edfa31998-08-20Per Hedbor 
b253412011-03-21Martin Stjernholm  .B--valgrind[=valgrind args]B.: Run the server in valgrind. Implies .B--onceB..
8a79f82003-02-05Jonas Wallden  .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 
1490152001-08-06Martin Stjernholm  .B--without-debugB.: Disable all debug. This is the default. .B--module-debugB.: Enable more internal debug checks to simplify debugging of Roxen modules.
e6a1712000-02-02Per Hedbor 
49693b2018-04-17Pontus Östlund  .B--module-hot-reload=<module-name>B. Enable hot reload of .B<module-name>B.. The module will be reloaded whenever the file is saved. NOTE! This should ONLY be used in a development environment. This flag can appear more than once. .B<module-name>B. is the filename minus the extension of the module.
5b94a52018-04-19Pontus Östlund  .B--module-hot-reload-conf=<conf>B. Set for which configuration .B--module-hot-reloadB. should be applied. By default all module instances in all configurations will be hot-reloaded.
c5e97b2009-06-25Martin Stjernholm  .B--mysql-log-queriesB.: Instruct the MySQL server to log all queries so that they end up in the Roxen debug log.
1490152001-08-06Martin Stjernholm  .B--fd-debugB.: Enable FD debug.
8edfa31998-08-20Per Hedbor 
1490152001-08-06Martin Stjernholm  .B--dump-debugB.: Enable dump debug.
67549e1999-09-05Per Hedbor 
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.
3f240b2001-09-04Honza Petrous  .B--with-snmp-agentB.: Enable internal SNMP agent code.
8a79f82003-02-05Jonas Wallden  .BArguments passed to Pike:B.
8edfa31998-08-20Per Hedbor 
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
e2a69f2001-02-26Martin Stjernholm  with debug (i.e. with --rtl-debug to configure).
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.
8a79f82003-02-05Jonas Wallden  Enabled when starting Roxen with --debug
bcdd9d1999-12-13Per Hedbor  .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.
8a79f82003-02-05Jonas Wallden  Useful for module and Roxen core
bcdd9d1999-12-13Per Hedbor  developers, but not so useful for the occasional pike-script-writer.
8a79f82003-02-05Jonas Wallden  Enabled when starting Roxen with --debug
bcdd9d1999-12-13Per Hedbor 
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 
337c782001-05-17Martin Stjernholm  .B-pB.: Turn on Pike profiling.
e6a1712000-02-02Per Hedbor  .B-t<level>B.: Turn on more Pike tracing. This only
e2a69f2001-02-26Martin Stjernholm  works if Pike is compiled with debug (i.e. with --rtl-debug to configure). .B-a<level>B.: Turn on Pike assembler debug. This only works if Pike is compiled with debug (i.e. with --rtl-debug to configure).
8edfa31998-08-20Per Hedbor 
0272d31999-11-03Henrik Grubbström (Grubba)  .B-wB.: Turn on Pike warnings.
8edfa31998-08-20Per Hedbor 
5e873b2008-06-18Martin Stjernholm  .B--pikeargs=<args>B.: Pass arbitrary arguments to Pike.
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
409e9b2001-02-01Per Hedbor  fi
b1fca01996-11-12Per Hedbor  ;; *)
21ae4e2001-10-19Henrik Grubbström (Grubba)  pass="$pass '`echo \"$1\" | sed -e \"s/'/'\\\"'\\\"'/g\"`'"
5e87b41997-04-09Henrik Grubbström (Grubba)  ;;
b1fca01996-11-12Per Hedbor  esac shift
82f5191997-03-02Per Hedbor  done
c22e4d2011-01-24Martin Stjernholm  if [ "x$do_setup_for_tests" = x1 ]; then setup_for_tests fi
82f5191997-03-02Per Hedbor }
ff3b9a2000-08-09Per Hedbor if [ ! "X$ROXEN_ARGS" = "X" ]; then parse_args $ROXEN_ARGS fi
21ae4e2001-10-19Henrik Grubbström (Grubba) parse_args "$@"
b1fca01996-11-12Per Hedbor 
0b92592004-05-04Henrik Grubbström (Grubba) if [ "$once" = "" ]; then :; else
6332dc2004-05-14Henrik Grubbström (Grubba)  # Once-mode.
63c5f62004-05-14Henrik Grubbström (Grubba)  if [ "x$passhelp" = "x1" ]; then :; else
6332dc2004-05-14Henrik Grubbström (Grubba)  # We're not using --program. # Pass --once along to roxenloader. pass="$pass --once=$once" fi
0b92592004-05-04Henrik Grubbström (Grubba) fi
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
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
fd87202000-09-01Martin Nilsson # Roxen WebServer will create files as the initial user,
b1e9fe1998-11-28Henrik Grubbström (Grubba) # 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
21ae4e2001-10-19Henrik Grubbström (Grubba)  DEFINES="$DEFINES \"-m$roxendir/lib/master.pike\""
2587671999-04-24Martin Stjernholm  elif [ -f lib/pike/master.pike ]; then
21ae4e2001-10-19Henrik Grubbström (Grubba)  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.
21ae4e2001-10-19Henrik Grubbström (Grubba)  DEFINES="$DEFINES \"-m$PIKE_MASTER\""
b1e9fe1998-11-28Henrik Grubbström (Grubba)  fi
6233cd2013-09-30Henrik Grubbström (Grubba)  # Kludge to add pike modules required by base_server to the # module path. Remove when the package system comes in use. for d in modules/feedimport; do for pm in pike_modules pike-modules; do if [ -d "$roxendir/$d/$pm/." ]; then DEFINES="$DEFINES \"-M$roxendir/$d/$pm\"" fi done done
b1e9fe1998-11-28Henrik Grubbström (Grubba) fi # Extra module-path
8cc1802001-01-03Per Hedbor #if [ -d etc/modules ]; then
21ae4e2001-10-19Henrik Grubbström (Grubba)  DEFINES="$DEFINES \"-M$roxendir/etc/modules\""
8cc1802001-01-03Per Hedbor #fi
b1e9fe1998-11-28Henrik Grubbström (Grubba) 
c8f66e2003-04-14Martin Stjernholm if [ -d "$LOCALDIR/pike_modules/." ]; then DEFINES="$DEFINES \"-M$LOCALDIR/pike_modules\"" fi
b1e9fe1998-11-28Henrik Grubbström (Grubba) # Extra include-path
8cc1802001-01-03Per Hedbor #if [ -d etc/include ]; then
21ae4e2001-10-19Henrik Grubbström (Grubba)  DEFINES="$DEFINES \"-I$roxendir/etc/include\""
8cc1802001-01-03Per Hedbor #fi
b1e9fe1998-11-28Henrik Grubbström (Grubba) 
21ae4e2001-10-19Henrik 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)
8cc1802001-01-03Per Hedbor #if [ -d base_server ]; then
1d1e6e2008-03-21Henrik Grubbström (Grubba)  DEFINES="$DEFINES \"-I$roxendir/base_server\" \"-P$roxendir/base_server\""
8cc1802001-01-03Per Hedbor #fi
b1e9fe1998-11-28Henrik Grubbström (Grubba) 
21ae4e2001-10-19Henrik 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
21ae4e2001-10-19Henrik Grubbström (Grubba) DEFINES="$DEFINES \"-P`pwd`\""
b1e9fe1998-11-28Henrik Grubbström (Grubba)  # Support for adding local pike-modules
21ae4e2001-10-19Henrik Grubbström (Grubba) if [ -d "$LOCALDIR/etc/." ]; then
b1e9fe1998-11-28Henrik Grubbström (Grubba)  # Extra module-path
21ae4e2001-10-19Henrik 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
21ae4e2001-10-19Henrik 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
21ae4e2001-10-19Henrik 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
8cc1802001-01-03Per Hedbor  dp "WARNING: Applying kludge for HPUX. (see base_server/roxen.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
1490152001-08-06Martin Stjernholm  "x"|"x0")
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
763acf2009-08-05Henrik Grubbström (Grubba) ####### START MySQL if [ -f "mysql-location.txt" ]; then :; else if [ "x$passhelp" = "x1" ]; then :; else dp "Warning: No mysql-location.txt" fi fi ####### END MySQL
38e43b1998-09-12Henrik Grubbström (Grubba) 
ce78ab2012-09-20Henrik Grubbström (Grubba) # Canonical configuration directory identifier (the inode number). canonicalconf=`ls -Lid "$DIR/." | awk '{ print $1; }'` if [ $verbose -gt 1 -a "$passhelp" = "" ]; then dp "Canonical Roxen configuration identifier: $canonicalconf." fi
7c20602012-09-26Henrik Grubbström (Grubba) start_pid="$$"
ce78ab2012-09-20Henrik Grubbström (Grubba) 
38e43b1998-09-12Henrik Grubbström (Grubba) # # Some useful functions #
ce78ab2012-09-20Henrik Grubbström (Grubba) # Check whether there's a valid pid lock on pid $1 # of process type $2 for configuration $3. check_pid_file_lock() { # Check that there's a lock-file. # # Primary check is in /var/run/ which often is restricted to root. # Secondary check is in /tmp/ to allow for normal users running # the script unmodified.
138e2a2012-09-27Henrik Grubbström (Grubba)  if [ "$verbose" -gt 1 ]; then
7c20602012-09-26Henrik Grubbström (Grubba)  dp "Checking pid-file lock roxen-$2.$1.pid for configuration $3." fi
ce78ab2012-09-20Henrik Grubbström (Grubba)  if [ -f "/var/run/roxen-$2.$1.pid" -o -f "/tmp/roxen-$2.$1.pid" ]; then # Check that the pid file belongs to our configuration.
7c20602012-09-26Henrik Grubbström (Grubba)  if [ "x$3" = "x" -o "x`cat /var/run/roxen-$2.$1.pid 2>/dev/null || cat /tmp/roxen-$2.$1.pid 2>/dev/null`" = "x$3" ]; then
ce78ab2012-09-20Henrik Grubbström (Grubba)  return 0 fi fi return 1 }
7c20602012-09-26Henrik Grubbström (Grubba) # Remove the lock on pid $1 of process type $2 for configuration $3 # (if any). cleanup_pid_file_lock() { if [ -z "$pidfile" ]; then return 0; fi if check_pid_file_lock "$1" "$2" "$3"; then if [ $verbose -gt 1 ]; then dp "Releasing pid-file lock roxen-$2.$1.pid." fi rm -f "/tmp/roxen-$2.$1.pid" 2>/dev/null rm -f "/var/run/roxen-$2.$1.pid" 2>/dev/null fi }
ce78ab2012-09-20Henrik Grubbström (Grubba) # Cleanup after the start-script. cleanup_start_pid_file() {
7c20602012-09-26Henrik Grubbström (Grubba)  cleanup_pid_file_lock "$start_pid" "start" "$canonicalconf"
ce78ab2012-09-20Henrik Grubbström (Grubba)  [ -z "$pidfile" ] || rm -f $pidfile } # Cleanup after Roxen. cleanup_roxen_pid_file() { if [ -z "$pidfile" ]; then return 0; fi read roxenpid <"$pidfile" if [ "x$roxenpid" = "xx" ]; then :; else if check_pid_file_lock "$roxenpid" "server" "$canonicalconf"; then # There's a valid pid file lock for the server for this configuration. # Delete it.
7c20602012-09-26Henrik Grubbström (Grubba)  cleanup_pid_file_lock "$roxenpid" "server" "$canonicalconf"
ce78ab2012-09-20Henrik Grubbström (Grubba)  fi # Remove the stale pid from the pid-file. if [ $verbose -gt 1 ]; then dp "Removing stale pids from $pidfile." fi
7c20602012-09-26Henrik Grubbström (Grubba)  { echo "x"; echo "$start_pid"; } >"$pidfile"
ce78ab2012-09-20Henrik Grubbström (Grubba)  fi
a3a0ec2001-03-17Martin Stjernholm }
0ed68e2012-01-17Henrik Grubbström (Grubba) # Check if the PID in $1 is an active process. processp() { if kill -0 "$1"; then return 0; fi; # Check that the cause for the failure is that the process doesn't exist.
365dd22012-09-27Henrik Grubbström (Grubba)  eval "\"$pike\" $PIKEARGS $DEFINES -e 'return !kill('\"$1\"', 0) && (errno() == System.ESRCH);'";
0ed68e2012-01-17Henrik Grubbström (Grubba)  return; }
ce78ab2012-09-20Henrik Grubbström (Grubba) # Check if the PID in $1 is an active process and has # a $2 {start,server} lock-file associated with the # configuration $3.
bb59c32012-09-17Henrik Grubbström (Grubba) roxenp() {
7c20602012-09-26Henrik Grubbström (Grubba)  if check_pid_file_lock "$1" "$2" "$3"; then
bb59c32012-09-17Henrik Grubbström (Grubba)  # Check that the process exists as well.
ce78ab2012-09-20Henrik Grubbström (Grubba)  if processp "$1"; then return 0; fi # Cleanup the lock, since it is stale.
7c20602012-09-26Henrik Grubbström (Grubba)  cleanup_pid_file_lock "$1" "$2" ""
bb59c32012-09-17Henrik Grubbström (Grubba)  fi return 1; }
ce78ab2012-09-20Henrik Grubbström (Grubba) # Create a roxen lock-file for PID $1 of type $2 # associated with configuration $3.
7c20602012-09-26Henrik Grubbström (Grubba) lock_pid_file() {
ce78ab2012-09-20Henrik Grubbström (Grubba)  if [ -z "$pidfile" ]; then return 0; fi # Create a lock-file. if [ $verbose -gt 1 ]; then dp "Creating lockfile roxen-$2.$1.pid for configuration $3." fi # NB: The subshell is needed to avoid script termination on # permission error (this occurs with /bin/sh on Solaris). ( echo "$3" >"/var/run/roxen-$2.$1.pid"; ) 2>/dev/null || \ echo "$3" >"/tmp/roxen-$2.$1.pid" 2>/dev/null }
63529d2003-12-03Henrik Grubbström (Grubba) # NOTE: The following function needs to be reentrant.
0259c42000-08-31Martin Stjernholm signal_exit() {
57ca9b2009-01-09Martin Stjernholm  test "x$once" != x2 && dp "Start script terminating."
9907572001-06-28Martin Stjernholm  trap "" 2 15
ce78ab2012-09-20Henrik Grubbström (Grubba)  if [ "x$ROXEN_PID" != "x" ]; then if processp $ROXEN_PID 2>/dev/null; then kill $ROXEN_PID 2>/dev/null && wait $ROXEN_PID 2>/dev/null fi # Zap the pid lock file if it is still around. # NB: We don't need to clean the pid-file, since # we will zap it later.
7c20602012-09-26Henrik Grubbström (Grubba)  cleanup_pid_file_lock "$ROXEN_PID" "server" ""
ce78ab2012-09-20Henrik Grubbström (Grubba)  ROXEN_PID=""
a3a0ec2001-03-17Martin Stjernholm  dp "Roxen WebServer shutdown."
63529d2003-12-03Henrik Grubbström (Grubba)  # FIXME: Consider exiting here.
0259c42000-08-31Martin Stjernholm  fi
b80b4c2001-07-09Martin Nilsson  if [ "x$keep_mysql" = "x" ] ; then
e0d0ff2007-05-28Martin Jonsson  if [ -f "$DIR/_mysql/mysql_pid" ] ; then mysql_pidfile="$DIR/_mysql/mysql_pid" elif [ -f "$ROXEN_DATADIR/mysql/mysql_pid" ] ; then mysql_pidfile="$ROXEN_DATADIR/mysql/mysql_pid" fi if [ "x$mysql_pidfile" != "x" ] ; then mysql_pid="`cat $mysql_pidfile 2>/dev/null`"
25a0f12003-12-03Henrik Grubbström (Grubba)  dp_no_nl "Shutting down MySQL." kill "$mysql_pid" 2>/dev/null # Give mysql 5 minutes to shut down. timer=""
e0d0ff2007-05-28Martin Jonsson  while [ -f "$mysql_pidfile" -a \
25a0f12003-12-03Henrik Grubbström (Grubba)  "$timer" != "mmmmm" ] && \
0ed68e2012-01-17Henrik Grubbström (Grubba)  processp "$mysql_pid" 2>/dev/null; do
25a0f12003-12-03Henrik Grubbström (Grubba)  sleep 2 timer=`echo "x$timer" | sed -e 's/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/m/'` if [ "x$SILENT_START" != "xy" ]; then # Progress indicator. echo "." | tr -d ' ' >&2 fi done if [ "x$SILENT_START" != "xy" ]; then echo >&2 fi
0ed68e2012-01-17Henrik Grubbström (Grubba)  if processp "$mysql_pid" 2>/dev/null; then
25a0f12003-12-03Henrik Grubbström (Grubba)  dp "Shutting down MySQL the hard way." kill -9 "$mysql_pid" 2>/dev/null fi
e0d0ff2007-05-28Martin Jonsson  if [ -f "$mysql_pidfile" ] && \ [ "$mysql_pid" = "`cat $mysql_pidfile`" ]; then rm -f "$mysql_pidfile" 2>/dev/null
b80b4c2001-07-09Martin Nilsson  fi
63deb32001-06-27Per Hedbor  fi fi
ce78ab2012-09-20Henrik Grubbström (Grubba)  cleanup_start_pid_file
57ca9b2009-01-09Martin Stjernholm  test "x$once" != x2 && dp "Start script terminated."
0259c42000-08-31Martin Stjernholm  exit 0 }
e8a9012001-01-31Per Hedbor exit_fail() { exitcode=1 }
88d43a2001-11-21Martin Stjernholm # This is a trick to get $ROXEN_PID and arguments containing spaces # correct at the same time. fork_roxen() {
099adb2003-03-25Martin Stjernholm  if [ $verbose -gt 0 ]; then dp "Server start command:" for arg do dp " $arg" done fi
88d43a2001-11-21Martin Stjernholm  "$@" & ROXEN_PID=$! }
ce78ab2012-09-20Henrik Grubbström (Grubba) # Start Roxen # # Entry/exit invariants: # # The pid-file does not contain an entry for the roxen process. # # The server pid lock file is nonexistant. # # During running (NB: updated by the Roxen process): # # The pid-file contains the Roxen server process pid as the first entry. # # The corresponding server pid lock file exists.
38e43b1998-09-12Henrik Grubbström (Grubba) start_roxen() {
196c3f2000-11-16Per Hedbor  check_owner
270fdc2000-12-30Per Hedbor  raise_limit
001f832000-11-20Per Hedbor 
77868d2000-03-13Per Hedbor  if [ x$remove_dumped = x1 ] ; then remove_old_dot_o_files "user request" fi
21ae4e2001-10-19Henrik Grubbström (Grubba)  if [ "x$DIR" != "x../configurations" ] ; then
5e873b2008-06-18Martin Stjernholm  args="$PIKEARGS $DEFINES $ARGS $program --config-dir='`echo \"$DIR\" | sed -e \"s/'/'\\\"'\\\"'/g\"`' $pass"
b796b51998-11-18Per Hedbor  else
5e873b2008-06-18Martin Stjernholm  args="$PIKEARGS $DEFINES $ARGS $program $pass"
b796b51998-11-18Per Hedbor  fi
941fc72001-06-20Fredrik Noring  if [ x"$cd_to" != x ] ; then cd "$cd_to"
b796b51998-11-18Per Hedbor  fi
ce78ab2012-09-20Henrik Grubbström (Grubba)  exitcode="0"
b253412011-03-21Martin Stjernholm  if [ "x$gdb" = "xno" -a "x$valgrind" = "x" ]; then
0259c42000-08-31Martin Stjernholm  if [ "x$once" = "x" ]; then
099adb2003-03-25Martin Stjernholm  if [ $verbose -gt 0 ]; then dp "Executing $pike $args"|sed -e "s!`pwd`!.!g" fi
88d43a2001-11-21Martin Stjernholm  eval "fork_roxen \"$pike\" $args 2>>\"${DEBUGLOG}.1\" 1>&2"
fd87202000-09-01Martin Nilsson  dp "Roxen WebServer server pid $ROXEN_PID."
ce78ab2012-09-20Henrik Grubbström (Grubba)  lock_pid_file "$ROXEN_PID" "server" "$canonicalconf"
42581f2001-08-13Martin Stjernholm  wait $ROXEN_PID 2>/dev/null 1>&2
0259c42000-08-31Martin Stjernholm  exitcode="$?" ROXEN_PID="" else
4ba8452001-01-31Per Hedbor  if [ "x$do_pipe" = "x" ] ; then
42581f2001-08-13Martin Stjernholm  if [ "x$once" = "x1" ]; then
09ecee2003-01-13Martin Stjernholm  eval "fork_roxen $truss \"$pike\" $args 2>&1"
42581f2001-08-13Martin Stjernholm  wait $ROXEN_PID 2>/dev/null 1>&2 exitcode="$?" ROXEN_PID="" else
09ecee2003-01-13Martin Stjernholm  eval "$truss \"$pike\" $args" 2>&1
42581f2001-08-13Martin Stjernholm  exitcode="$?" fi
4ba8452001-01-31Per Hedbor  else
e8a9012001-01-31Per Hedbor  trap exit_fail 1
09ecee2003-01-13Martin Stjernholm  eval "(eval \"$truss \\\"$pike\\\" $args\" || kill -1 $$) 2>&1 $do_pipe"
ce78ab2012-09-20Henrik Grubbström (Grubba)  cleanup_roxen_pid_file
e8a9012001-01-31Per Hedbor  exit $exitcode
4ba8452001-01-31Per Hedbor  fi
0259c42000-08-31Martin Stjernholm  fi
b253412011-03-21Martin Stjernholm  elif [ "x$gdb" != "xno" ]; then
38e43b1998-09-12Henrik Grubbström (Grubba)  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
1ccca72001-08-14Stefan Wallström  if uname | grep 'Linux' >/dev/null 2>&1; then echo >>.gdbinit handle SIG38 nostop noprint pass echo >>.gdbinit handle SIG39 nostop noprint pass fi
4d8c0e2003-09-18Martin Stjernholm  echo >>.gdbinit break debug_fatal echo >>.gdbinit break pike_gdb_breakpoint
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).
a3a0ec2001-03-17Martin Stjernholm  dp "Executing $pike --gdb $args"
21ae4e2001-10-19Henrik Grubbström (Grubba)  eval "\"$pike\" --gdb $args"
348d6c2000-08-30Martin Stjernholm  else
a3a0ec2001-03-17Martin Stjernholm  dp "Executing gdb $pike $args"
21ae4e2001-10-19Henrik Grubbström (Grubba)  echo >>.gdbinit "run $args" gdb "$pike"
348d6c2000-08-30Martin Stjernholm  fi
38e43b1998-09-12Henrik Grubbström (Grubba)  rm .gdbinit
b253412011-03-21Martin Stjernholm  else firstline=`head -1 "$pike" 2>/dev/null` if expr "x$firstline" : 'x#! */.*' >/dev/null; then dp "Executing $pike $valgrind $args" eval "\"$pike\" \"$valgrind\" $args" else dp "Executing valgrind $pike $args" valgrind `expr "$valgrind" : '--valgrind=\(.*\)'` "$pike" fi
38e43b1998-09-12Henrik Grubbström (Grubba)  fi
ce78ab2012-09-20Henrik Grubbström (Grubba)  cleanup_roxen_pid_file
38e43b1998-09-12Henrik Grubbström (Grubba) }
9f87e62013-01-22Henrik Grubbström (Grubba) # <pid> <signal> <type> <canonicalconf> <description> stop_roxen() { if roxenp "$1" "$3" "$4"; then if [ "$2" = "TERM" ]; then dp "Shutting down the $5..." kill "$1" || exit 1 while processp "$1" 2>/dev/null; do echo "Waiting for $5 $1 to die." >&2 sleep 1 done else kill "-$2" "$1" || exit 1 fi return 0 fi return 1 }
0259c42000-08-31Martin Stjernholm 
38e43b1998-09-12Henrik Grubbström (Grubba) # # Now do the stuff #
a3a0ec2001-03-17Martin Stjernholm  trap signal_exit 2 15 trap "" 1
b8e5bf2004-02-04Martin Stjernholm if [ "$program" = "base_server/roxenloader.pike" ] ; then # Starting a Roxen server. Fix the pid file.
21ae4e2001-10-19Henrik Grubbström (Grubba)  [ -z "$pidfile" ] && pidfile="${ROXEN_PID_FILE:-$DIR/_roxen_pid}" pass="$pass --pid-file='`echo \"$pidfile\" | sed -e \"s/'/'\\\"'\\\"'/g\"`'"
49693b2018-04-17Pontus Östlund  if [ "x$module_hot_reload" != "x" ]; then pass="$pass --module-hot-reload=\"$module_hot_reload\"" fi
5b94a52018-04-19Pontus Östlund  if [ "x$module_hot_reload_conf" != "x" ]; then pass="$pass --module-hot-reload-conf=\"$module_hot_reload_conf\"" fi
c071372005-12-21Fredrik Noring  # Check for stop.
138e2a2012-09-27Henrik Grubbström (Grubba)  if [ "$stop"x != x ]
c071372005-12-21Fredrik Noring  then
138e2a2012-09-27Henrik Grubbström (Grubba)  if [ -f "$pidfile" ]; then if read roxenpid && read scriptpid; then problems=""
9f87e62013-01-22Henrik Grubbström (Grubba)  # NB: No need to shut down the start-script # if we're going to do a restart. if [ "$start"x = x -a "$stop" = "TERM" ]; then if stop_roxen "$scriptpid" "TERM" "start" "$canonicalconf" "start script"; then : else problems="nostart" fi
138e2a2012-09-27Henrik Grubbström (Grubba)  fi # NB: At this point the original start script has # often already shut down the server, but...
9f87e62013-01-22Henrik Grubbström (Grubba)  if stop_roxen "$roxenpid" "$stop" "server" "$canonicalconf" "Roxen server"; then :
138e2a2012-09-27Henrik Grubbström (Grubba)  else problems="$problems:noserver" fi if [ "$problems" = "nostart:noserver" ]; then dp "There is a pid file $pidfile," dp "but the corresponding processes do not exist," dp "or are not associated with this configuration." dp "Stale pid file? Deleting the pid file." rm "$pidfile" : fi
9f87e62013-01-22Henrik Grubbström (Grubba)  if [ "$problems:$start" = "nostart:1" ]; then dp "The listed start script was dead. Starting a new one." : fi
138e2a2012-09-27Henrik Grubbström (Grubba)  else dp "There is a pid file $pidfile," dp "but it seems to be truncated." exit 1 fi < "$pidfile"
846a912017-09-29Henrik Grubbström (Grubba)  if [ "x$keep_mysql" = "x2" ]; then stop_mysql; fi elif [ "x$keep_mysql" = "x2" ]; then stop_mysql;
ce78ab2012-09-20Henrik Grubbström (Grubba)  else
138e2a2012-09-27Henrik Grubbström (Grubba)  dp "The pid file $pidfile does not exist." dp "The server is probably not running."
9f87e62013-01-22Henrik Grubbström (Grubba)  if [ "$stop" != "TERM" ]; then exit 1 fi fi if [ "$start"x = x ]; then exit 0
138e2a2012-09-27Henrik Grubbström (Grubba)  fi
c071372005-12-21Fredrik Noring  fi
a3a0ec2001-03-17Martin Stjernholm  # Avoid duplicate start scripts if we got a pid file.
9f87e62013-01-22Henrik Grubbström (Grubba)  if [ -f "$pidfile" ]; then
35ebfd2016-05-17Henrik Grubbström (Grubba)  (
9f87e62013-01-22Henrik Grubbström (Grubba)  if read roxenpid && read scriptpid; then if roxenp "$scriptpid" "start" "$canonicalconf" 2>/dev/null ; then if [ "$stop"x = x ]; then dp "According to the pid file $pidfile," dp "there is already a start script running with pid $scriptpid. Specify " dp "another pid file with --pid-file if this is a different server." dp "Server not started." exit 1 fi dp "The old start script (pid $scriptpid) should now restart the server." exit 2 elif roxenp "$roxenpid" "server" "$canonicalconf" 2>/dev/null ; then dp "According to the pid file $pidfile," dp "there is already a server running with pid $roxenpid, but its start " dp "script seems to have died. You should shut it down and restart " dp "it, since it won't restart automatically. Server not started." exit 1 fi fi
35ebfd2016-05-17Henrik Grubbström (Grubba)  ) < "$pidfile" || {
9f87e62013-01-22Henrik Grubbström (Grubba)  # NB: The exits above just exit the subshell used for the # redirect. Adjust the exit codes and exit for real. [ "$?" = "2" ]; exit; } fi
a3a0ec2001-03-17Martin Stjernholm  # Minor race here.
7c20602012-09-26Henrik Grubbström (Grubba)  lock_pid_file $start_pid "start" "$canonicalconf" { echo "x" && echo $start_pid; } > "$pidfile"
ce78ab2012-09-20Henrik Grubbström (Grubba)  trap cleanup_start_pid_file 0
a3a0ec2001-03-17Martin Stjernholm fi
21ae4e2001-10-19Henrik Grubbström (Grubba) PIKEVERSION="`\"$pike\" --version 2>&1|head -1`" LS="`ls -lL \"$pike\" 2>/dev/null`"
dec2ed2001-01-19Per Hedbor LS="$LS `find etc/modules -ls 2>/dev/null`" LS="$LS `find base_server -ls 2>/dev/null`"
2213981999-09-05Per Hedbor 
688d032000-09-25Per Hedbor VERSION_DATA="$PIKEVERSION $DEFINES $LS"
2213981999-09-05Per Hedbor 
e6a1712000-02-02Per Hedbor if [ "$program" = "base_server/roxenloader.pike" ] ; then
21ae4e2001-10-19Henrik Grubbström (Grubba)  if [ "`cat \"$old_roxen_defines\" 2>/dev/null`" != "$VERSION_DATA" ] ; then
8a79f82003-02-05Jonas Wallden  remove_old_dot_o_files "defines or Pike version changed"
7541211999-10-08Per Hedbor  fi
21ae4e2001-10-19Henrik Grubbström (Grubba)  echo "$VERSION_DATA" > "$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
fd87202000-09-01Martin Nilsson  dp "Starting the Roxen WebServer."
14fd211998-11-28Henrik Grubbström (Grubba)  else :; fi
567dac2001-03-23Per Hedbor  if [ "x$DEBUGLOG" = "x" ] ; then DEBUGDIR="$LOGDIR/debug" DEBUGLOG="$DEBUGDIR/$FILES" else DEBUGDIR="`dirname "$DEBUGLOG"`" fi
ae7fb42006-09-11Marcus Wellhardh  LOGFILE="${DEBUGLOG}.1" export LOGFILE
6466f12001-03-24Per Hedbor  # This duplicate of the logdir creation code is needed, check the # redirect below if [ ! -d "$DEBUGDIR" ] ; then if ./mkdir -p "$DEBUGDIR" 2>/dev/null; then :; else dp "Failed to create log directory $DEBUGDIR."
ce78ab2012-09-20Henrik Grubbström (Grubba)  cleanup_start_pid_file
6466f12001-03-24Per Hedbor  exit 1 fi fi
bd2f642003-09-24Henrik Grubbström (Grubba)  if [ -f "bin/setup_nsr.pike" ]; then # Setup .nsr (Networker) files for the logfile directories.
5e873b2008-06-18Martin Stjernholm  eval "\"$pike\" $PIKEARGS $DEFINES bin/setup_nsr.pike --logdir=\"$LOGDIR\" --debugdir=\"$DEBUGDIR\""
bd2f642003-09-24Henrik Grubbström (Grubba)  fi
14fd211998-11-28Henrik Grubbström (Grubba)  if [ $verbose -gt 0 ]; then
a3a0ec2001-03-17Martin Stjernholm  dp "Using configuration from $DIR"
567dac2001-03-23Per Hedbor  dp "Storing the debug log in ${DEBUGLOG}.1"
a3a0ec2001-03-17Martin Stjernholm  dp "You can use the administration interface in the server to see debug info."
14fd211998-11-28Henrik Grubbström (Grubba)  else :; fi
13c5481998-07-02Henrik Grubbström (Grubba) 
0259c42000-08-31Martin Stjernholm  if ( (
a3a0ec2001-03-17Martin Stjernholm  # Minor race here wrt pid file cleanup.
7c20602012-09-26Henrik Grubbström (Grubba)  # Note: We can't use $$ here since it is the pid of the master shell. # We can't use $(exec sh -c 'echo $PPID') (the POSIX way), for # multiple reasons, most of them pertaining to /bin/sh on # Solaris which supports neither $PPID nor $(). old_start_pid="$start_pid" start_pid="`\"$pike\" $PIKEARGS -e 'return (string)getppid();'`" lock_pid_file "$start_pid" "start" "$canonicalconf" [ -z "$pidfile" ] || { echo "x" && echo $start_pid; } > "$pidfile" if [ "x$old_start_pid" = "x$start_pid" ]; then :; else # Get rid of the tentative pid file lock. cleanup_pid_file_lock "$old_start_pid" "start" "$canonicalconf" fi
0259c42000-08-31Martin Stjernholm  exec 3>&-
a3a0ec2001-03-17Martin Stjernholm  trap signal_exit 2 15 trap "" 1
ce78ab2012-09-20Henrik Grubbström (Grubba)  trap cleanup_start_pid_file 0
0259c42000-08-31Martin Stjernholm  while : ; do
567dac2001-03-23Per Hedbor  if test -d "$DEBUGDIR/."; then :; else
0259c42000-08-31Martin Stjernholm  # Avoid infinite loop if the debug directory is deleted. # Thanks to Emils Klotins <emils@dot.lv> for reporting it.
6466f12001-03-24Per Hedbor  if ./mkdir -p "$DEBUGDIR" 2>/dev/null; then :; else
567dac2001-03-23Per Hedbor  dp "Failed to create log directory $DEBUGDIR."
ce78ab2012-09-20Henrik Grubbström (Grubba)  cleanup_start_pid_file
0259c42000-08-31Martin Stjernholm  exit 1 fi
12017a2000-06-05Emils Klotins  fi
49fff32000-01-27Henrik Grubbström (Grubba) 
0259c42000-08-31Martin Stjernholm  dp "Server start at `date`"
567dac2001-03-23Per Hedbor  dp "Debug log in ${DEBUGLOG}.1"
21ae4e2001-10-19Henrik Grubbström (Grubba)  rotate "$DEBUGLOG"
a3a0ec2001-03-17Martin Stjernholm  start_roxen
49fff32000-01-27Henrik Grubbström (Grubba) 
0259c42000-08-31Martin Stjernholm  if [ "$exitcode" -eq "0" ] ; then # Clean shutdown.
fd87202000-09-01Martin Nilsson  dp "Roxen WebServer shutdown."
b1886b2001-11-09Henrik Grubbström (Grubba)  signal_exit
cf769a2002-10-14Henrik Grubbström (Grubba)  # Not reached, but...
0259c42000-08-31Martin Stjernholm  exit 0 fi if [ "$exitcode" -lt "0" ] ; then # Signal death.
d97cca2001-11-15Henrik Grubbström (Grubba)  dp "Roxen WebServer died of signal $exitcode."
0259c42000-08-31Martin Stjernholm  else
00b8b02001-02-02Fredrik Noring  case "$exitcode" in 100) dp "Changing Roxen WebServer version. Restarting."
8e9f182002-01-03Henrik Grubbström (Grubba)  # We need to clean up the pid file, since we're mentioned in it...
ce78ab2012-09-20Henrik Grubbström (Grubba)  cleanup_start_pid_file
00b8b02001-02-02Fredrik Noring  cd .. && exec ./start "$@" dp 'Failed to spawn start script. -- Permission problem?' exit 1 ;;
cf769a2002-10-14Henrik Grubbström (Grubba)  50) dp "Failed to open any port. Shutdown." keep_mysql=1 signal_exit # Not reached, but... exit 50 ;;
00b8b02001-02-02Fredrik Noring  *)
d97cca2001-11-15Henrik Grubbström (Grubba)  dp "Roxen WebServer down with code $exitcode."
00b8b02001-02-02Fredrik Noring  ;; esac
0259c42000-08-31Martin Stjernholm  fi
d97cca2001-11-15Henrik Grubbström (Grubba)  if [ -f "$LOCALDIR/restart_rc" ]; then dp "Running $LOCALDIR/restart_rc..." if /bin/sh "$LOCALDIR/restart_rc"; then :; else dp "$LOCALDIR/restart_rc failed with code $?." fi fi dp "Restarting..."
0259c42000-08-31Martin Stjernholm  done ) &
a3a0ec2001-03-17Martin Stjernholm  # Minor race here wrt pid file contents.
7c20602012-09-26Henrik Grubbström (Grubba)  start_pid=$!
a3a0ec2001-03-17Martin Stjernholm  trap "" 0
7c20602012-09-26Henrik Grubbström (Grubba)  dp "Forked start script, pid $start_pid." 2>&3 dp "Start script pid $start_pid."
9ae44d2015-05-06Henrik Grubbström (Grubba)  if test "x$daemonize" = "xyes"; then :; else
a5acf42015-05-06Henrik Grubbström (Grubba)  trap "stop_roxen $start_pid TERM start \"$canonicalconf\" \"start script\"" 2 15
9ae44d2015-05-06Henrik Grubbström (Grubba)  wait; signal_exit fi
567dac2001-03-23Per Hedbor  ) 3>&2 </dev/null >"$DEBUGDIR/start_$FILES.output" 2>&1; then
a3a0ec2001-03-17Martin Stjernholm  trap "" 0
0259c42000-08-31Martin Stjernholm  :
49fff32000-01-27Henrik Grubbström (Grubba)  else
ff3b9a2000-08-09Per Hedbor  dp 'Failed to spawn subshell. -- Permission problem?'
ce78ab2012-09-20Henrik Grubbström (Grubba)  cleanup_start_pid_file
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
a3a0ec2001-03-17Martin Stjernholm  start_roxen
975dae2003-10-13Henrik Grubbström (Grubba)  if [ "$once" = "1" -a "$exitcode" = "50" ]; then dp "Failed to open any port. Shutdown." keep_mysql=1 fi signal_exit
a8135b1996-11-12Per Hedbor fi
941fc72001-06-20Fredrik Noring