引导系统后自动启动python flask webserver并保持运行到最后 [英] Start python flask webserver automatically after booting the system and keep it on till the end

查看:311
本文介绍了引导系统后自动启动python flask webserver并保持运行到最后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用flask作为我的UI的网络服务器(这是一个简单的Web界面,它同时通过网络摄像头和 framegrabber /比较简单的播放器,使用ubuntu上的gstreamer来控制录制)

I'm using flask as a webserver for my UI (it's a simple web interface which controls the recording using gstreamer on ubuntu from a webcam and a framegrabber simultaneously / kinda simple player)

每次我都需要运行命令"python main.py"来从命令提示符下手动运行服务器.

Every time I need to run the command "python main.py" to run the server from command prompt manually.

我尝试了init.d解决方案,甚至编写了一个简单的shell脚本,并在每次启动后重新引导系统后每次都启动它,但是它无法保持服务器的正常运行并一直运行到最后(只是调用服务器,然后我猜它终止了)

I've tried the init.d solution or even writing a simple shell script and launching it every time after rebooting the system on start up but it fails to keep the server up and running till the end (just invokes the server and terminates it I guess)

有什么解决方案可以帮助我在启动系统时每次引导后启动Web服务器并保持其正常运行吗?

is there any solution that could help me to start the webserver every time after booting the system on startup and keep it on and running?

我想将我的系统配置为直接启动到浏览器中,因此不需要用户进行更多操作.

I'd like to configure my system to boot directly into the browser so don't wanna have any need for more actions by the user.

感谢您的任何建议/帮助.

Any Kind of suggestion/help is appreciated.

推荐答案

我想建议使用主管,文档为

I'd like to suggest using supervisor, the documentation is here

出于非常简单的演示目的,在安装并完成设置后,请触摸一个新文件,如下所示:

for a very simple demo purpose, after you installed it and finish the set up, touch a new a file like this:

[program:flask_app]                                                                  
command = python main.py                                      
directory = /dir/to/your/app                            
autostart = true                                                                
autorestart = true

然后

$ sudo supervisorctl update

现在,您应该一切顺利.每次启动计算机后,flask应用程序都会启动.(注意:分发软件包已集成到服务管理基础架构中,如果您正在使用其他软件包,请参见

Now, you should be good to go. The flask app will start every time after you boot you machine.(note: distribution package has already integrated into the service management infrastructure, if you're using others, see here)

检查您的应用程序是否正在运行:

to check whether you app is running:

$ sudo supervisorctl status


对于生产,您可以使用nginx + uwsgi + supervisor.烧瓶部署文档位于此处

这篇关于引导系统后自动启动python flask webserver并保持运行到最后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆