simulator_launch.sh
2.12 KB
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
# setting
SIM_FIXTURES="../simulators/fixtures/"
SIM_PATH="../simulators/"
echo -n "Existing simulations : "
ls "$SIM_FIXTURES"
echo -n "Enter which simulation you want to launch : "
read -r line
if [ ! -f "$SIM_FIXTURES"/"$line" ]; then
echo "This simulation doesn't exist"
exit
fi
sed -i -e "s/SIMULATOR_VALUE = None/SIMULATOR_VALUE = '$line'/g" userSimulator/tasks.py
sed -i -e "s/CELERY_TEST = False/CELERY_TEST = True/g" pyros/settings.py
trap ctrl_c INT
function ctrl_c() {
./../pyrosrun.sh kill_simulation
killall ALERTsimulator.py
killall PLCsimulator.py
echo "Ctrl-c catched, all process launched have been killed"
exit
}
rm -f testdb.sqlite3
python manage.py migrate
python manage.py loaddata misc/fixtures/initial_fixture.json
python manage.py loaddata "$SIM_FIXTURES"/"$line"
echo "----------------LAUNCHING WEB SERVER----------------"
python manage.py runserver &
sleep 2
echo "----------------WEB SERVER LAUNCHED-----------------"
echo "----------------------------------------SUMMARY---------------------------------------------"
echo "The simulator has been successfully initialised"
echo "The simulator run on a temp database : src/testdb.sqlite3"
echo "The simulation will be ended by the task 'simulator herself'"
echo "If you want to shutdown the simulation, please run :"
echo "CTRL-C or ./pyrosrun.sh kill_simulation"
echo "If the simulation isn't correctly killed, please switch the variable"
echo "CELERY_TEST in src/pyros/settings.py to false"
echo ""
echo "----------------------------------------SUMMARY---------------------------------------------"
echo ""
read -n1 -r -p "Press any key to continue..." key
#launch simulator workers
./../simulators/scripts/start_simulator_worker.sh 2>&1 /dev/null
#launch simulators binaries
python "$SIM_PATH"/alert/ALERTsimulator.py "$line" &
ALERTPID=$!
python "$SIM_PATH"/plc/PLCsimulator.py "$line" &
PLCPID=$!
echo ""
echo "Waiting for ALERTsimulator to finish"
wait "$ALERTPID"
echo "Alersimulator finished"
echo ""
echo "Waiting for PLCsimulator to finish"
wait "$PLCPID"
echo "PLCsimulator finished"
echo ""
echo "Killing all processes"
./../pyrosrun.sh kill_simulation