Roxen.git / server / start

version» Context lines:

Roxen.git/server/start:1:   #!/bin/sh   # - # $Id: start,v 1.243 2012/01/17 10:52:44 grubba Exp $ + # $Id: start,v 1.244 2012/09/17 16:38: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:738:    fi   fi      ####### END MySQL      #   # Some useful functions   #      cleanup_pid_file() { +  rm -f "/tmp/roxen.$$" 2>/dev/null +  rm -f "/var/run/roxen.$$" 2>/dev/null    [ -z "$pidfile" ] || rm $pidfile   }      # 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.    "$PIKE" $DEFINES -e 'return !kill('"$1"', 0) && (errno() == System.ESRCH);';    return;   }    -  + # Check if the PID in $1 is an active process and is the Roxen start-script. + roxenp() { +  # 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. +  if [ -f "/var/run/roxen.$1" -o -f "/tmp/roxen.$1" ]; then +  # Check that the process exists as well. +  processp "$1"; +  return; +  fi +  return 1; + } +    # NOTE: The following function needs to be reentrant.   signal_exit() {    test "x$once" != x2 && dp "Start script terminating."    trap "" 2 15    if [ "x$ROXEN_PID" != "x" ] && \    processp $ROXEN_PID 2>/dev/null; then    kill $ROXEN_PID 2>/dev/null && wait $ROXEN_PID 2>/dev/null    dp "Roxen WebServer shutdown."    # FIXME: Consider exiting here.    fi
Roxen.git/server/start:796:    if processp "$mysql_pid" 2>/dev/null; then    dp "Shutting down MySQL the hard way."    kill -9 "$mysql_pid" 2>/dev/null    fi    if [ -f "$mysql_pidfile" ] && \    [ "$mysql_pid" = "`cat $mysql_pidfile`" ]; then    rm -f "$mysql_pidfile" 2>/dev/null    fi    fi    fi +  cleanup_pid_file    test "x$once" != x2 && dp "Start script terminated."    exit 0   }      exit_fail() {    exitcode=1   }      # This is a trick to get $ROXEN_PID and arguments containing spaces   # correct at the same time.
Roxen.git/server/start:912:   trap signal_exit 2 15   trap "" 1      if [ "$program" = "base_server/roxenloader.pike" ] ; then    # Starting a Roxen server. Fix the pid file.    [ -z "$pidfile" ] && pidfile="${ROXEN_PID_FILE:-$DIR/_roxen_pid}"    pass="$pass --pid-file='`echo \"$pidfile\" | sed -e \"s/'/'\\\"'\\\"'/g\"`'"    # Check for stop.    if [ "$stop"x != x ] && [ -f "$pidfile" ]    then +  if read roxenpid && read scriptpid && roxenp "$scriptpid"; then    pids=`cat "$pidfile"`    echo "$pids" | xargs kill    cat "$pidfile" | while read pid; do    while processp $pid 2>/dev/null; do    echo "Waiting for $pid to die." >&2    sleep 1    done    done -  +  else +  dp "There is a pid file $pidfile," +  dp "but the corresponding processes do not exist." +  dp "Stale pid file? Deleting the pid file." +  rm "$pidfile" +  : +  fi < "$pidfile"    exit    fi    # Avoid duplicate start scripts if we got a pid file.    mypid=$$    test -f "$pidfile" && {    if read roxenpid && read scriptpid; then -  if processp $scriptpid 2>/dev/null; then +  if roxenp $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 processp $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    # Minor race here. -  +  { touch "/var/run/roxen.$mypid" || touch "/tmp/roxen.$mypid"; } 2>/dev/null    { 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`"   LS="$LS `find etc/modules -ls 2>/dev/null`"   LS="$LS `find base_server -ls 2>/dev/null`"      VERSION_DATA="$PIKEVERSION $DEFINES $LS"
Roxen.git/server/start:978:    DEBUGDIR="`dirname "$DEBUGLOG"`"    fi    LOGFILE="${DEBUGLOG}.1"    export LOGFILE       # 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." +  cleanup_pid_file    exit 1    fi    fi    if [ -f "bin/setup_nsr.pike" ]; then    # Setup .nsr (Networker) files for the logfile directories.    eval "\"$pike\" $PIKEARGS $DEFINES bin/setup_nsr.pike --logdir=\"$LOGDIR\" --debugdir=\"$DEBUGDIR\""    fi    if [ $verbose -gt 0 ]; then    dp "Using configuration from $DIR"    dp "Storing the debug log in ${DEBUGLOG}.1"
Roxen.git/server/start:1005:    trap signal_exit 2 15    trap "" 1    trap cleanup_pid_file 0       while : ; do    if test -d "$DEBUGDIR/."; then :; else    # 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." +  cleanup_pif_file    exit 1    fi    fi       dp "Server start at `date`"    dp "Debug log in ${DEBUGLOG}.1"    rotate "$DEBUGLOG"    start_roxen       if [ "$exitcode" -eq "0" ] ; then
Roxen.git/server/start:1032:    # Signal death.    dp "Roxen WebServer died of signal $exitcode."    else    case "$exitcode" in    100)    dp "Changing Roxen WebServer version. Restarting."    # We need to clean up the pid file, since we're mentioned in it...    cleanup_pid_file    cd .. && exec ./start "$@"    dp 'Failed to spawn start script. -- Permission problem?' +  cleanup_pid_file    exit 1    ;;    50)    dp "Failed to open any port. Shutdown."    keep_mysql=1    signal_exit    # Not reached, but...    exit 50    ;;    *)
Roxen.git/server/start:1066:    pid=$!    trap "" 0    [ -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?' +  cleanup_pid_file    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    if [ "$once" = "1" -a "$exitcode" = "50" ]; then    dp "Failed to open any port. Shutdown."    keep_mysql=1    fi    signal_exit   fi