我正在做一个从Ubuntu 12.04到16.04的暂存和生产服务器有点痛苦的迁移过程。 我正在testing迁移的阶段,它主要是工作,除了让uWSGI在systemd下启动(它以前在Upstart下工作得很好)。 这工作没有问题:
uwsgi --ini /etc/uwsgi/my_wsgi.ini
但是运行以下操作不起作用(uWSGI不启动,但不会产生错误):
sudo systemctl start uwsgi
我在/etc/systemd/system/uwsgi.service中创build了以下服务:
[Unit] Description=uWSGI Service [Service] ExecStart=/usr/local/bin/uwsgi --ini /etc/uwsgi/my_wsgi.ini Restart=always RestartSec=5 KillSignal=SIGQUIT Type=notify NotifyAccess=all [Install] WantedBy=multi-user.target
和my_wsgi.ini具有以下内容:
[uwsgi] # Django-related settings # the base directory (full path) chdir = /path/to/project/hidden # Django's wsgi file module = wsgi # process-related settings # master master = true # maximum number of worker processes processes = 8 # the socket (use the full path to be safe) socket = /path/to/socket/hidden # ... with appropriate permissions - may be needed chmod-socket = 666 # clear environment on exit vacuum = true # Mercilessly kill this worker if it takes longer than this time to reload reload-mercy = 8 # Reload workers after the specified amount of managed requests (avoid memory leaks) max-requests = 5000 # Every request that will take longer than the seconds specified in the harakiri timeout will be dropped and the corresponding worker is thereafter recycled. harakiri = 90 # Log everything and make daemon daemonize = /var/log/uwsgi/my.log # use custom settings file env = DJANGO_SETTINGS_MODULE=settings.staging # set pid file for starting/stopping server pidfile = /path/to/pid/hidden.pid # See https://docs.newrelic.com/docs/python/python-agent-and-uwsgi enable-threads = true single-interpreter = true
运行systemd-analyze verify uwsgi.service返回任何内容, sudo journalctl返回以下内容:
Starting uWSGI Service... [uWSGI] getting INI configuration from /etc/uwsgi/my_wsgi.ini Started uWSGI Service. uwsgi.service: Service hold-off time over, scheduling restart. Stopped uWSGI Service. ... (repeats a few times) ....
我怀疑uwsgi.service: Service hold-off time over, scheduling restart. 可能会指出这个问题,但我还没有弄明白。
uwsgi文件清楚地说明:
注意:不要守护皇帝(或主人),除非你知道你在做什么!
不幸的是,你不知道你在做什么, 从你的问题:
# Log everything and make daemon daemonize = /var/log/uwsgi/my.log
问题是uwsgi是systemd-aware,而systemd单元告诉systemd当uwsgi准备开始处理请求时,uwsgi会通知systemd。 默认情况下,uwsgi在systemd系统上以这种模式启动, 除非您告诉它守护进程。 在这种情况下,uwsgi 不会与systemd交谈。 这就是为什么systemd等了一会儿,最后放弃等待uwsgi告诉systemd已经准备好了。
文档build议您不要让uwsgi守护进程并直接login到文件,而应该让它logging到默认的标准错误,让systemd选取日志并logging下来。 如果您最终会将日志发送到其他地方,例如ELK堆栈,您将需要这样做。 例如:
[Service] StandardError=syslog
或者你可以直接从uwsgilogin而不需要守护进程。
logto = /var/log/uwsgi/my.log