From e1c3f0e50bdde8dda9400315eb440f8d43d69c88 Mon Sep 17 00:00:00 2001 From: w Date: Fri, 18 Jul 2025 00:44:11 -0300 Subject: [PATCH] Add environment mode support and WSGI configuration - Introduced environment mode variable to control bot and web server behavior. - Updated startup script to run Gunicorn in production mode and Flask in development mode. - Created a new WSGI entry point for the web application. --- startup.sh | 10 +++++++++- web/__init__.py | 0 web/app.py | 8 ++++++-- web/wsgi.py | 18 ++++++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 web/__init__.py create mode 100644 web/wsgi.py diff --git a/startup.sh b/startup.sh index 3741e71..7ac4c90 100755 --- a/startup.sh +++ b/startup.sh @@ -22,6 +22,10 @@ cd "$(dirname "$0")" # Activate virtual environment source venv/bin/activate +# Read the environment mode +ENV_MODE=${KEMOVERSE_ENV:-prod} +echo "Running in '$ENV_MODE' mode..." + # Start the bot echo "Starting bot..." python3 bot/bot_app.py & @@ -31,7 +35,11 @@ BOT_PID=$! # Start the website echo "Starting web server..." -python3 web/app.py & +if [ "$ENV_MODE" = "dev" ]; then + python3 web/app.py & +else + gunicorn -w 4 -b 127.0.0.1:8000 web.wsgi:app & +fi # Save the web PID too WEB_PID=$! diff --git a/web/__init__.py b/web/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/web/app.py b/web/app.py index ef22a6f..7c19ffa 100644 --- a/web/app.py +++ b/web/app.py @@ -108,5 +108,9 @@ def player_list(): return render_template('player_list.html', players=[]) return render_template('player_list.html', players=players) -if __name__ == '__main__': - app.run(host=config.BIND_ADDRESS, port=config.WEB_PORT, debug=True) +if __name__ == '__main__' and os.environ.get("KEMOVERSE_ENV") == "dev": + app.run( + host=config.BIND_ADDRESS, + port=config.WEB_PORT, + debug=True, + ) \ No newline at end of file diff --git a/web/wsgi.py b/web/wsgi.py new file mode 100644 index 0000000..c2b024b --- /dev/null +++ b/web/wsgi.py @@ -0,0 +1,18 @@ +#Kemoverse - a gacha-style bot for the Fediverse. +#Copyright © 2025 Waifu +# +#This program is free software: you can redistribute it and/or modify +#it under the terms of the GNU Affero General Public License as +#published by the Free Software Foundation, either version 3 of the +#License, or (at your option) any later version. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU Affero General Public License for more details. +# +#You should have received a copy of the GNU Affero General Public License +#along with this program. If not, see https://www.gnu.org/licenses/. + +from .app import app +