-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.sh
executable file
·61 lines (56 loc) · 1.95 KB
/
server.sh
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
#!/bin/bash
if [[ $# -lt 1 ]] || [[ $1 != "start" && $1 != "restart" && $1 != "stop" ]] ; then
echo "Start, restart or stop simulation and session servers."
echo "Usage: server.sh COMMAND [CONFIG]"
echo "COMMAND: either 'start', 'restart' or 'stop'"
echo "CONFIG: refer to config/*/<CONFIG>.json files"
echo " not needed for 'stop' command"
echo " default to 'local' if not specified"
echo "Examples:"
echo "./server.sh start -- start local session and simulation servers"
echo "./server.sh start cyberbotics1 -- start specific session and simulation servers"
echo "./server.sh start cyberbotics2 -- start only specific simulation server"
echo "./server.sh restart local -- restart local session and simulation servers"
echo "./server.sh stop -- stop all session and simulation servers"
exit
fi
SESSION_PID="log/.session.pid"
SIMULATION_PID="log/.simulation.pid"
if [[ $1 == "restart" || $1 == "stop" ]] ; then
if [ -e $SESSION_PID ] ; then
if kill $(<$SESSION_PID) ; then
echo "Stopped session server ($(<$SESSION_PID))"
fi
rm $SESSION_PID
fi
if [ -e $SIMULATION_PID ] ; then
if kill $(<$SIMULATION_PID) ; then
echo "Stopped simulation server ($(<$SIMULATION_PID))"
fi
rm $SIMULATION_PID
fi
fi
if [[ $1 == "start" || $1 == "restart" ]] ; then
if [[ $# -lt 2 ]] ; then
CONFIG="local"
else
CONFIG=$2
fi
SESSION_CONFIG="config/session/$CONFIG.json"
SIMULATION_CONFIG="config/simulation/$CONFIG.json"
case "$(uname)" in
MSYS_NT*) PYTHON=python ;;
*) PYTHON=python3 ;;
esac
if [ -e $SESSION_CONFIG ] ; then
$PYTHON session_server.py $SESSION_CONFIG >/dev/null &
echo $! > $SESSION_PID
echo "Started $CONFIG session server ($!)"
fi
if [ -e $SIMULATION_CONFIG ] ; then
$PYTHON simulation_server.py $SIMULATION_CONFIG >/dev/null &
echo $! > $SIMULATION_PID
echo "Started $CONFIG simulation server ($!)"
fi
fi
exit