【问题标题】:How do I update my flask API code deployed over uWSGI and Nginx on ubuntu?如何更新在 ubuntu 上部署在 uWSGI 和 Nginx 上的烧瓶 API 代码?
【发布时间】:2018-01-23 06:44:55
【问题描述】:

我按照指南在这里设置了我的 api:https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-ubuntu-14-04

效果很好,我现在可以成功地对我的 api 进行查询。我的问题是,现在我想调整我的烧瓶应用程序/api 来做一些稍微不同的事情并添加功能,但是我正在 ping 的 API 似乎是旧的,尽管我已经从我的 ssh 更新了服务器上的烧瓶 .py 文件。我尝试完成教程中的所有步骤,我得到了它,希望刷新它访问的代码,但似乎没有任何效果。我尝试过的其中一些命令是:

sudo nginx -t

sudo service nginx restart

如何执行此操作并 ping 更新的烧瓶 .py 文件?

按照nos的建议我试过了:

restart myproject

但这给出了以下错误:

restart: Rejected send message, 1 matched rules; type="method_call", sender=":1.8" (uid=1000 pid=2596 comm="restart thonapi ") interface="com.ubuntu.Upstart0_6.Job" member="Restart" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init ")

【问题讨论】:

    标签: python api ubuntu nginx flask


    【解决方案1】:

    你正在重启 Nginx 但不是 uwsgi。 Nginx 只是一个代理服务器,它将请求路由到 wsgi 应用程序。当您更改 Nginx 的配置时,这些命令将起作用。但是当 wsgi 应用程序发生更改时,您必须重新启动 uwsgi 服务。

    您可以通过以下命令重新启动服务。这取决于使用的是什么初始化系统服务

    如果服务使用 systemd 系统。

    sudo systemctl restart myproject

    否则,如果它使用新贵脚本。

    sudo restart myproject

    如果一切都失败了,你可以使用或者如果你不知道正在使用的初始化系统:

    sudo service restart myproject

    【讨论】:

    • 这给出了以下错误:无法重新启动 myproject.service:没有这样的方法“RestartUnit”,但我通过 sudo restart myproject 让它工作
    • @majorcoder 我错过了您遵循的教程中使用 upstart 作为初始化系统的部分。我已经针对所有类型的系统更新了我的答案。
    【解决方案2】:

    您需要重新启动为此应用程序创建的服务。 您链接到的文档有一个“创建新贵脚本”部分,我假设您已经完成了。这会像服务一样运行您的应用程序,您需要使用以下命令重新启动该服务:

    restart myproject
    

    (或您提供的任何名称,而不是“myproject”)

    【讨论】:

    • 谢谢。我试过这个,但它给出了以下错误:重新启动:拒绝发送消息,1匹配规则; type="method_call", sender=":1.8" (uid=1000 pid=2596 comm="restart thonapi") interface="com.ubuntu.Upstart0_6.Job" member="Restart" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init ")
    • 系统相关的管理任务几乎总是需要以root身份完成,所以试试sudo restart myproject
    • 添加 sudo 做到了!
    猜你喜欢
    • 2017-11-16
    • 2011-07-05
    • 2012-11-28
    • 2019-09-29
    • 2015-07-18
    • 1970-01-01
    • 2015-05-08
    • 2016-03-19
    • 1970-01-01
    相关资源
    最近更新 更多