uWSGI不会重新加载,重新启动或让我运行服务 [英] uWSGI won't reload, restart or let me run service

查看:983
本文介绍了uWSGI不会重新加载,重新启动或让我运行服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当大的问题。



我对uwsgi非常新鲜,我不是100%肯定如何调试这个问题,但我会给你的信息




  • 我以前曾经有过这个配置的网站,突然它不起作用。 $ b
  • 我正在运行皇帝模式。

  • 当我使用命令行运行它时,我的ini文件是确定的,但似乎他们不会自动启动



当我运行 uwsgi reload

  sudo service uwsgi reload 

我收到这个错误

  *重新加载应用服务器uwsgi 
...失败!

这样做。我没有任何其他的东西。



我一直在寻找堆栈溢出的时间,没有发现任何概述这个问题的东西,我发现很多与人民。 ini文件,但我知道这不是我的问题,因为当通过 uwsgi --ini MYINI.ini 手动运行我的网站,然后访问它运行完全正常,问题是在uWSGI我不知道如何找到这个解决方案。我查看了这些文件,找不到任何关于这个特定错误的东西。



如果这里有兴趣的人是我的uwsgi-server.conf文件

 描述uWSGI皇帝

在运行级别开始[2345]
停止在运行级别[!2345]

respawn

env LOGTO = / var / log / uwsgi.log
env BINPATH = / usr / local / bin / uwsgi

exec $ BINPATH --emperor / etc / uwsgi / vassals --logto $ LOGTO

任何洞察力将赞赏。我觉得我错过了一些东西,但是在uWSGI这么新的时候,我甚至不能猜测它可能是什么,对我来说,这一切看起来都符合文档。



如果您需要有关我的设置的更多信息,请问。

解决方案

我今天写了一篇有关uwsgi的博客,您可以阅读第一个:
http://guoqiao.farbox .com / post / 2014/0416-use-uwsgi-the-right-way



正确使用uwsgi



使用uwsgi来ubuntu服务器上的django站点是很容易的,但是在出错之前还需要先了解一下。



install



你有两种方式在ubuntu上安装uwsgi:apt-get或pip



apt-get



如果您使用apt-get,则需要安装python插件:

  sudo apt-get install uwsgi-plugin-python 
sudo apt-获取安装uwsgi

而且,在您的网站的uwsgi ini文件中,您需要添加: / p>

plugins = python



pip



如果您使用点,您需要先安装python-dev:

  sudo apt-get install python-dev 
sudo pip install uwsgi

而且,你不需要ini文件中的 plugins = python



在pip之前看到sudo?是的,uwsgi应该安装在全局系统中。
如果你错过了这个sudo,你可以将它安装在你的virtualenv中。
这是没有意义的,您可能无法运行它。



守护程序uwsgi



守护程序意味着使uwsgi在系统启动和后台运行。
根据你如何安装uwsgi,你有两种方法。



apt-get



您在ubuntu上的 apt-get install uwsgi ,它将自动安装。魔法在这个文件中:

  /etc/init.d/uwsgi 

/etc/init.d 中的文件将由sysvinit加载。那么你可以这样管理你的uwsgi服务:

  sudo /etc/init.d/uwsgi start | stop | restart | reload 

或:

 code> sudo service uwsgi start | stop | restart | reload 

服务命令可以找到由sysvinit管理的服务



pip



如果您通过pip安装uwsgi,则只能将可执行文件/ usr / local / bin / uwsgi,您需要自己守护进程。



当您打开 / etc / init中的某些文件时。 d / ,你可能会感到难过:
我只想注册uwsgi作为一个服务,为什么我需要写这么长的脚本看起来类似于其他?这是没有意义的。



好消息是,在Upstart的帮助下,这是一个简单的方法,这是sysvinit的替代方法。它使用 / etc / init / 而不是 /etc/init.d /



只需创建一个文件 /etc/init/uwsgi.conf ,其中包含以下内容:

 描述uWSGI皇帝
从运行级别开始[2345]
停止在运行级别[!2345]
respawn
exec / usr /本地/ bin / uwsgi --emperor / etc / uwsgi / vassals / --logto /var/log/uwsgi.log

然后,您可以像这样管理你的uwsgi进程:

  sudo initctl start | stop | restart | reload | uwsgi 

还是这样:

  sudo service uwsgi start | stop | restart | reload 

是的,您可以看到,服务命令很聪明,它可以使用相同的命令来管理sysvinit和Upstart的服务。



如果您同时拥有 /etc/init.d/uwsgi /etc/init/uwsgi.conf ,当你说:

  sudo服务uwsgi重新启动

它将重新启动Upstart文件 /etc/init/uwsgi.conf
sysvinit将被忽略,或类似的东西。



您网站的uwsgi配置



我建议大家使用pip和Upstart方式,这比apt-get方式好多了。



如果是这样,你使用的是uwsgi的皇帝模式,非常方便和强大。



现在,您可以在 / etc / uwsgi / vassals / 中创建一个ini文件这个:

  [uwsgi] 
virtualenv = / path / to / venv /
chdir = / path / to / proj / root
module = wsgi:application
env = DJANGO_SETTINGS_MODULE = settings
master = True
vacuum = True
socket = / tmp /%n。 sock
pidfile = / tmp /%n.pid
daemonize = / var / log / uwsgi /%n.log

%n表示您的文件名。例如,我的项目名称是readfree,我创建一个readfree.ini文件。那么%n表示'readfree'。你不需要用真实的名字替换它。 uwsgi会为你做这个。



然后重新启动或重新加载uwsgi:

  sudo服务uwsgi重新启动

检查您的套接字文件:

  ll /tmp/*.sock 

如果它在那里,你现在是成功的uwsgi:)



您网站的nginx配置



readfree.me例如:

  server {
listen 80;
server_name www.readfree.me;
return 301 $ scheme://readfree.me$request_uri;
}

server {
listen 80;
charset utf-8;
server_name readfree.me;

location / static / {
alias / path / to / static /;
}

location / media / {
alias / path / to / media /;
}

location / {
try_files $ uri @django;
}

location @django {
uwsgi_pass unix:///tmp/readfree.sock;
包括uwsgi_params;
}
}

重启nginx,你会看到你的网站! p>

回答你的问题



你的uwsgi配置文件是/etc/init/uwsgi-server.conf
所以,你应该使用的名字是 uwsgi-server ,而不是 uwsgi



您需要重新启动uwsgi emperor实例,如下所示:

  sudo initctl restart uwsgi-server 

或:

  sudo服务uwsi-server restart 

这就是全部!


I have a fairly big issue.

I am very new to uwsgi and am not 100% sure on how to debug this issue but I will give you information on where I am at.

  • I have previously had sites working on this configuration and suddenly it isn't working.
  • I am running Emperor mode.
  • My ini files are ok when I use command line to run them but it seems they wont automatically start

When I run uwsgi reload

sudo service uwsgi reload

I get this error

* Reloading app server(s) uwsgi
...fail!

Thats it. I get nothing else.

I have been looking for hours on stack overflow and haven't found anything that outlines this problem exactly, I found a lot to do with peoples .ini files but I know that is NOT my issue because when running my site manually via uwsgi --ini MYINI.ini then accessing it it runs perfectly fine, the issue is in uWSGI and I don't know how to find the solution to this one. I have looked in the documents and can't find anything on this particular error.

If this interests anyone here is my uwsgi-server.conf file

description     "uWSGI Emperor"

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

respawn

env LOGTO=/var/log/uwsgi.log
env BINPATH=/usr/local/bin/uwsgi

exec $BINPATH --emperor /etc/uwsgi/vassals --logto $LOGTO

Any insight would be appreciated. I feel like I am missing something but being so new with uWSGI I cant even guess as to what it may be, To me this all looks ok as per the documentation.

If you need any more information on my setup please just ask.

解决方案

I wrote a blog about uwsgi today, you can read it first: http://guoqiao.farbox.com/post/2014/0416-use-uwsgi-the-right-way

Use uwsgi the right way

Using uwsgi to deply django site on ubuntu server is quite easy, but there are still something you need to know before making mistakes.

install

You have two ways to install uwsgi on ubuntu: apt-get or pip

apt-get

if you use apt-get, you need to install the python plugin:

sudo apt-get install uwsgi-plugin-python
sudo apt-get install uwsgi

And, in your uwsgi ini file for your site, you need to add this:

plugins=python

pip

if you use pip, you need to install python-dev first:

sudo apt-get install python-dev
sudo pip install uwsgi

And, you don't need the plugins=python in ini file anymore.

See the sudo before pip? Yes, uwsgi should be installed in global system. If you miss the sudo here, you may install it in your virtualenv. It's meaningless and you may have trouble running it.

daemonize uwsgi

Daemonize means make uwsgi run on system boot and in the background. According to how you install uwsgi, you have two ways.

apt-get

When you apt-get install uwsgi on ubuntu, it's installed as a service automatically. The magic lies in this file:

/etc/init.d/uwsgi

Files in /etc/init.d will be loaded by sysvinit. Then you can manage your uwsgi service like this:

sudo /etc/init.d/uwsgi start|stop|restart|reload

or:

sudo service uwsgi start|stop|restart|reload

the service command can find the service managed by sysvinit

pip

If you uwsgi is installed by pip, you only have the executable file in /usr/local/bin/uwsgi, you need to daemonize it yourself.

When you open some of the files in /etc/init.d/, you may feel sad: I just want to register uwsgi as a service, why I need to write such long a script which looks similar to the others? It doesn't make sense.

Good news is that it is quite simple with the help of Upstart, which is an alternative to sysvinit. It use /etc/init/ instead of /etc/init.d/.

Just create a file /etc/init/uwsgi.conf with following content:

description "uWSGI Emperor"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals/ --logto /var/log/uwsgi.log

and then, you can manage your uwsgi process like this:

sudo initctl start|stop|restart|reload| uwsgi

or, still this:

sudo service uwsgi start|stop|restart|reload

Yes, as you can see, the service command is smart, it can manage service from both sysvinit and Upstart, with the same command.

And, if you have both /etc/init.d/uwsgi and /etc/init/uwsgi.conf, when you say:

sudo service uwsgi restart

It will restart the Upstart file /etc/init/uwsgi.conf. The sysvinit one will be ignored, or something similar.

uwsgi config for your site

I recommend everyone to use the pip and Upstart way, it's much better then the apt-get way.

If so, you are using the emperor mode of uwsgi, which is very handy and powerful.

Now, you can create a ini file in /etc/uwsgi/vassals/ like this:

[uwsgi]
virtualenv=/path/to/venv/
chdir=/path/to/proj/root
module=wsgi:application
env=DJANGO_SETTINGS_MODULE=settings
master=True
vacuum=True
socket=/tmp/%n.sock
pidfile=/tmp/%n.pid
daemonize=/var/log/uwsgi/%n.log

The %n means your file name. For example, my project name is 'readfree', I create a readfree.ini file for it. Then the %n means 'readfree'. You don't need to replace it with real name. uwsgi will do this for you.

And then restart or reload uwsgi:

sudo service uwsgi restart

Check your socket file:

ll /tmp/*.sock

If it's there, you are successful with uwsgi now:)

nginx config for your site

Take domain readfree.me for example:

server {
    listen          80;
    server_name     www.readfree.me;
    return          301 $scheme://readfree.me$request_uri;
}

server {
    listen 80;
    charset utf-8;
    server_name readfree.me;

    location  /static/ {
        alias  /path/to/static/;
    }

    location  /media/ {
        alias /path/to/media/;
    }

    location / {
        try_files $uri @django;
    }

    location @django {
       uwsgi_pass unix:///tmp/readfree.sock;
       include uwsgi_params;
    }
}

restart nginx, you will see your site!

answer to you question

Your config file for uwsgi is /etc/init/uwsgi-server.conf So, the name you should use is uwsgi-server, not uwsgi

you need to restart your uwsgi emperor instance like this:

sudo initctl restart uwsgi-server

or:

sudo service uwsi-server restart

That's all!

这篇关于uWSGI不会重新加载,重新启动或让我运行服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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