![]() |
|
Guide Auto-Start Python and Flask Apps After Reboot in aaPanel - Printable Version +- AdminsForum (https://adminsforum.com) +-- Forum: Free & open-source control panels (https://adminsforum.com/Forum-free-open-source-control-panels) +--- Forum: aaPanel (https://adminsforum.com/Forum-aapanel) +---- Forum: aaPanel Guides & Tutorials (https://adminsforum.com/Forum-aapanel-guides-tutorials) +----- Forum: aaPanel Websites & Web Servers Guides (https://adminsforum.com/Forum-aapanel-websites-web-servers-guides) +----- Thread: Guide Auto-Start Python and Flask Apps After Reboot in aaPanel (/Thread-guide-auto-start-python-and-flask-apps-after-reboot-in-aapanel) |
Auto-Start Python and Flask Apps After Reboot in aaPanel - DEV - 10-14-2026 A Python project that works today can remain offline after a VPS reboot unless its startup setting is enabled. This guide enables aaPanel's native recovery option and verifies that a Flask app actually returns after a real reboot. Tested: Ubuntu 22.04.5 and aaPanel Free 8.0.7, with Flask served by Gunicorn through Nginx. Our project is af_flask_lab and listens on 127.0.0.1:3200. Replace these values with your own project. A reboot temporarily interrupts every service on that VPS; use a lab or a planned maintenance window. 1. Confirm the app is healthy first Complete Run Flask with Gunicorn and, if you need a public hostname, Connect Flask to a Domain and HTTPS. Open Website → Python Project and confirm the application is running. From the VPS terminal: Code: curl -i http://127.0.0.1:3200/2. Enable aaPanel's Startup option Click the project name, then open Project information. Locate Startup and tick the checkbox labelled default built-in daemon checks every 120 seconds. Click Save. Enable the native Startup checkbox for the correct Python project, then save its settings. This setting tells aaPanel to recover the project when its daemon finds it stopped. It is not an immediate availability guarantee: the panel advertises a 120-second check interval. Keep the same working startup command, environment, project path and non-root user. Our command remained: Code: gunicorn --workers 1 --bind 127.0.0.1:3200 app:app3. Recheck HTTP and HTTPS after saving Before rebooting, check localhost and the public hostname again. In our aaPanel 8.0.7 lab, saving the Python project settings regenerated its Nginx configuration and removed the 443 SSL listener. The app still worked on localhost, but public HTTPS selected another site's certificate and failed hostname validation. This is a separate configuration problem, not proof that Gunicorn failed. Check SSL and the project's Nginx Config after saving. Back up the configuration before editing it. For this lab we restored the HTTPS listener and the existing certificate references, validated Nginx configuration and reloaded Nginx. We did not issue another certificate. The existing certificate paths in this lab were: Code: /www/server/panel/vhost/cert/af_flask_lab/fullchain.pem
/www/server/panel/vhost/cert/af_flask_lab/privkey.pem4. Record the current boot before rebooting From the VPS terminal: Code: cat /proc/sys/kernel/random/boot_idReboot only after your work is saved and you have a working way to reconnect. In a disposable test VPS, a normal reboot command is: Code: sudo reboot5. Verify recovery without manually starting the app Reconnect through SSH after the VPS is reachable. Check: Code: cat /proc/sys/kernel/random/boot_id
ss -lntp | grep ':3200'
curl -i http://127.0.0.1:3200/
curl -i https://your-hostname/Our new boot ID differed from the original. Gunicorn returned automatically with a master and worker listening on 127.0.0.1:3200. After restoring the SSL listener described above, the public Flask hostname returned HTTP 200 with AdminsForum Flask lab and passed certificate validation. Nginx, Postfix and Dovecot were also active. 6. Inspect logs if recovery fails In the project window, open Project logs. Check the latest startup attempt rather than old messages. For this project, the error log was: Code: /www/wwwlogs/python/af_flask_lab/error.logKnow the limits of this test
Completion checklist
Tested on the AdminsForum lab VPS. Screenshot and test results are from our own deployment. |