simulator_launch.sh 2.12 KB
# 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