简体   繁体   English

如何在django,uwsgi和nginx设置中反映python的更改

[英]How to reflect python changes in django, uwsgi and nginx setup

Hi I have deployed Django using UWSGI and Nginx using following tutorial http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html Everything is running fine. 嗨,我已经使用以下教程http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html使用UWSGI和Nginx部署了Django。 I face a challenge while updating python code. 我在更新python代码时面临挑战。 I don't know the efficient way to deploy new changes. 我不知道部署新更改的有效方法。 after hit and trial, I used following commands to deploy 经过反复试验后,我使用以下命令进行部署

git pull; sudo service uwsgi stop; sudo service nginx restart; sudo service uwsgi restart; /usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals

this command works fine. 这个命令工作正常。 But I face following problems 但是我面临以下问题

  1. Usagi runs in the foreground. Usagi在前景中运行。 Every time I make changes, a new UWSGI instance start running. 每次进行更改时,都会运行一个新的UWSGI实例。
  2. Due to multiple UWSGI instances, My AWS server get crashed, due to memory exhaustion. 由于存在多个UWSGI实例,我的AWS服务器由于内存耗尽而崩溃了。

I want to know what commands should I run to reflect changes in python code. 我想知道应该运行哪些命令来反映python代码中的更改。 PS: in my previous APACHE Django setup, I only used to restart apache, is it possible to reflect changes by only restarting nginx. PS:在我以前的APACHE Django设置中,我仅用于重新启动apache,是否可以仅通过重新启动nginx来反映更改。

Please have a look at this for running uwsgi in background. 请在后台运行uwsgi时查看一下。 create an .ini file /etc/uwsgi/sites/projectname.ini. 创建一个.ini文件/etc/uwsgi/sites/projectname.ini。 The script would look like this(for ubuntu 16.04): 该脚本如下所示(对于Ubuntu 16.04):

[uwsgi]
project = projectname
base = projectpath

chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application

master = true
processes = 5

socket = %(base)/%(project)/%(project).sock
chmod-socket = 666
vacuum = true

(For ubuntu 16.04): (对于Ubuntu 16.04):

then create the following systemd script at /etc/systemd/system/uwsgi.service: 然后在/etc/systemd/system/uwsgi.service中创建以下systemd脚本:

[Unit]
Description=uWSGI Emperor service
After=syslog.target

[Service]
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

Refresh the state of the systemd init system with this new uWSGI service on board 使用板上的此新uWSGI服务刷新systemd初始化系统的状态

sudo systemctl daemon-reload

In order to start the script you'll need to run the following: 为了启动脚本,您需要运行以下命令:

sudo systemctl start uwsgi

In order to start uWSGI on reboot, you will also need: 为了在重新启动时启动uWSGI,您还需要:

sudo systemctl enable uwsgi

You can use the following to check its status: 您可以使用以下命令检查其状态:

systemctl status uwsgi

(For ubuntu 14.04): (对于Ubuntu 14.04):

Create an upstart script for uWSGI: 为uWSGI创建新贵的脚本:

sudo nano /etc/init/uwsgi.conf

Then add following lines in the above created file: 然后在上面创建的文件中添加以下行:

description "uWSGI application server in Emperor mode"

start on runlevel [2345]
stop on runlevel [!2345]

setuid user
setgid www-data

exec /usr/local/bin/uwsgi --emperor /etc/uwsgi/sites

Try this: 尝试这个:

git pull
python manage.py migrate  # to run any migrations
sudo service uwsgi restart

Press Ctrl + Z and then bg + enter This should run the process in the background. 按Ctrl + Z,然后按bg + Enter。这应在后台运行该过程。

Please let me know if this works. 请让我知道是否可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM