Roxen.git / server / start

version» Context lines:

Roxen.git/server/start:1:   #!/bin/sh   # - # $Id: start,v 1.246 2012/09/21 08:17:54 grubba Exp $ + # $Id: start,v 1.247 2012/09/26 15:44:15 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:774:      ####### END MySQL      # 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    + start_pid="$$"      #   # Some useful functions   #    - cleanup_pid_file_lock() { -  if [ -z "$pidfile" ]; then return 0; fi -  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 - } -  +    # 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. -  +  if [ "$verbose" -g 1 ]; then +  dp "Checking pid-file lock roxen-$2.$1.pid for configuration $3." +  fi    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. -  if [ "`cat /var/run/roxen-$2.$1.pid 2>/dev/null || cat /var/run/roxen-$2.$1.pid 2>/dev/null`" = "$3" ]; then +  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    return 0    fi    fi    return 1   }    -  + # 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 + } +    # Cleanup after the start-script.   cleanup_start_pid_file() { -  cleanup_pid_file_lock "$$" "start" "$canonicalconf" +  cleanup_pid_file_lock "$start_pid" "start" "$canonicalconf"    [ -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. -  cleanup_pid_file_lock "$roxenpid" "server" +  cleanup_pid_file_lock "$roxenpid" "server" "$canonicalconf"    fi    # Remove the stale pid from the pid-file.    if [ $verbose -gt 1 ]; then    dp "Removing stale pids from $pidfile."    fi -  { echo "x"; echo "$$"; } >"$pidfile" +  { echo "x"; echo "$start_pid"; } >"$pidfile"    fi   }      # 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 has   # a $2 {start,server} lock-file associated with the   # configuration $3.   roxenp() { -  if check_pid_file "$1" "$2" "$3"; then +  if check_pid_file_lock "$1" "$2" "$3"; then    # Check that the process exists as well.    if processp "$1"; then return 0; fi    # Cleanup the lock, since it is stale. -  cleanup_pid_file_lock "$1" "$2" +  cleanup_pid_file_lock "$1" "$2" ""    fi    return 1;   }      # Create a roxen lock-file for PID $1 of type $2   # associated with configuration $3. - lock_pid() { + lock_pid_file() {    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   }
Roxen.git/server/start:876:   signal_exit() {    test "x$once" != x2 && dp "Start script terminating."    trap "" 2 15    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. -  cleanup_pid_file_lock "$ROXEN_PID" "server" +  cleanup_pid_file_lock "$ROXEN_PID" "server" ""    ROXEN_PID=""    dp "Roxen WebServer shutdown."    # FIXME: Consider exiting here.    fi    if [ "x$keep_mysql" = "x" ] ; then    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
Roxen.git/server/start:1071:    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 roxenp "$scriptpid" "start" "$canonicalconf" 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 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."    :    else false; fi    else false; fi    } < "$pidfile" && exit 1    # Minor race here. -  lock_pid $mypid "start" "$canonicalconf" -  { echo "x" && echo $mypid; } > "$pidfile" +  lock_pid_file $start_pid "start" "$canonicalconf" +  { echo "x" && echo $start_pid; } > "$pidfile"    trap cleanup_start_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:1144:    fi    if [ $verbose -gt 0 ]; then    dp "Using configuration from $DIR"    dp "Storing the debug log in ${DEBUGLOG}.1"    dp "You can use the administration interface in the server to see debug info."    else :; fi       if (    (    # Minor race here wrt pid file cleanup. +  +  # 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 +     exec 3>&-    trap signal_exit 2 15    trap "" 1    trap cleanup_start_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
Roxen.git/server/start:1207:    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..."    done    ) &    # Minor race here wrt pid file contents. -  pid=$! +  start_pid=$!    trap "" 0 -  lock_pid_file "$pid" "start" "$canonicalconf" -  [ -z "$pidfile" ] || { echo "x" && echo $pid; } > "$pidfile" -  dp "Forked start script, pid $pid." 2>&3 -  dp "Start script pid $pid." +  dp "Forked start script, pid $start_pid." 2>&3 +  dp "Start script pid $start_pid."    ) 3>&2 </dev/null >"$DEBUGDIR/start_$FILES.output" 2>&1; then    trap "" 0    :    else    dp 'Failed to spawn subshell. -- Permission problem?'    cleanup_start_pid_file    exit 1    fi       # Try to get rid of some fd's.