niren
niren

Reputation: 2741

Unable to run uwsgi with upstart/supervisord

I'm not able to run uwsgi with upstart/supervisord, I used pyenv to setup python with virtualenv myenv, myenv has python3.4.3 and system's python pointing to python2.7.6. I changed pyenv global to 3.4.3.

Right now as my_user, which python => /home/my_user/.pyenv/shims/python and python --version => Python 3.4.3.

When I do with sudo, I get sudo which python => /usr/bin/python and sudo python --version => Python 2.7.6.

/etc/init/uwsgi_servers.conf has

description "uWSGI instance to serve authservice in production"

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

exec /usr/local/bin/uwsgi --emperor /etc/uwsgi/sites/ --uid my_user --gid my_user

and /etc/uwsgi/sites/uwsgi.ini has

[uwsgi]
# variables
projectname = accounts
base =  /home/my_user/django/accounts/
for-readline = /home/my_user/conf/django/accounts/env_var
  env = %(_)
endfor =

# config
chdir =  /home/my_user/django/accounts/
master = True
processes = 5
protocol = uwsgi
env = in_accounts.settings.production
module = in_accounts.wsgi
socket = /tmp/uwsgi_%(projectname).sock
chmod-socket = 666
home = /home/my_user/.virtualenvs/accounts_production
logto = %(base)/logs/uwsgi.log
daemonize = /var/log/uwsgi/%(projectname).log
vacuum = True
pidfile = /tmp/%(projectname).pid
die-on-term = true

When I run sudo service uwsgi_servers start, I get error from log

*** Starting uWSGI 2.0.11.2 (64bit) on [Tue Oct 13 09:32:18 2015] ***
compiled with version: 4.8.4 on 12 October 2015 11:59:31
os: Linux-3.16.0-43-generic #58~14.04.1-Ubuntu SMP Mon Jun 22 10:21:20 UTC 2015
nodename: st-auths-web1
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /etc/uwsgi/sites
writing pidfile to /tmp/accounts.pid
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /home/my_user/django/accounts/current
your processes number limit is 13731
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/uwsgi_accounts.sock fd 3
Python version: 2.7.6 (default, Jun 22 2015, 18:01:27)  [GCC 4.8.2]
Set PythonHome to /home/my_user/.virtualenvs/accounts_production
ImportError: No module named site
VACUUM: pidfile removed.
VACUUM: unix socket /tmp/uwsgi_accounts.sock removed.

From log I can see that starting uwsgi using upstart try to use python2.7.6 since I use sudo to run upstart service, but It should have used python3.4.3, this might be the reason why server isn't running. Though I use uid and gid I get the above error. I also tried setuid and setgid, but no luck.

NOTE: I can able to run uwsgi server successfully without upstart as uwsgi --emperor /etc/uwsgi/sites/. I tried use supervisord, but no use, getting same error.

Upvotes: 1

Views: 409

Answers (1)

middlestump
middlestump

Reputation: 1055

To make this work you will have to tell wsgi which virtualenv to use that's with the -H option. If your virtualenv is in your home folder, upstart will not be able to access it. So move it to a readable place and try

uwsgi -H /usr/local/virtualenv 

or something like that with the correct path to the virtualenv in your upstart file.

Upvotes: 1

Related Questions