From f4fe17696896f5240c1b202bab0cd979f7824470 Mon Sep 17 00:00:00 2001 From: Rogier Neeleman Date: Thu, 29 Jun 2017 18:37:25 +0200 Subject: [PATCH] #1 webserver is replaced by twisted --- .gitignore | 6 ++++++ README.md | 13 +++++++++---- nfgame.py | 2 +- run.sh | 32 +++++++++++++++++++++++--------- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 3e82497..b20b5fc 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,9 @@ # Ignoring the database *.db + +# Ignoring logfiles +*.log + +# Ignoring PID files +*.pid diff --git a/README.md b/README.md index e300061..a27954f 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,12 @@ The next software is needed to run this game: - Python 2.6 or higher OR - Python 3.3 or higher - Flask 0.11 or higher +- Twisted You can install this as root by doing the following: -- Debian: apt-get install python-flask -- FreeBSD: pkg install py27-Flask +- Debian: apt-get install python-flask python-twisted +- FreeBSD: pkg install py27-Flask py27-twisted - pip: pip install Flask Watch out! Raspbian has an old version of flask! (0.10) A raspberry is perfect @@ -38,7 +39,7 @@ Please change the password! cp nfgame.cfg-example nfgame.cfg ## Running the game - ./run.sh + ./run.sh start The site is running on http://1.2.3.4:5000 You can find the administator page for cleaning the database on http://1.2.3.4:5000/admin/password @@ -46,4 +47,8 @@ You can find the administator page for cleaning the database on http://1.2.3.4:5 ## Debug mode You can enable the debug mode by running: - ./run.sh debug + ./run.sh start debug + +## Ending the game + + ./run.sh stop diff --git a/nfgame.py b/nfgame.py index 6b66025..2ecd111 100644 --- a/nfgame.py +++ b/nfgame.py @@ -195,4 +195,4 @@ def delete_user(): return render_template('admin_page.html') if __name__ == '__main__': - app.run() + app.run(threaded=True) diff --git a/run.sh b/run.sh index a235142..58c7293 100755 --- a/run.sh +++ b/run.sh @@ -8,13 +8,6 @@ BINDIP=0.0.0.0 export FLASK_APP=nfgame.py export NFGAME_SETTINGS=nfgame.cfg -# If working in debug mode -if [[ $1 == 'debug' ]]; then - export FLASK_DEBUG=1 -else - export FLASK_DEBUG=0 -fi - # If the database does not exists, create it. if [ ! -f nfgame.db ]; then python -m flask initdb @@ -22,6 +15,27 @@ fi if [ ! -f nfgame.cfg ]; then echo "Please copy nfgame.cfg-example to nfgame.cfg and edit the options!" -else - python -m flask run --host=$BINDIP --port=$RUNPORT + exit 1 +fi + +# If working in debug mode +if [[ $1 == 'start' ]]; then + if [[ $2 == 'debug' ]]; then + export FLASK_DEBUG=1 + python -m flask run --host=$BINDIP --port=$RUNPORT + else + if [ -f twistd.pid ]; then + echo "Game is still running." + echo "Stop the game first, or remove the file twistd.pid" + exit 1 + fi + twistd web --port $RUNPORT --logfile=nfgame.log --wsgi=nfgame.app + echo "Game is started!" + echo "Have fun!" + fi +fi + +if [[ $1 == 'stop' ]]; then + kill `cat twistd.pid` + echo "Game is over!" fi