Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 21.35 KB | None | 0 0
  1. #! /bin/sh
  2.  
  3. # Copyright (c) 1999, 2006 Tanuki Software Inc.
  4. #
  5. # Java Service Wrapper sh script.  Suitable for starting and stopping
  6. #  wrapped Java applications on UNIX platforms.
  7.  
  8. # Get the fully qualified path to the script
  9. case $0 in
  10.     /*)
  11.         SCRIPT="$0"
  12.         ;;
  13.     *)
  14.         PWD=`pwd`
  15.         SCRIPT="$PWD/$0"
  16.         ;;
  17. esac
  18.  
  19. # Resolve the true real path without any sym links.
  20. CHANGED=true
  21. while [ "X$CHANGED" != "X" ]
  22. do
  23.     # Change spaces to ":" so the tokens can be parsed.
  24.     SAFESCRIPT=`echo $SCRIPT | sed -e 's; ;:;g'`
  25.     # Get the real path to this script, resolving any symbolic links
  26.     TOKENS=`echo $SAFESCRIPT | sed -e 's;/; ;g'`
  27.     REALPATH=
  28.     for C in $TOKENS; do
  29.         # Change any ":" in the token back to a space.
  30.         C=`echo $C | sed -e 's;:; ;g'`
  31.         REALPATH="$REALPATH/$C"
  32.         # If REALPATH is a sym link, resolve it.  Loop for nested links.
  33.         while [ -h "$REALPATH" ] ; do
  34.             LS="`ls -ld "$REALPATH"`"
  35.             LINK="`expr "$LS" : '.*-> \(.*\)$'`"
  36.             if expr "$LINK" : '/.*' > /dev/null; then
  37.                 # LINK is absolute.
  38.                 REALPATH="$LINK"
  39.             else
  40.                 # LINK is relative.
  41.                 REALPATH="`dirname "$REALPATH"`""/$LINK"
  42.             fi
  43.         done
  44.     done
  45.  
  46.     if [ "$REALPATH" = "$SCRIPT" ]
  47.     then
  48.         CHANGED=""
  49.     else
  50.         SCRIPT="$REALPATH"
  51.     fi
  52. done
  53.  
  54. # Save the startup directory
  55. STARTUP_DIR=`pwd`
  56.  
  57. # Change the current directory to the location of the script
  58. cd "`dirname "$REALPATH"`"
  59. REALDIR=`pwd`
  60.  
  61. ######################################################################
  62. # Customized for Mule
  63. ######################################################################
  64.  
  65. # Check for MULE_HOME
  66. if [ -z "$MULE_HOME" ] ; then
  67.     # REALDIR points to $MULE_HOME/bin now, strip off the bin part so
  68.     # we get a proper MULE_HOME instead of a relative path
  69.     MULE_HOME="`dirname "${REALDIR}"`"
  70. fi
  71.  
  72. # strip a potential trailing slash in MULE_HOME. This is required to build a
  73. # valid path for WRAPPER_CMD below which is used when running the stop
  74. # command
  75. MULE_HOME=`echo ${MULE_HOME} | sed -e 's/\/$//'`
  76. export MULE_HOME
  77. echo "MULE_HOME is set to ${MULE_HOME}"
  78.  
  79. # If MULE_BASE is not set, set it to MULE_HOME
  80. if [ -z "$MULE_BASE" ] ; then
  81.     MULE_BASE=$MULE_HOME
  82. fi
  83. export MULE_BASE
  84.  
  85. # Application
  86. if [ "$MULE_APP" = "" ]
  87. then
  88.     MULE_APP="mule"
  89. fi
  90. export MULE_APP
  91. if [ "$MULE_APP_LONG" = "" ]
  92. then
  93.     MULE_APP_LONG="Mule"
  94. fi
  95. export MULE_APP_LONG
  96. APP_NAME=${MULE_APP}
  97. APP_LONG_NAME=${MULE_APP_LONG}
  98.  
  99. # Wrapper
  100. WRAPPER_CMD="${MULE_HOME}/lib/boot/exec/wrapper"
  101. WRAPPER_CONF="${MULE_BASE}/conf/wrapper.conf"
  102.  
  103. # add XML compatibility jars
  104. MULE_ENDORSED=-M-Djava.endorsed.dirs="${MULE_HOME}/lib/endorsed"
  105.  
  106. MULE_OPTS="wrapper.working.dir=\"$STARTUP_DIR\" \
  107.           wrapper.app.parameter.1=$2 \
  108.           wrapper.app.parameter.2=$3 \
  109.           wrapper.app.parameter.3=$4 \
  110.           wrapper.app.parameter.4=$5 \
  111.           wrapper.app.parameter.5=$6 \
  112.           wrapper.app.parameter.6=$7 \
  113.           wrapper.app.parameter.7=$8 \
  114.           wrapper.app.parameter.8=$9 \
  115.           wrapper.app.parameter.9=$10"
  116.  
  117. # Configure remote Java debugging options here
  118. # Setting suspend=y will wait for you to connect before proceeding
  119. JPDA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9989"
  120.  
  121. ######################################################################
  122.  
  123. # Priority at which to run the wrapper.  See "man nice" for valid priorities.
  124. #  nice is only used if a priority is specified.
  125. PRIORITY=
  126.  
  127. # Location of the pid file.
  128. PIDDIR="."
  129.  
  130. # If uncommented, causes the Wrapper to be shutdown using an anchor file.
  131. #  When launched with the 'start' command, it will also ignore all INT and
  132. #  TERM signals.
  133. #IGNORE_SIGNALS=true
  134.  
  135. # If specified, the Wrapper will be run as the specified user.
  136. # IMPORTANT - Make sure that the user has the required privileges to write
  137. #  the PID file and wrapper.log files.  Failure to be able to write the log
  138. #  file will cause the Wrapper to exit without any way to write out an error
  139. #  message.
  140. # NOTE - This will set the user which is used to run the Wrapper as well as
  141. #  the JVM and is not useful in situations where a privileged resource or
  142. #  port needs to be allocated prior to the user being changed.
  143. #RUN_AS_USER=
  144.  
  145. # The following two lines are used by the chkconfig command. Change as is
  146. #  appropriate for your application.  They should remain commented.
  147. # chkconfig: 2345 20 80
  148. # description: Mule
  149.  
  150. #-----------------------------------------------------------------------------
  151.  
  152. LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MULE_HOME/lib/native/profiler
  153.  
  154. # If the PIDDIR is relative, set its value relative to the full REALPATH to avoid problems if
  155. #  the working directory is later changed.
  156. FIRST_CHAR=`echo $PIDDIR | cut -c1,1`
  157. if [ "$FIRST_CHAR" != "/" ]
  158. then
  159.     PIDDIR=$REALDIR/$PIDDIR
  160. fi
  161. # Same test for WRAPPER_CMD
  162. FIRST_CHAR=`echo $WRAPPER_CMD | cut -c1,1`
  163. if [ "$FIRST_CHAR" != "/" ]
  164. then
  165.     WRAPPER_CMD=$REALDIR/$WRAPPER_CMD
  166. fi
  167. # Same test for WRAPPER_CONF
  168. FIRST_CHAR=`echo $WRAPPER_CONF | cut -c1,1`
  169. if [ "$FIRST_CHAR" != "/" ]
  170. then
  171.     WRAPPER_CONF=$REALDIR/$WRAPPER_CONF
  172. fi
  173.  
  174. # Process ID
  175. ANCHORFILE="$PIDDIR/$APP_NAME.anchor"
  176. ######################################################################
  177. # Patched for Mule
  178. ######################################################################
  179. PIDFILE="$PIDDIR/.$APP_NAME.pid"
  180. ######################################################################
  181. LOCKDIR="/var/lock/subsys"
  182. LOCKFILE="$LOCKDIR/$APP_NAME"
  183. pid=""
  184.  
  185. # Resolve the location of the 'ps' command
  186. PSEXE="/usr/ucb/ps"
  187. if [ ! -x "$PSEXE" ]
  188. then
  189.     PSEXE="/usr/bin/ps"
  190.     if [ ! -x "$PSEXE" ]
  191.     then
  192.         PSEXE="/bin/ps"
  193.         if [ ! -x "$PSEXE" ]
  194.         then
  195.             echo "Unable to locate 'ps'."
  196.             echo "Please report this message along with the location of the command on your system."
  197.             exit 1
  198.         fi
  199.     fi
  200. fi
  201. PSKEYWORD="args"
  202.  
  203. # Resolve the os
  204. DIST_OS=`uname -s | tr [:upper:] [:lower:] | tr -d [:blank:]`
  205. case "$DIST_OS" in
  206.     'sunos')
  207.         DIST_OS="solaris"
  208.         ;;
  209.     'hp-ux' | 'hp-ux64')
  210.         DIST_OS="hpux"
  211.         ;;
  212.     'darwin')
  213.         DIST_OS="macosx"
  214.         PSKEYWORD="command"
  215.         ;;
  216.     'unix_sv')
  217.         DIST_OS="unixware"
  218.         ;;
  219.     'aix')
  220.         DIST_OS="aix"
  221.         ;;
  222. esac
  223.  
  224. ######################################################################
  225. # Patched for Mule (MULE-1288, MULE-1322, MULE-1337, MULE-1396)
  226. ######################################################################
  227.  
  228. # Resolve the architecture
  229. UNAME_PROC_OPTION="-m"
  230. if [ "$DIST_OS" = "aix" ]; then
  231.     UNAME_PROC_OPTION="-p"
  232. fi
  233.  
  234. PROC_ARCH=`uname $UNAME_PROC_OPTION | tr [:upper:] [:lower:] | tr -d [:blank:]`
  235.  
  236. # The previous approach was this:
  237. # If a 32-bit wrapper binary exists then it will work on 32 or 64 bit
  238. # platforms, if the 64-bit binary exists then the distribution most
  239. # likely wants to use long names.
  240. DIST_BITS="32"
  241.  
  242. while :
  243. do
  244.     case "$PROC_ARCH" in
  245.         'amd64' | 'athlon' | 'i386' | 'i486' | 'i586' | 'i686' | 'i86pc')
  246.             DIST_ARCH="x86"
  247.             break;;
  248.         'x86_64')
  249.             DIST_ARCH="x86"
  250.             # on 64 bit Linuxes the 32 bit subsystem may not be installed so
  251.             # let's use the 64 bit wrapper
  252.             DIST_BITS="64"
  253.             break;;
  254.         'ia32' | 'ia64')
  255.              DIST_ARCH="ia"
  256.             break;;
  257.         'ip27')
  258.             DIST_ARCH="mips"
  259.             break;;
  260.         'power' | 'powerpc' | 'power_pc' | 'ppc64' | 'powermacintosh')
  261.             DIST_ARCH="ppc"
  262.             break;;
  263.         'pa_risc' | 'pa-risc')
  264.             DIST_ARCH="parisc"
  265.             break;;
  266.         'sun4u' | 'sun4us' | 'sun4v' | 'sparcv9' | 'sparc')
  267.             DIST_ARCH="sparc"
  268.             break;;
  269.         '9000/800')
  270.             DIST_ARCH="parisc"
  271.             break;;
  272.         *)
  273.             echo "Your machine's hardware type (uname $UNAME_PROC_OPTION) was not recognized by the Service Wrapper as a supported platform."
  274.             echo "Please report this message along with your machine's processor/architecture."
  275.             exit 1
  276.             ;;
  277.     esac
  278. done
  279. ######################################################################
  280.  
  281. outputFile() {
  282.     if [ -f "$1" ]
  283.     then
  284.         echo "  $1 (Found but not executable.)";
  285.     else
  286.         echo "  $1"
  287.     fi
  288. }
  289.  
  290. WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS"
  291. if [ -x "$WRAPPER_TEST_CMD" ]
  292. then
  293.     WRAPPER_CMD="$WRAPPER_TEST_CMD"
  294. else
  295.     if [ "$DIST_OS" = "macosx" ]
  296.     then
  297.         WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-universal-32"
  298.         if [ -x "$WRAPPER_TEST_CMD" ]
  299.         then
  300.             WRAPPER_CMD="$WRAPPER_TEST_CMD"
  301.         else
  302.             WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-64"
  303.             if [ -x "$WRAPPER_TEST_CMD" ]
  304.             then
  305.                 WRAPPER_CMD="$WRAPPER_TEST_CMD"
  306.             else
  307.                 WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-universal-64"
  308.                 if [ -x "$WRAPPER_TEST_CMD" ]
  309.                 then
  310.                     WRAPPER_CMD="$WRAPPER_TEST_CMD"
  311.                 else
  312.                     if [ ! -x "$WRAPPER_CMD" ]
  313.                     then
  314.                         echo "Unable to locate any of the following binaries:"
  315.                         outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
  316.                         outputFile "$WRAPPER_CMD-$DIST_OS-universal-32"
  317.                         outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-64"
  318.                         outputFile "$WRAPPER_CMD-$DIST_OS-universal-64"
  319.                         outputFile "$WRAPPER_CMD"
  320.                         exit 1
  321.                     fi
  322.                 fi
  323.             fi
  324.         fi
  325.     else
  326.         if [ ! -x "$WRAPPER_CMD" ]
  327.         then
  328.             echo "Unable to locate any of the following binaries:"
  329.             outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
  330.             outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-64"
  331.             outputFile "$WRAPPER_CMD"
  332.             exit 1
  333.         fi
  334.     fi
  335. fi
  336.  
  337. # Build the nice clause
  338. if [ "X$PRIORITY" = "X" ]
  339. then
  340.     CMDNICE=""
  341. else
  342.     CMDNICE="nice -$PRIORITY"
  343. fi
  344.  
  345. # Build the anchor file clause.
  346. if [ "X$IGNORE_SIGNALS" = "X" ]
  347. then
  348.    ANCHORPROP=
  349.    IGNOREPROP=
  350. else
  351.    ANCHORPROP=wrapper.anchorfile=\"$ANCHORFILE\"
  352.    IGNOREPROP=wrapper.ignore_signals=TRUE
  353. fi
  354.  
  355. # Build the lock file clause.  Only create a lock file if the lock directory exists on this platform.
  356. LOCKPROP=
  357. if [ -d $LOCKDIR ]
  358. then
  359.     if [ -w $LOCKDIR ]
  360.     then
  361.         LOCKPROP=wrapper.lockfile=\"$LOCKFILE\"
  362.     fi
  363. fi
  364.  
  365. checkUser() {
  366.     # $1 touchLock flag
  367.     # $2 command
  368.  
  369.     # Check the configured user.  If necessary rerun this script as the desired user.
  370.     if [ "X$RUN_AS_USER" != "X" ]
  371.     then
  372.         # Resolve the location of the 'id' command
  373.         IDEXE="/usr/xpg4/bin/id"
  374.         if [ ! -x "$IDEXE" ]
  375.         then
  376.             IDEXE="/usr/bin/id"
  377.             if [ ! -x "$IDEXE" ]
  378.             then
  379.                 echo "Unable to locate 'id'."
  380.                 echo "Please report this message along with the location of the command on your system."
  381.                 exit 1
  382.             fi
  383.         fi
  384.  
  385.         if [ "`$IDEXE -u -n`" = "$RUN_AS_USER" ]
  386.         then
  387.             # Already running as the configured user.  Avoid password prompts by not calling su.
  388.             RUN_AS_USER=""
  389.         fi
  390.     fi
  391.     if [ "X$RUN_AS_USER" != "X" ]
  392.     then
  393.         # If LOCKPROP and $RUN_AS_USER are defined then the new user will most likely not be
  394.         # able to create the lock file.  The Wrapper will be able to update this file once it
  395.         # is created but will not be able to delete it on shutdown.  If $2 is defined then
  396.         # the lock file should be created for the current command
  397.         if [ "X$LOCKPROP" != "X" ]
  398.         then
  399.             if [ "X$1" != "X" ]
  400.             then
  401.                 # Resolve the primary group
  402.                 RUN_AS_GROUP=`groups $RUN_AS_USER | awk '{print $3}' | tail -1`
  403.                 if [ "X$RUN_AS_GROUP" = "X" ]
  404.                 then
  405.                     RUN_AS_GROUP=$RUN_AS_USER
  406.                 fi
  407.                 touch $LOCKFILE
  408.                 chown $RUN_AS_USER:$RUN_AS_GROUP $LOCKFILE
  409.             fi
  410.         fi
  411.  
  412.         # Still want to change users, recurse.  This means that the user will only be
  413.         #  prompted for a password once. Variables shifted by 1
  414.         su -m $RUN_AS_USER -c "\"$REALPATH\" $2"
  415.  
  416.         # Now that we are the original user again, we may need to clean up the lock file.
  417.         if [ "X$LOCKPROP" != "X" ]
  418.         then
  419.             getpid
  420.             if [ "X$pid" = "X" ]
  421.             then
  422.                 # Wrapper is not running so make sure the lock file is deleted.
  423.                 if [ -f "$LOCKFILE" ]
  424.                 then
  425.                     rm "$LOCKFILE"
  426.                 fi
  427.             fi
  428.         fi
  429.  
  430.         exit 0
  431.     fi
  432. }
  433.  
  434. getpid() {
  435.     if [ -f "$PIDFILE" ]
  436.     then
  437.         if [ -r "$PIDFILE" ]
  438.         then
  439.             pid=`cat "$PIDFILE"`
  440.             if [ "X$pid" != "X" ]
  441.             then
  442.                 # It is possible that 'a' process with the pid exists but that it is not the
  443.                 #  correct process.  This can happen in a number of cases, but the most
  444.                 #  common is during system startup after an unclean shutdown.
  445.                 # The ps statement below looks for the specific wrapper command running as
  446.                 #  the pid.  If it is not found then the pid file is considered to be stale.
  447.                 ######################################################################
  448.                 # TODO MULE-2052: ps -o args gets truncated to 80 columns on Solaris which makes
  449.                 # this test fail if the path is too long.
  450.                 # http://sourceforge.net/tracker/index.php?func=detail&aid=1664303&group_id=39428&atid=425187
  451.                 ######################################################################
  452.                 if [ "$DIST_OS" = 'solaris' ]
  453.                 then
  454.                     # on Solaris, both /usr/ucb/ps and /usr/bin/ps accept the ww option.
  455.                     # Use it to overcome the truncation issue mentioned above
  456.                     pidtest=`$PSEXE ww $pid | grep "$WRAPPER_CMD" | tail -1`
  457.                 else
  458.                     pidtest=`$PSEXE -p $pid -o $PSKEYWORD | grep "$WRAPPER_CMD" | tail -1`
  459.                 fi
  460.  
  461.                 if [ "X$pidtest" = "X" ]
  462.                 then
  463.                     # This is a stale pid file.
  464.                     rm -f "$PIDFILE"
  465.                     echo "Removed stale pid file: $PIDFILE"
  466.                     pid=""
  467.                 fi
  468.             fi
  469.         else
  470.             echo "Cannot read $PIDFILE."
  471.             exit 1
  472.         fi
  473.     fi
  474. }
  475.  
  476. testpid() {
  477.     if [ "$DIST_OS" = 'solaris' ]
  478.     then
  479.         # on Solaris, both /usr/ucb/ps and /usr/bin/ps accept the ww option.
  480.         pid=`$PSEXE ww $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
  481.     else
  482.         pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
  483.     fi
  484.  
  485.     if [ "X$pid" = "X" ]
  486.     then
  487.         # Process is gone so remove the pid file.
  488.         rm -f "$PIDFILE"
  489.         pid=""
  490.     fi
  491. }
  492.  
  493. console() {
  494.     echo "Running $APP_LONG_NAME..."
  495.     getpid
  496.     if [ "X$pid" = "X" ]
  497.     then
  498.         # The string passed to eval must handle spaces in paths correctly.
  499.         COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=$APP_NAME wrapper.pidfile=\"$PIDFILE\" $ANCHORPROP $LOCKPROP"
  500.         ######################################################################
  501.         # Customized for Mule
  502.         ######################################################################
  503.         eval $COMMAND_LINE $MULE_OPTS
  504.         ######################################################################
  505.     else
  506.         echo "$APP_LONG_NAME is already running."
  507.         exit 1
  508.     fi
  509. }
  510.  
  511. debug() {
  512.     echo "Debugging $APP_LONG_NAME..."
  513.     getpid
  514.     if [ "X$pid" = "X" ]
  515.     then
  516.         # The string passed to eval must handle spaces in paths correctly.
  517.         COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=$APP_NAME wrapper.pidfile=\"$PIDFILE\" $ANCHORPROP $LOCKPROP"
  518.         ######################################################################
  519.         # Customized for Mule
  520.         ######################################################################
  521.  
  522.  
  523.         echo "command line: $COMMAND_LINE"
  524.         echo "mule opts: $MULE_OPTS"
  525.         echo "JPDA_OPTS: $JPDA_OPTS"
  526.  
  527.         eval $COMMAND_LINE $JPDA_OPTS $MULE_OPTS
  528.         ######################################################################
  529.     else
  530.         echo "$APP_LONG_NAME is already running."
  531.         exit 1
  532.     fi
  533. }
  534.  
  535. start() {
  536.     echo "Starting $APP_LONG_NAME..."
  537.     getpid
  538.     if [ "X$pid" = "X" ]
  539.     then
  540.         # The string passed to eval must handles spaces in paths correctly.
  541.         COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=$APP_NAME wrapper.pidfile=\"$PIDFILE\" wrapper.daemonize=TRUE $ANCHORPROP $IGNOREPROP $LOCKPROP"
  542.         ######################################################################
  543.         # Customized for Mule
  544.         ######################################################################
  545.         eval $COMMAND_LINE $MULE_OPTS
  546.         ######################################################################
  547.     else
  548.         echo "$APP_LONG_NAME is already running."
  549.         exit 1
  550.     fi
  551. }
  552.  
  553. stopit() {
  554.     echo "Stopping $APP_LONG_NAME..."
  555.     getpid
  556.     if [ "X$pid" = "X" ]
  557.     then
  558.         echo "$APP_LONG_NAME was not running."
  559.     else
  560.         if [ "X$IGNORE_SIGNALS" = "X" ]
  561.         then
  562.             # Running so try to stop it.
  563.             kill $pid
  564.             if [ $? -ne 0 ]
  565.             then
  566.                 # An explanation for the failure should have been given
  567.                 echo "Unable to stop $APP_LONG_NAME."
  568.                 exit 1
  569.             fi
  570.         else
  571.             rm -f "$ANCHORFILE"
  572.             if [ -f "$ANCHORFILE" ]
  573.             then
  574.                 # An explanation for the failure should have been given
  575.                 echo "Unable to stop $APP_LONG_NAME."
  576.                 exit 1
  577.             fi
  578.         fi
  579.  
  580.         # We can not predict how long it will take for the wrapper to
  581.         #  actually stop as it depends on settings in wrapper.conf.
  582.         #  Loop until it does.
  583.         savepid=$pid
  584.         CNT=0
  585.         TOTCNT=0
  586.         while [ "X$pid" != "X" ]
  587.         do
  588.             # Show a waiting message every 5 seconds.
  589.             if [ "$CNT" -lt "5" ]
  590.             then
  591.                 CNT=`expr $CNT + 1`
  592.             else
  593.                 echo "Waiting for $APP_LONG_NAME to exit..."
  594.                 CNT=0
  595.             fi
  596.             TOTCNT=`expr $TOTCNT + 1`
  597.  
  598.             sleep 1
  599.  
  600.             testpid
  601.         done
  602.  
  603.         pid=$savepid
  604.         testpid
  605.         if [ "X$pid" != "X" ]
  606.         then
  607.             echo "Failed to stop $APP_LONG_NAME."
  608.             exit 1
  609.         else
  610.             echo "Stopped $APP_LONG_NAME."
  611.         fi
  612.     fi
  613. }
  614.  
  615. status() {
  616.     getpid
  617.     if [ "X$pid" = "X" ]
  618.     then
  619.         echo "$APP_LONG_NAME is not running."
  620.         exit 1
  621.     else
  622.         echo "$APP_LONG_NAME is running ($pid)."
  623.         exit 0
  624.     fi
  625. }
  626.  
  627. dump() {
  628.     echo "Dumping $APP_LONG_NAME..."
  629.     getpid
  630.     if [ "X$pid" = "X" ]
  631.     then
  632.         echo "$APP_LONG_NAME was not running."
  633.  
  634.     else
  635.         kill -3 $pid
  636.  
  637.         if [ $? -ne 0 ]
  638.         then
  639.             echo "Failed to dump $APP_LONG_NAME."
  640.             exit 1
  641.         else
  642.             echo "Dumped $APP_LONG_NAME."
  643.         fi
  644.     fi
  645. }
  646.  
  647. checkAdditionalJvmParams() {
  648.     # The string passed to eval must handle spaces in paths correctly.
  649.     "$MULE_HOME/bin/launcher" \"$MULE_HOME/bin/additional.groovy\" \"$WRAPPER_CONF\" \"$JPDA_OPTS\" \"$MULE_ENDORSED\" $@
  650.     EXIT_STATUS=$?
  651.  
  652.     if [ "$EXIT_STATUS" -ne "0" ] ; then
  653.         exit $EXIT_STATUS
  654.     fi
  655. }
  656.  
  657. case "$1" in
  658.  
  659.     'console')
  660.         checkUser touchlock $1
  661.         checkAdditionalJvmParams $*
  662.         console
  663.         ;;
  664.  
  665.     'debug')
  666.         checkUser touchlock $1
  667.         checkAdditionalJvmParams $*
  668.         debug
  669.         ;;
  670.  
  671.     'start')
  672.         checkUser touchlock $1
  673.         checkAdditionalJvmParams $*
  674.         start
  675.         ;;
  676.  
  677.     'stop')
  678.         checkUser "" $1
  679.         stopit
  680.         ;;
  681.  
  682.     'restart')
  683.         checkUser touchlock $1
  684.         stopit
  685.         start
  686.         ;;
  687.  
  688.     'status')
  689.         checkUser "" $1
  690.         status
  691.         ;;
  692.  
  693.     'dump')
  694.         checkUser "" $1
  695.         dump
  696.         ;;
  697.  
  698.     *)
  699.         ######################################################################
  700.         # Customized for Mule
  701.         ######################################################################
  702.         echo "Running in console (foreground) mode by default, use Ctrl-C to exit..."
  703.  
  704.         # Change back to the original startup directory.
  705.         cd "$STARTUP_DIR"
  706.  
  707.         # Call this script recursively with the "console" parameter.
  708.         "$REALPATH" console $*
  709.         ######################################################################
  710.         ;;
  711. esac
  712.  
  713. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement