-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·81 lines (68 loc) · 2.32 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
SERVICE_NAME="ecoSpace Server"
#PATH_TO_JAR="java -Djava.library.path=../native/target -cp ../java/target/ecoSpace-server-java-1.0-SNAPSHOT.jar:./* pt.floraon.ecospace.EcoSpace"
PATH_TO_JAR="java -Djava.library.path=../native/target -jar ../java/target/ecoSpace-server-java-1.0-SNAPSHOT-jar-with-dependencies.jar"
PID_PATH_NAME=/tmp/MyService-pid
PORT=7520
cd dependencies
detectrunning() {
## This could be achieved with filtering using -sTCP:LISTEN but this option is not available
## on lsof v4.78 which is the one bundled with some distros. So we have to do this grep below
newpid=$(lsof -i :$PORT -F T -Ts | grep -i "TST=LISTEN" -B1 | head -n1)
newpid=${newpid:1}
}
case $1 in
start)
echo "Starting $SERVICE_NAME ..."
if [ ! -f $PID_PATH_NAME ]; then
nohup $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
echo $! > $PID_PATH_NAME
STARTED_PID=$(cat $PID_PATH_NAME);
echo -n "Waiting for server to be ready."
while kill -0 $STARTED_PID 2> /dev/null ; do
## wait for start, pick up the server listening on the port
detectrunning
if [ $newpid ] ; then
break
fi
printf "."
sleep 1
done
printf "\n$SERVICE_NAME started with pid=$newpid!\n\n"
else
echo "$SERVICE_NAME is already running"
fi
;;
stop)
if [ -f $PID_PATH_NAME ]; then
PID=$(cat $PID_PATH_NAME);
echo "$SERVICE_NAME stoping..."
kill $PID;
echo "$SERVICE_NAME stopped."
rm $PID_PATH_NAME
else
echo "$SERVICE_NAME is not running"
fi
;;
restart)
if [ -f $PID_PATH_NAME ]; then
PID=$(cat $PID_PATH_NAME);
echo "$SERVICE_NAME stopping...";
kill $PID;
echo "$SERVICE_NAME stopped ...";
rm $PID_PATH_NAME
echo "$SERVICE_NAME starting ..."
nohup $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
echo $! > $PID_PATH_NAME
echo "$SERVICE_NAME started ..."
else
echo "$SERVICE_NAME is not running ..."
fi
;;
direct)
$PATH_TO_JAR
;;
*)
echo "Usage: run { start | stop | restart | direct }"
exit 0;;
esac