You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Pier Fumagalli <pi...@betaversion.org> on 2003/01/24 04:29:21 UTC

[PATCH] New "server" script

If you're trying out that idea of mine for having a cocoon "server"
distribution, I have a _much_ much nicer startup script... (if it's on the
mailing list, I ain't gonna loose it!) :-) Attached...

Also, any thought about my patch for having cocoon.xconf and logkit.xconf
outside of WEB-INF. Can I get that applied??? I'm tired of patching it up on
every machine where I do "cvs co" :-) :-) :-)

Have fun...

    Pier

#!/bin/sh

######################################################################
# _realpath():                                                       #
#   Given a directory name, outputs its real absolute path name.     #
######################################################################
_realpath() {
  REALDIR_PATH="$1"
  REALDIR_TEMP="$PWD"
  cd "$REALDIR_PATH"
  REALDIR_PATH="$PWD"
  cd "$REALDIR_TEMP"
  echo "$REALDIR_PATH"
  unset REALDIR_PATH
  unset REALDIR_TEMP
}

######################################################################
# _realfile():                                                       #
#   Given a path name and a script name resolves the absolute path   #
#   of the script, following symlinks if necessary.                  #
######################################################################
_realfile () {
  # Verify if the script invoked is a symlink to something else
  RESOLVE_PATH="$1"
  RESOLVE_FILE="$2"

  # Figure out the real name of this script
  RESOLVE_TEMP=`expr "$RESOLVE_FILE" : '^\(.*/.*\)$'`
  if test -z "$RESOLVE_TEMP" ; then
    # This script is in a directory specified in the current PATH
    RESOLVE_FILE=`PATH="$PATH:." which "$RESOLVE_FILE"`
  else
    # Check if $RESOLVE_FILE specifies an absolute or relative path
    RESOLVE_TEMP=`expr "$RESOLVE_FILE" : '^\(/.*\)'`
    if test -z "$RESOLVE_TEMP" ; then
      RESOLVE_FILE="$RESOLVE_PATH/$RESOLVE_FILE"
    else
      RESOLVE_FILE="$RESOLVE_FILE"
    fi
  fi

  # Get the real directory name of the script and the file name
  RESOLVE_PATH=`dirname "$RESOLVE_FILE"`
  RESOLVE_PATH=`_realpath "$RESOLVE_PATH"`
  RESOLVE_FILE=`basename "$RESOLVE_FILE"`

  # Check if this was a link otherwise print the resolved name
  if test -h "$RESOLVE_PATH/$RESOLVE_FILE" ; then
    RESOLVE_FILE=`ls -ld "$RESOLVE_PATH/$RESOLVE_FILE"`
    RESOLVE_FILE=`expr "$RESOLVE_FILE" : '^.* -> \(.*\)$'`
    _realfile "$RESOLVE_PATH" "$RESOLVE_FILE"
  else
    echo "$RESOLVE_PATH/$RESOLVE_FILE"
    unset RESOLVE_FILE
    unset RESOLVE_PATH
    unset RESOLVE_TEMP
  fi
}

######################################################################
#                                                                    #
#             M A I N  S C R I P T  S T A R T S  H E R E             #
#                                                                    #
######################################################################

######################################################################
# Initialization: discovery of COCOON_HOME and JAVA_HOME
COCOON_VERS="2.1-dev (Jetty/4.2.6-dev)"

# If unspecified, search for the current COCOON_HOME
if test -z "$COCOON_HOME" ; then
  COCOON_HOME=`_realfile "$PWD" "$0"`
  COCOON_HOME=`dirname   "$COCOON_HOME"`
  COCOON_HOME=`_realpath "$COCOON_HOME/.."`
fi
test -x "$COCOON_HOME/bin/cocoon" || {
  echo "Invalid or unspecified COCOON_HOME"
  exit 1
}

# If unspecified, search for the current JAVA_HOME
if test -z "$JAVA_HOME" ; then
  if test "`uname -s`" = "Darwin" ; then
    JAVA_HOME="/Library/Java/Home"
  else
    JAVA_HOME=`_realfile "$PWD" "java"`
    JAVA_HOME=`dirname   "$JAVA_HOME"`
    JAVA_HOME=`_realpath "$JAVA_HOME"`
  fi
fi
test -x "$JAVA_HOME/bin/java" || {
  echo "Invalid or unspecified JAVA_HOME"
  exit 1
}

######################################################################
# Start processing command line arguments

# Set initial configuration file name
COCOON_CFGS="$COCOON_HOME/conf/server.xml"

# Examine command line parameters one-by-one
while test -n "$1" ; do
  case "$1" in
  start|stop)
    break
    ;;
  -help)
    echo "Cocoon Server version $COCOON_VERS"
    echo ""
    echo "Usage: `basename $0` [options] (start|stop)"
    echo ""
    echo "  Options:"
    echo "    -help        Print this help message"
    echo "    -showversion Display version numbers and continue"
    echo "    -version     Display version numbers and exit"
    echo "    -showenv     Display runtime parameters and continue"
    echo "    -admin       Enable the web-based admin interface"
    echo "    -...         Any other option passed to the Java VM"
    echo "                 (See: $JAVA_HOME/bin/java -help)"
    echo ""
    echo "  Tasks:"
    echo "    start        Start the Cocoon Server"
    echo "    stop         Stop the Cocoon Server"
    echo ""
    echo "  Environment Variables:"
    echo "    COCOON_HOME  The Cocoon Server home directory."
    echo "                 (Now: $COCOON_HOME)"
    echo "    JAVA_HOME    The Java Virtual Machine home directory."
    echo "                 (Now: $JAVA_HOME)"
    echo "    JAVA_OPTS    Additional options passed to the Java"
    echo "                 virtual machine"
    echo ""
    echo "  Relevant links:"
    echo "    http://cocoon.apache.org/ (Apache Cocoon)"
    echo "    http://jetty.mortbay.org/ (Jetty)"
    echo ""
    exit 0
    ;;
  -showenv)
    COCOON_SHOW="true"
    ;;
  -showversion)
    echo "Cocoon Server version $COCOON_VERS"
    "$JAVA_HOME/bin/java" $JAVA_OPTS -version
    ;;
  -version)
    echo "Cocoon Server version $COCOON_VERS"
    "$JAVA_HOME/bin/java" $JAVA_OPTS -version
    exit 0
    ;;
  -admin)
    COCOON_CFGS="$COCOON_CFGS $COCOON_HOME/conf/admin.xml"
    ;;
  -*)
    if test -z "$JAVA_OPTS" ; then
      JAVA_OPTS="$1"
    else
      JAVA_OPTS="$JAVA_OPTS $1"
    fi
    ;;
  *)
    echo "Unrecognized option: $1"
    echo "Unable to start Cocoon Server"
    exit 1
    ;;
  esac
  shift
done

# Remember remaining command line arguments
COCOON_ARGS="$@"

######################################################################
# Process the CLASSPATH (use shell parameter expansion with echo)

COCOON_CPTH=`echo "$COCOON_HOME"/server/*.jar | sed 's| |:|g'`
COCOON_CPTH="$COCOON_CPTH:$COCOON_HOME/classes"
if test -n "$CLASSPATH" ; then
  COCOON_CPTH="$COCOON_CPTH:$CLASSPATH"
fi

######################################################################
# Display (if appropriate) the current environment (debugging)

if test "$COCOON_SHOW" = "true" ; then
  echo "Cocoon Args:    \"$COCOON_ARGS\""
  echo "Cocoon Home:    \"$COCOON_HOME\""
  echo "Java Home:      \"$JAVA_HOME\""
  echo "Java Options:   \"$JAVA_OPTS\""

  # Tricky! :-) Handle multiple configuration files nicely
  OLDIFS="$IFS" ; IFS=" " ; set $COCOON_CFGS ; IFS="$OLDIFS"
  echo "Configurations: \"$1\"" ; shift
  while test -n "$1" ; do
    echo "                \"$1\"" ; shift
  done

  # TrickyToo! :-) Process classpath entries nicely
  OLDIFS="$IFS" ; IFS=":" ; set $COCOON_CPTH ; IFS="$OLDIFS"
  echo "Classpath:      \"$1\"" ; shift
  while test -n "$1" ; do
    echo "                \"$1\"" ; shift
  done

  # All nicely printed
  echo ""
fi

######################################################################
# Go for it

set $COCOON_ARGS
case "$1" in
start)
  echo "$$" > "$COCOON_HOME/logs/cocoon.pid"
  exec "$JAVA_HOME/bin/java" $JAVA_OPTS \
    -classpath "$COCOON_CPTH" \
    -Dcocoon.home="$COCOON_HOME" \
    -Djetty.home="$COCOON_HOME" \
    org.mortbay.jetty.Server \
    $COCOON_CFGS $COCOON_ARGS
  ;;
stop)
  echo "Kill manually (not written yet)"
  ;;
esac
exit 0


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org