2018-05-29 23:54:06 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# This script is needed because of https://www.ctl.io/developers/blog/post/gracefully-stopping-docker-containers/
|
|
|
|
|
2018-11-29 08:06:17 +00:00
|
|
|
types=(saas aws)
|
2018-08-11 18:38:47 +01:00
|
|
|
|
|
|
|
if [ -z "$TYPE" ]; then
|
|
|
|
echo "Please specify one of following types: ${types[@]}"
|
|
|
|
exit 1
|
2018-05-29 23:54:06 +01:00
|
|
|
fi
|
2018-08-11 18:38:47 +01:00
|
|
|
TYPE=$(echo "$TYPE" | tr '[:upper:]' '[:lower:]')
|
2018-05-29 23:54:06 +01:00
|
|
|
|
2018-08-11 18:38:47 +01:00
|
|
|
if [ -z "$TEMPLATE" ]; then
|
|
|
|
case $TYPE in
|
|
|
|
"${types[0]}" )
|
|
|
|
TEMPLATE="/root/tmp/devices.json"
|
|
|
|
;;
|
|
|
|
"${types[1]}" )
|
|
|
|
TEMPLATE="/root/tmp/aws.json"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
"Type $TYPE is not supported! Valid types: ${types[@]}"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "$TEMPLATE" ]; then
|
2018-05-29 23:54:06 +01:00
|
|
|
echo "File not found! Nothing to do!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-08-11 18:38:47 +01:00
|
|
|
echo "[geny_start] Available types: ${types[@]}"
|
|
|
|
echo "[geny_start] Selected type of deployment: $TYPE, Template file: $TEMPLATE"
|
|
|
|
export TYPE=$TYPE
|
|
|
|
export TEMPLATE=$TEMPLATE
|
|
|
|
export TYPES=${types[@]}
|
|
|
|
|
2018-05-29 23:54:06 +01:00
|
|
|
getAbort() {
|
2018-08-11 18:38:47 +01:00
|
|
|
case $TYPE in
|
|
|
|
"${types[0]}" )
|
2019-06-07 08:28:48 +01:00
|
|
|
echo "ABORT SIGNAL detected! Stopping all created instances / emulators..."
|
|
|
|
|
|
|
|
# Get the list of created instances from the instance.txt
|
|
|
|
if [ ! -f "$INSTANCES_PATH" ]; then
|
|
|
|
echo "File not found! Nothing to do!"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
content=$(cat ${INSTANCES_PATH})
|
|
|
|
read -a instances <<< $content
|
|
|
|
echo "All created instances: ${instances[@]}"
|
|
|
|
|
|
|
|
# Stop the instance one by one
|
|
|
|
for i in "${instances[@]}"
|
|
|
|
do
|
|
|
|
echo "stop instance with id \"${i}\""
|
|
|
|
gmsaas instances stop "${i}"
|
|
|
|
echo "stopped"
|
|
|
|
done
|
|
|
|
echo "Done"
|
|
|
|
fi
|
2018-08-11 18:38:47 +01:00
|
|
|
;;
|
|
|
|
"${types[1]}" )
|
|
|
|
contents=$(cat $TEMPLATE)
|
|
|
|
echo "ABORT SIGNAL detected! Detroy all EC2 instance(s)..."
|
2018-08-30 12:35:03 +01:00
|
|
|
./terraform destroy -auto-approve -lock=false
|
2018-08-11 18:38:47 +01:00
|
|
|
;;
|
|
|
|
esac
|
2018-05-29 23:54:06 +01:00
|
|
|
}
|
|
|
|
trap 'getAbort; exit' EXIT
|
|
|
|
|
|
|
|
/usr/bin/supervisord --configuration supervisord.conf
|