Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JLigier-local.sh
Go to the documentation of this file.
1#!/usr/bin/env zsh
2#
3# \author mdejong
4#
5script=${0##*/}
6
7# ------------------------------------------------------------------------------------------
8#
9# Utility script to locally run JLigier.
10#
11# ------------------------------------------------------------------------------------------
12
13if [ -z $JPP_DIR ]; then
14 echo "Variable JPP_DIR undefined."
15 exit
16fi
17
18source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
19
20set_variable PORT 5553
21set_variable TIMEOUT_US 3000
22set_variable: DEBUG JNET_DEBUG 1
23set_variable: WORKDIR JNET_WORKDIR ${TMPDIR:-/tmp}/
24set_variable APPLICATION JLigier
25
26if do_usage $*; then
27 usage "$script [port] <option>"\
28 "\nPossible options: start, stop, continue, restart."
29fi
30
31case $# in
32 2) set_variable OPTION $2
33 set_variable PORT $1;;
34 1) set_variable OPTION $1;;
35 *) fatal "Wrong number of arguments."
36esac
37
38if [[ $OPTION != "start" && $OPTION != "stop" && $OPTION != "continue" && $OPTION != "restart" ]]; then
39 fatal "Invalid option $OPTION."
40fi
41
42#
43# get PID
44#
45
46if [[ $(uname) == "Darwin" ]]; then
47 alias get_pid="pgrep -lf '${APPLICATION} -P ${PORT}' | cut -d ' ' -f 1"
48else
49 alias get_pid='eval ps h -o \"%p %a\" -C ${APPLICATION} | eval sed -n \"s/ \*\\\\\‍(\[0-9\]\*\\\\\‍) ${APPLICATION} \.\*-P ${PORT}\\\\\‍( \\\\\|\$\\\\\‍)\.\*/\\\1/p\"'
50fi
51
52
53if [[ $OPTION == "stop" || $OPTION == "restart" ]]; then
54
55 PID=`get_pid`
56
57 if [[ -n $PID ]]; then
58 notice "Stop $APPLICATION using port $PORT with PID $PID."
59 kill -9 $PID
60 fi
61
62 OPTION=${OPTION/restart/start}
63
64elif [[ $OPTION == "continue" ]]; then
65
66 PID=`get_pid`
67
68 if [[ -n $PID ]]; then
69 notice "$APPLICATION using port $PORT is running with PID $PID."
70 else
71 OPTION=start
72 fi
73
74fi
75
76if [[ $OPTION = "start" ]]; then
77
78 PID=`get_pid`
79
80 if [[ -n $PID ]]; then
81 fatal "$APPLICATION using port $PORT is already running with PID $PID."
82 fi
83
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 &
86
87 for (( i = 0; $i != 20; ++i )); do
88
89 sleep 1
90
91 PID=`get_pid`
92
93 if [[ -n $PID ]]; then
94 notice "$APPLICATION using port $PORT is now running with PID $PID."
95 return 0
96 fi
97 done
98
99 error "$APPLICATION is not running on $HOST."
100fi
101