Roxen.git / server / start

version» Context lines:

Roxen.git/server/start:1:   #!/bin/sh   # - # $Id: start,v 1.185 2001/10/15 17:27:10 grubba Exp $ + # $Id: start,v 1.186 2001/10/19 11:00:46 grubba 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      check_owner() {
Roxen.git/server/start:45:   dn="`dirname $0`"   case "$dn" in    ""|".")    ;;    *)    # dp is not used here since we cannot source bin/functions before we    # are in the correct directory, for quite obvious reasons...    if [ ! "$dn" = "`pwd`" ]    then    echo " : Changing current directory to '$dn' (now `pwd`)" >&2 -  cd $dn +  cd "$dn"    echo " : Got new directory as `pwd`" >&2    fi    ;;   esac      . bin/functions      # Can be set with '--config-dir=DIR'   DIR=../configurations   LOGDIR=../logs   FILES="default"   program=base_server/roxenloader.pike   VARDIR=../var   LOCALDIR=../local   SELF_TEST_DIR=etc/test      # Make LOCALDIR an absolute path   if test -d $LOCALDIR/.; then -  LOCALDIR=`cd $LOCALDIR; pwd` +  LOCALDIR="`cd $LOCALDIR; pwd`"   else :; fi      if test -d $VARDIR/.; then :; else    dp "Creating directory $VARDIR"    ./mkdir -p $VARDIR/ || exit 1   fi         pcdir="$VARDIR/`roxen_version`/precompiled/`uname -m | tr ' ' '_' `.`uname -r`"   old_roxen_defines="$pcdir/old_roxen_defines" - ./mkdir -p $pcdir || exit 1 - chmod 1777 $pcdir + ./mkdir -p "$pcdir" || exit 1 + chmod 1777 "$pcdir"      # Default verbosity level.   verbose=1      # Do not default to using a relative path.   roxendir="`pwd`"      # No debug by default.   debug=-1   
Roxen.git/server/start:102:      ####### BEGIN ARGUMENT PARSING         DEFINES="$DEFINES -DRAM_CACHE"      # 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 +  # FIXME: What about Solaris 10+ (SunOS 5.10+)?   # if [ $verbose -gt 0 ] ; then   # dp "Solaris 2.5 or later detected. Using threads by default."   # fi    DEFINES="$DEFINES -DENABLE_THREADS"    fi   fi   # Darwin 1.4 or later (Mac OS X 10.1 or newer) also uses threads.   if uname | grep 'Darwin' >/dev/null 2>&1; then    if uname -r | grep '^1\.[4-9]' >/dev/null 2>&1; then    DEFINES="$DEFINES -DENABLE_THREADS"
Roxen.git/server/start:130:    # to roxenloader instead.    pass="$pass --remove-dumped"   }      ## Parse all arguments.   ## GNU-style, long options only, except for -D, simply passed on.   ARGS=""      setup_for_tests() {    # Kill roxen mysql if it's running... -  if [ -f $VARDIR/test_config/_mysql/mysql_pid ] ; then -  kill `cat $VARDIR/test_config/_mysql/mysql_pid` +  if [ -f "$VARDIR/test_config/_mysql/mysql_pid" ] ; then +  kill `cat "$VARDIR/test_config/_mysql/mysql_pid"`    fi    self_test=y    DEFINES="-DRUN_SELF_TEST -DSELF_TEST_DIR=\"$SELF_TEST_DIR\" $DEFINES" -  rm -rf $VARDIR/test_config* -  DIR=$VARDIR/test_config -  if [ -f $SELF_TEST_DIR/scripts/setup.pike ] ; then -  $PIKE $SELF_TEST_DIR/scripts/setup.pike $SELF_TEST_DIR $VARDIR +  rm -rf "$VARDIR/test_config"* +  DIR="$VARDIR/test_config" +  if [ -f "$SELF_TEST_DIR/scripts/setup.pike" ] ; then +  $PIKE "$SELF_TEST_DIR/scripts/setup.pike" "$SELF_TEST_DIR" "$VARDIR"    fi    once=${once:-1}    debug=1    remove_dumped=1   }      parse_args() {    while [ ! c"$1" = "c" ] ; do    case "$1" in    -D*)
Roxen.git/server/start:256:    debug=0    ;;    '--program')    program="$2"    once=2    passhelp=1    shift    shift    # Pass any remaining arguments along to the program.    while [ ! c"$1" = "c" ] ; do -  pass="$pass $1" +  pass="$pass '`echo \"$1\" | sed -e \"s/'/'\\\"'\\\"'/g\"`'"    shift    done    break    ;;    '--cd')    cd_to="$2"    # Use the absolute path...    roxendir="`pwd`"    once=${once:-1}    shift
Roxen.git/server/start:490:    .BROXEN_PID_FILEB.: Same as .B--pid-file=... B.    .BROXEN_LANGB.: The default language for all language    related tags. Defaults to 'en' for english.      EOF    tput 'rmso' 2>/dev/null    exit 0    fi    ;;    *) -  pass="$pass $1" +  pass="$pass '`echo \"$1\" | sed -e \"s/'/'\\\"'\\\"'/g\"`'"    ;;    esac    shift    done   }      if [ ! "X$ROXEN_ARGS" = "X" ]; then    parse_args $ROXEN_ARGS   fi    - parse_args $@ + parse_args "$@"      # The work has already been done above, but the debug printout is better   # to have _after_ parse_args (consider --help and --version)      if [ ! "X$ROXEN_ARGS" = "X" ]; then    if [ $verbose -gt 0 ]; then    dp "Used $ROXEN_ARGS from ROXEN_ARGS."    else :; fi   fi   
Roxen.git/server/start:528:   ####### BEGIN PIKE OPTIONS      # Roxen WebServer will create files as the initial user,   # which it expects to be able to read as the run-time user.   umask 022      if [ "x$PIKE_NO_DEFAULT_PATHS" = "x" ]; then    # Pike default Master-program    if [ "x$PIKE_MASTER" = "x" ]; then    if [ -f lib/master.pike ]; then -  DEFINES="$DEFINES -m$roxendir/lib/master.pike" +  DEFINES="$DEFINES \"-m$roxendir/lib/master.pike\""    elif [ -f lib/pike/master.pike ]; then -  DEFINES="$DEFINES -m$roxendir/lib/pike/master.pike" +  DEFINES="$DEFINES \"-m$roxendir/lib/pike/master.pike\""    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" +  DEFINES="$DEFINES \"-m$PIKE_MASTER\""    fi   fi      # Extra module-path   #if [ -d etc/modules ]; then -  DEFINES="$DEFINES -M$roxendir/etc/modules" +  DEFINES="$DEFINES \"-M$roxendir/etc/modules\""   #fi      # Extra include-path   #if [ -d etc/include ]; then -  DEFINES="$DEFINES -I$roxendir/etc/include" +  DEFINES="$DEFINES \"-I$roxendir/etc/include\""   #fi    - if [ -d $LOCALDIR/include/. ]; then -  DEFINES="$DEFINES -I$LOCALDIR/include" + if [ -d "$LOCALDIR/include/." ]; then +  DEFINES="$DEFINES \"-I$LOCALDIR/include\""   fi      # Extra include-path (2)   #if [ -d base_server ]; then -  DEFINES="$DEFINES -I$roxendir/base_server" +  DEFINES="$DEFINES \"-I$roxendir/base_server\""   #fi    - if [ -d $LOCALDIR/base_server/. ]; then -  DEFINES="$DEFINES -I$LOCALDIR/base_server -P$LOCALDIR/base_server" + if [ -d "$LOCALDIR/base_server/." ]; then +  DEFINES="$DEFINES \"-I$LOCALDIR/base_server\" \"-P$LOCALDIR/base_server\""   fi      # Extra program-path - DEFINES="$DEFINES -P`pwd`" + DEFINES="$DEFINES \"-P`pwd`\""      # Support for adding local pike-modules - if [ -d $LOCALDIR/etc/. ]; then + if [ -d "$LOCALDIR/etc/." ]; then    # Extra module-path -  if [ -d $LOCALDIR/etc/modules/. ]; then -  DEFINES="$DEFINES -M$LOCALDIR/etc/modules" +  if [ -d "$LOCALDIR/etc/modules/." ]; then +  DEFINES="$DEFINES \"-M$LOCALDIR/etc/modules\""    fi       # Extra include-path -  if [ -d $LOCALDIR/etc/include/. ]; then -  DEFINES="$DEFINES -I$LOCALDIR/etc/include" +  if [ -d "$LOCALDIR/etc/include/." ]; then +  DEFINES="$DEFINES \"-I$LOCALDIR/etc/include\""    fi       # Extra program-path -  DEFINES="$DEFINES -P$LOCALDIR/etc" +  DEFINES="$DEFINES \"-P$LOCALDIR/etc\""   fi      # Extra kludge for HPUX   # HPUX doesn't like group 60001(nobody)   if uname | grep 'HP-UX' >/dev/null 2>&1; then    if [ $verbose -gt 0 ]; then    dp "WARNING: Applying kludge for HPUX. (see base_server/roxen.pike)"    else :; fi    DEFINES="$DEFINES -DHPUX_KLUDGE"   fi
Roxen.git/server/start:654:    exitcode=1   }      start_roxen() {    check_owner    raise_limit       if [ x$remove_dumped = x1 ] ; then    remove_old_dot_o_files "user request"    fi -  if [ x$DIR != x../configurations ] ; then -  args="$DEFINES $ARGS $program --config-dir=$DIR $pass" +  if [ "x$DIR" != "x../configurations" ] ; then +  args="$DEFINES $ARGS $program --config-dir='`echo \"$DIR\" | sed -e \"s/'/'\\\"'\\\"'/g\"`' $pass"    else    args="$DEFINES $ARGS $program $pass"    fi    if [ x"$cd_to" != x ] ; then    cd "$cd_to"    fi    if [ "x$gdb" = "xno" ]; then    if [ $verbose -gt 0 ]; then    if [ $verbose -gt 1 -o -z "$once" ] ; then -  dp Executing $pike $args|sed -e "s!`pwd`!.!g" +  dp "Executing $pike $args"|sed -e "s!`pwd`!.!g"    else    dp "Using the '$pike' pike binary"|sed -e "s!`pwd`!.!g"    fi    fi       if [ "x$once" = "x" ]; then -  "$pike" $args 2>>"${DEBUGLOG}.1" 1>&2 & +  eval "\"$pike\" $args" 2>>"${DEBUGLOG}.1" 1>&2 &    ROXEN_PID=$!    dp "Roxen WebServer server pid $ROXEN_PID."    wait $ROXEN_PID 2>/dev/null 1>&2    exitcode="$?"    ROXEN_PID=""    else    if [ "x$do_pipe" = "x" ] ; then    if [ "x$once" = "x1" ]; then -  "$pike" $args 2>&1 & +  eval "\"$pike\" $args" 2>&1 &    ROXEN_PID=$!    wait $ROXEN_PID 2>/dev/null 1>&2    exitcode="$?"    ROXEN_PID=""    else -  "$pike" $args 2>&1 +  eval "\"$pike\" $args" 2>&1    exitcode="$?"    fi    else    trap exit_fail 1 -  eval "($pike $args || kill -1 $$) 2>&1 $do_pipe" +  eval "(eval \"\\\"$pike\\\" $args\" || kill -1 $$) 2>&1 $do_pipe"    exit $exitcode    fi    fi    else    echo >.gdbinit handle SIGPIPE nostop noprint pass    echo >>.gdbinit handle SIGUSR1 nostop noprint pass    echo >>.gdbinit handle SIGUSR2 nostop noprint pass    echo >>.gdbinit handle SIGLWP nostop noprint pass    if uname | grep 'Linux' >/dev/null 2>&1; then    echo >>.gdbinit handle SIG38 nostop noprint pass    echo >>.gdbinit handle SIG39 nostop noprint pass    fi    firstline=`head -1 "$pike" 2>/dev/null`    if expr "x$firstline" : 'x#! */.*' >/dev/null; then    # Looks like a script. gdb will not grok it, so we try passing    # --gdb to it instead (which works in the special case of the    # bin/pike script that is built by the top level Makefile in the    # Pike source tree).    dp "Executing $pike --gdb $args" -  $pike --gdb $args +  eval "\"$pike\" --gdb $args"    else    dp "Executing gdb $pike $args" -  echo >>.gdbinit run $args -  gdb $pike +  echo >>.gdbinit "run $args" +  gdb "$pike"    fi    rm .gdbinit    fi    if [ x$once = x1 ] ; then    signal_exit    fi   }         #   # Now do the stuff   #      trap signal_exit 2 15   trap "" 1      if [ -z "$once" ]; then    # Fix the pid file. We don't do this if once is set, since that    # often signifies that it's not the real server starting up, but    # instead some other process, e.g. one given with --program. -  [ -z "$pidfile" ] && pidfile=${ROXEN_PID_FILE:-$DIR/_roxen_pid} -  pass="$pass --pid-file=$pidfile" +  [ -z "$pidfile" ] && pidfile="${ROXEN_PID_FILE:-$DIR/_roxen_pid}" +  pass="$pass --pid-file='`echo \"$pidfile\" | sed -e \"s/'/'\\\"'\\\"'/g\"`'"    # Avoid duplicate start scripts if we got a pid file.    mypid=$$ -  test -f $pidfile && { +  test -f "$pidfile" && {    if read roxenpid && read scriptpid; then    if kill -0 $scriptpid 2>/dev/null; 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."    :    elif kill -0 $roxenpid 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."    :    else false; fi    else false; fi -  } < $pidfile && exit 1 +  } < "$pidfile" && exit 1    # Minor race here. -  { echo "x" && echo $mypid; } > $pidfile +  { echo "x" && echo $mypid; } > "$pidfile"    trap cleanup_pid_file 0   fi    - PIKEVERSION="`$pike --version 2>&1|head -1`" - LS="`ls -lL $pike 2>/dev/null`" + PIKEVERSION="`\"$pike\" --version 2>&1|head -1`" + LS="`ls -lL \"$pike\" 2>/dev/null`"   LS="$LS `find etc/modules -ls 2>/dev/null`"   LS="$LS `find base_server -ls 2>/dev/null`"      VERSION_DATA="$PIKEVERSION $DEFINES $LS"      if [ "$program" = "base_server/roxenloader.pike" ] ; then -  if [ "`cat $old_roxen_defines 2>/dev/null`" != "$VERSION_DATA" ] ; then +  if [ "`cat \"$old_roxen_defines\" 2>/dev/null`" != "$VERSION_DATA" ] ; then    remove_old_dot_o_files "defines or pike version changed"    fi -  echo "$VERSION_DATA" > $old_roxen_defines +  echo "$VERSION_DATA" > "$old_roxen_defines"   fi      if [ -z "$once" ] ; then    if [ $verbose -gt 0 ]; then    dp "Starting the Roxen WebServer."    else :; fi    if [ "x$DEBUGLOG" = "x" ] ; then    DEBUGDIR="$LOGDIR/debug"    DEBUGLOG="$DEBUGDIR/$FILES"    else
Roxen.git/server/start:821:    # Avoid infinite loop if the debug directory is deleted.    # Thanks to Emils Klotins <emils@dot.lv> for reporting it.    if ./mkdir -p "$DEBUGDIR" 2>/dev/null; then :; else    dp "Failed to create log directory $DEBUGDIR."    exit 1    fi    fi       dp "Server start at `date`"    dp "Debug log in ${DEBUGLOG}.1" -  rotate $DEBUGLOG +  rotate "$DEBUGLOG"    start_roxen       if [ "$exitcode" -eq "0" ] ; then    # Clean shutdown.    dp "Roxen WebServer shutdown."    exit 0    fi    if [ "$exitcode" -lt "0" ] ; then    # Signal death.    dp "Roxen WebServer died of signal $exitcode. Restarting..."
Roxen.git/server/start:850:    *)    dp "Roxen WebServer down. Restarting."    ;;    esac    fi    done    ) &    # Minor race here wrt pid file contents.    pid=$!    trap "" 0 -  [ -z "$pidfile" ] || { echo "x" && echo $pid; } > $pidfile +  [ -z "$pidfile" ] || { echo "x" && echo $pid; } > "$pidfile"    dp "Forked start script, pid $pid." 2>&3    dp "Start script pid $pid."    ) 3>&2 </dev/null >"$DEBUGDIR/start_$FILES.output" 2>&1; then    trap "" 0    :    else    dp 'Failed to spawn subshell. -- Permission problem?'    exit 1    fi       # Try to get rid of some fd's.    # Some /bin/sh's have problems detaching otherwise.       exec >/dev/null    exec </dev/null   else    start_roxen   fi