7# ------------------------------------------------------------------------------------------
9# Utility script to locally run JLigier.
11# ------------------------------------------------------------------------------------------
13if [ -z $JPP_DIR ]; then
14 echo "Variable JPP_DIR undefined."
18source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
21set_variable TIMEOUT_US 3000
22set_variable: DEBUG JNET_DEBUG 1
23set_variable: WORKDIR JNET_WORKDIR ${TMPDIR:-/tmp}/
24set_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;;
35 *) fatal "Wrong number of arguments."
38if [[ $OPTION != "start" && $OPTION != "stop" && $OPTION != "continue" && $OPTION != "restart" ]]; then
39 fatal "Invalid option $OPTION."
46if [[ $(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\"'
53if [[ $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}
64elif [[ $OPTION == "continue" ]]; then
68 if [[ -n $PID ]]; then
69 notice "$APPLICATION using port $PORT is running with PID $PID."
76if [[ $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_$PORT.log"
85 nohup $APPLICATION -P $PORT -T $TIMEOUT_US -d $DEBUG --! >& $WORKDIR/ligier_$PORT.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."