From ea8551043f6a2fd0e4131c909715ceed978f91a6 Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 8 Feb 2026 02:08:58 -0600 Subject: [PATCH] v0.17.3 - Updated the way Gunicorn restarts the server --- app.py | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/app.py b/app.py index 0591920..9688439 100644 --- a/app.py +++ b/app.py @@ -28,7 +28,7 @@ app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(hours=1) # 1. Define the version -APP_VERSION = '0.17.2' # Bumped version for modular architecture +APP_VERSION = '0.17.3' # Bumped version for modular architecture # 2. Inject it into all templates automatically @app.context_processor @@ -206,34 +206,34 @@ def deactivate_module(module_key): @app.route('/admin/restart', methods=['POST']) @login_required def restart_server(): - """Restart the Flask server""" if session.get('role') not in ['owner', 'admin']: return jsonify({'success': False, 'message': 'Access denied'}), 403 - import os - import sys - try: - print("\nšŸ”„ Server restart requested by admin...") + import signal + import os + import sys - # Return response first - response = jsonify({'success': True, 'message': 'Server restarting...'}) - - # Schedule restart after response is sent - def restart(): - import time - time.sleep(0.5) # Give time for response to send + # Check if running under Gunicorn + if 'gunicorn' in os.environ.get('SERVER_SOFTWARE', ''): + # Gunicorn: Send HUP to master for graceful reload + master_pid = os.getppid() + os.kill(master_pid, signal.SIGHUP) + return jsonify({'success': True, 'message': 'Server reloading...'}) + else: + # Flask dev server: Restart process + def restart(): + import time + time.sleep(0.5) + if os.name == 'nt': # Windows + os.execv(sys.executable, ['python'] + sys.argv) + else: # Linux/Mac + os.execv(sys.executable, [sys.executable] + sys.argv) + + from threading import Thread + Thread(target=restart).start() + return jsonify({'success': True, 'message': 'Server restarting...'}) - if os.name == 'nt': # Windows - os.execv(sys.executable, ['python'] + sys.argv) - else: # Linux/Mac - os.execv(sys.executable, [sys.executable] + sys.argv) - - from threading import Thread - Thread(target=restart).start() - - return response - except Exception as e: return jsonify({'success': False, 'message': f'Restart failed: {str(e)}'})