Branch: Tag:

2000-08-31

2000-08-31 01:50:41 by Martin Stjernholm <mast@lysator.liu.se>

Made the start script respond to SIGINT and SIGTERM, and shut down
Roxen properly on them. Various other small changes.

Rev: server/start:1.123

1:   #!/bin/sh   # - # $Id: start,v 1.122 2000/08/29 23:28:32 mast Exp $ + # $Id: start,v 1.123 2000/08/31 01:50:41 mast Exp $      pre="`echo \" $$ \" | sed -e 's/\(.........\)\(.*\)/\1/g'` :"   
550:    for a in 4 3 2 1 ; do mv -f $1.$a $1.$b 2> /dev/null; b=$a; done   }    + 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 + } +    start_roxen() {    if [ x$remove_dumped = x1 ] ; then    remove_old_dot_o_files "user request"
570:    dp "Using '$pike'"|sed -e "s!`pwd`!.!g"    fi    fi -  $pike $args "$@" +  +  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 +  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    firstline=`head -1 "$pike" 2>/dev/null`    if expr "x$firstline" : 'x#! */.*' >/dev/null; then -  # Looks like a script. gdb won't grok it, so we try passing +  # 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's built by the top level Makefile in 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 "$@"
593:    fi   }    +    #   # Now do the stuff   #
613:    ./mkdir -p $LOGDIR/debug/       if [ $verbose -gt 0 ]; then -  cat << oo - Using configuration from $DIR, storing the debug log in $LOGDIR/debug/$FILES.1 - You can use the administration interface in the server to get debug info. - oo +  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."    else :; fi    -  # Try to get rid of some fd's. -  # Some /bin/sh's have problems detaching otherwise. +  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 >/dev/null -  exec </dev/null +  exec 3>&-    -  if ((while : ; do +  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.
635:    fi    fi    -  dp "Server restart at `date`" +  dp "Server start at `date`"    dp "Debug log in $LOGDIR/debug/$FILES.1"    rotate $LOGDIR/debug/$FILES -  start_roxen $extra_args 2>>$LOGDIR/debug/$FILES.1 1>&2 +  start_roxen $extra_args    -  exitcode="$?" -  +     if [ "$exitcode" -eq "0" ] ; then    # Clean shutdown.    dp "Roxen shutdown."
653:    else    dp "Roxen down. Restarting."    fi -  done) & ) </dev/null >$LOGDIR/debug/start_$FILES.output 2>&1; then -  :; +  done +  ) & +  dp "Forked start script, pid $!." >&3 +  ) 3>&1 </dev/null >$LOGDIR/debug/start_$FILES.output 2>&1; then +  :    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 $extra_args 2>&1 +  start_roxen $extra_args   fi