Launching a Flask Web App on Startup

http://localhost
.
This is especially problematic when the desire is to launch the app on power-up of the Raspberry Pi 3 that will run the server side. "Run on startup" is one of those tasks that have many different approaches across different flavors of Linux. Each with their advantages and disadvantages, benefits and gotchas.
The first attempt is to write a shell script that launches the Flask web server and the Chromium web browser. This works when executed interactively at the command line logged in as the default user pi
. But it didn't work when executed as a cron
@reboot
job, probably something to do with the fact it would run as root
.
The next effort led to Raspberry Pi documentation, which pointed to the file /etc/rc.local
. We seem to have better luck here - the Flask web server does launch but Chromium web browser still did not.
Further hunting eventually found this page for setting up a Raspberry Pi running Chromium web browser as a web kiosk. Not quite the project at hand, but close enough for the answer to be applicable. This meant leaving Flask startup in /etc/rc.local
and editing the file /home/pi/.config/lxsession/LXDE-pi/autostart
to have it launch chromium-browser with the parameter --kiosk http://localhost:5000/
Upon power-up, this Pi will now launch Flask web server and Chromium web browser to point at that server running on the same device. It works, but it's not clear why these hoops were necessary. It's pretty bewildering for a beginner to try to understand the why behind all these different startup mechanisms. A few hours of reading (sometimes contradictory) documentation did not make the situation any more clear. Sadly, time constraints dictate that we can't get to the bottom of this issue today. Perhaps later.