Jpp  master_rocky-43-ge265d140c
the software that should make you happy
JLigier-local.sh
Go to the documentation of this file.
1 #!/bin/zsh
2 #
3 # \author mdejong
4 #
5 script=${0##*/}
6 
7 # ------------------------------------------------------------------------------------------
8 #
9 # Utility script to locally run JLigier.
10 #
11 # ------------------------------------------------------------------------------------------
12 
13 if [ -z $JPP_DIR ]; then
14  echo "Variable JPP_DIR undefined."
15  exit
16 fi
17 
18 source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
19 
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
25 
26 if do_usage $*; then
27  usage "$script [port] <option>"\
28  "\nPossible options: start, stop, continue, restart."
29 fi
30 
31 case $# in
32  2) set_variable OPTION $2
33  set_variable PORT $1;;
34  1) set_variable OPTION $1;;
35  *) usage;;
36 esac
37 
38 if [[ $OPTION != "start" && $OPTION != "stop" && $OPTION != "continue" && $OPTION != "restart" ]]; then
39  fatal "Invalid option $OPTION."
40 fi
41 
42 #
43 # get PID
44 #
45 
46 if [[ $(uname) == "Darwin" ]]; then
47  alias get_pid="pgrep -lf '${APPLICATION} -P ${PORT}' | cut -d ' ' -f 1"
48 else
49  alias get_pid='eval ps h -o \"%p %a\" -C ${APPLICATION} | eval sed -n \"s/ \*\\\\\‍(\[0-9\]\*\\\\\‍) ${APPLICATION} \.\*-P ${PORT}\\\\\‍( \\\\\|\$\\\\\‍)\.\*/\\\1/p\"'
50 fi
51 
52 
53 if [[ $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 
64 elif [[ $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 
74 fi
75 
76 if [[ $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.log"
85  nohup $APPLICATION -P $PORT -T $TIMEOUT_US -d $DEBUG --! >& $WORKDIR/ligier.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."
100 fi
101