7 # ------------------------------------------------------------------------------------------
 
    9 #                             Utility script to locally run JLigier.
 
   11 # ------------------------------------------------------------------------------------------
 
   13 if [ -z $JPP_DIR ]; then
 
   14     echo "Variable JPP_DIR undefined."
 
   18 source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
 
   20 set_variable   PORT            5553          
 
   21 set_variable   TIMEOUT_US      3000          
 
   22 set_variable:  DEBUG           JNET_DEBUG     1
 
   23 set_variable:  WORKDIR         JNET_WORKDIR   ${TMPDIR:-/tmp}/         
 
   24 set_variable   APPLICATION     JLigier
 
   27     usage  "$script [port] <option>"\
 
   28            "\nPossible options: start, stop, continue, restart."
 
   32     2) set_variable  OPTION  $2
 
   33        set_variable  PORT    $1;;
 
   34     1) set_variable  OPTION  $1;;
 
   38 if   [[ $OPTION != "start" && $OPTION != "stop" && $OPTION != "continue" && $OPTION != "restart" ]]; then
 
   39     fatal "Invalid option $OPTION."    
 
   46 if [[ $(uname) == "Darwin" ]]; then
 
   47   alias get_pid="pgrep -lf '${APPLICATION} -P ${PORT}' | cut -d ' ' -f 1"
 
   49   alias get_pid='eval ps h -o \"%p %a\" -C ${APPLICATION} | eval sed -n \"s/ \*\\\\\(\[0-9\]\*\\\\\) ${APPLICATION} \.\*-P ${PORT}\\\\\( \\\\\|\$\\\\\)\.\*/\\\1/p\"'
 
   53 if   [[ $OPTION == "stop" || $OPTION == "restart" ]]; then
 
   57     if [[ -n $PID ]]; then 
 
   58         notice "Stop $APPLICATION using port $PORT with PID $PID."
 
   62     OPTION=${OPTION/restart/start}
 
   64 elif [[ $OPTION == "continue" ]]; then
 
   68     if [[ -n $PID ]]; then 
 
   69         notice "$APPLICATION using port $PORT is running with PID $PID."
 
   76 if [[ $OPTION = "start" ]]; then
 
   80     if [[ -n $PID ]]; then 
 
   81         fatal "$APPLICATION using port $PORT is already running with PID $PID."
 
   84     notice "$APPLICATION -P $PORT -T $TIMEOUT_US -d $DEBUG --! >& $WORKDIR/ligier.log"
 
   85     nohup   $APPLICATION -P $PORT -T $TIMEOUT_US -d $DEBUG --! >& $WORKDIR/ligier.log &
 
   87     for (( i = 0; $i != 20; ++i )); do
 
   93         if [[ -n $PID ]]; then 
 
   94             notice "$APPLICATION using port $PORT is now running with PID $PID."
 
   99     error "$APPLICATION is not running on $HOST."