simulator_launch.sh 2.16 KB
# setting
SCRIPT_PATH=$0
SCRIPT_PATH=${SCRIPT_PATH%/*}

cd $SCRIPT_PATH/..

echo -n "Existing simulations : "
ls misc/fixtures/simulation/
echo -n "Enter which simulation you want to launch : "
read -r line

if [ ! -f misc/fixtures/simulation/"$line" ]; then
  echo "This simulation doesn't exist"
  exit
fi

sed -i -e "s/SIMULATOR_VALUE = None/SIMULATOR_VALUE = '$line'/g" simulator/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 misc/fixtures/simulation/"$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
./scripts/start_simulator_worker.sh 2>&1 /dev/null

#launch simulators binaries
python simulator/alertSimulator/ALERTsimulator.py "$line" &
ALERTPID=$!
python simulator/plcSimulator/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