2018-09-26 01:45:08 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
2018-07-27 22:22:17 +08:00
|
|
|
PORT=5000
|
2018-09-26 01:45:08 +08:00
|
|
|
BASE_DIR=$(cd $(dirname $0) && pwd)
|
2018-07-31 18:54:39 +08:00
|
|
|
PIDFILE=$BASE_DIR/riot.pid
|
2018-07-31 17:41:01 +08:00
|
|
|
CONFIG_BACKUP=config.e2etests_backup.json
|
|
|
|
|
|
|
|
if [ -f $PIDFILE ]; then
|
2018-08-14 18:53:16 +08:00
|
|
|
exit
|
2018-07-31 17:41:01 +08:00
|
|
|
fi
|
|
|
|
|
2018-07-31 18:54:39 +08:00
|
|
|
cd $BASE_DIR/
|
|
|
|
echo -n "starting riot on http://localhost:$PORT ... "
|
2018-07-27 19:29:59 +08:00
|
|
|
pushd riot-web/webapp/ > /dev/null
|
2018-07-28 01:27:53 +08:00
|
|
|
|
|
|
|
# backup config file before we copy template
|
|
|
|
if [ -f config.json ]; then
|
2018-08-14 18:53:16 +08:00
|
|
|
mv config.json $CONFIG_BACKUP
|
2018-07-28 01:27:53 +08:00
|
|
|
fi
|
|
|
|
cp $BASE_DIR/config-template/config.json .
|
|
|
|
|
2018-07-31 18:54:39 +08:00
|
|
|
LOGFILE=$(mktemp)
|
|
|
|
# run web server in the background, showing output on error
|
|
|
|
(
|
2018-09-26 01:45:08 +08:00
|
|
|
source $BASE_DIR/env/bin/activate
|
|
|
|
python -m ComplexHTTPServer $PORT > $LOGFILE 2>&1 &
|
2018-08-14 18:53:16 +08:00
|
|
|
PID=$!
|
|
|
|
echo $PID > $PIDFILE
|
|
|
|
# wait so subshell does not exit
|
|
|
|
# otherwise sleep below would not work
|
|
|
|
wait $PID; RESULT=$?
|
2018-07-31 18:54:39 +08:00
|
|
|
|
2018-08-14 18:53:16 +08:00
|
|
|
# NOT expected SIGTERM (128 + 15)
|
|
|
|
# from stop.sh?
|
|
|
|
if [ $RESULT -ne 143 ]; then
|
|
|
|
echo "failed"
|
|
|
|
cat $LOGFILE
|
|
|
|
rm $PIDFILE 2> /dev/null
|
|
|
|
fi
|
|
|
|
rm $LOGFILE
|
|
|
|
exit $RESULT
|
2018-07-31 18:54:39 +08:00
|
|
|
)&
|
|
|
|
# to be able to return the exit code for immediate errors (like address already in use)
|
|
|
|
# we wait for a short amount of time in the background and exit when the first
|
2018-09-26 01:45:08 +08:00
|
|
|
# child process exits
|
2018-07-31 18:54:39 +08:00
|
|
|
sleep 0.5 &
|
|
|
|
# wait the first child process to exit (python or sleep)
|
|
|
|
wait -n; RESULT=$?
|
|
|
|
# return exit code of first child to exit
|
|
|
|
if [ $RESULT -eq 0 ]; then
|
2018-08-14 18:53:16 +08:00
|
|
|
echo "running"
|
2018-07-31 18:54:39 +08:00
|
|
|
fi
|
|
|
|
exit $RESULT
|