Python3 uWSGI stops instantly - django

I am having a an issue where I can't get uwsgi to run on my machine. I keep getting this:
/usr/bin$ sudo service ppuwsgi start
>>ppuwsgi start/running, process 17452
/usr/bin$ sudo service ppuwsgi status
>>ppuwsgi stop/waiting
I think I might be having a similar issue as this guy here. However, I didn't install from source. I saw that the machine came with python3.4. But I did do
sudo apt-get install libpq-dev python3-dev
and maybe even
sudo apt-get install python-dev
I want to think I don't have python installed twice. And I have no idea how to check and see. I opened up my usr/local/bin and saw uwsgi and some pip stuff but no python.
Lastly, here is my /etc/init/ppuwsgi.conf
# file: /etc/init/ppuwsgi.conf
description "uWSGI server for PingPlot"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /usr/local/bin/uwsgi --home /home/ubuntu/web/app/ --socket /home/ubuntu/web/ppuwsgi.sock --chmod-socket --module wsgi --pythonpath /home/ubuntu/web/ -H /home/ubuntu/.virtualenvs/pingplot --logto /home/ubuntu/web/logs/uwsgi.log
The sock file and log file seem to get created as well (the log file is empty). I don't know what the deal is.
Edit:
So I opened up user/bin/ and here are all the python things I have.
EDIT: I LIED
I am getting stuff in the error log. I just couldn't see it because I opened vim without sudo. Here is the error log:
*** Starting uWSGI 2.0.8 (64bit) on [Thu Dec 11 05:36:59 2014] ***
compiled with version: 4.8.2 on 09 December 2014 02:42:22
os: Linux-3.13.0-36-generic #63-Ubuntu SMP Wed Sep 3 21:30:07 UTC 2014
nodename: ip-172-31-9-208
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 15925
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)
chmod() socket to 666 for lazy and brave users
uwsgi socket 0 bound to UNIX address /home/ubuntu/web/ppuwsgi.sock fd 3
Python version: 2.7.6 (default, Mar 22 2014, 23:03:41) [GCC 4.8.2]
Set PythonHome to /home/ubuntu/.virtualenvs/pennypledge
ImportError: No module named site

Based on the error log. I changed my version of Python. I uninstalled uwsgi and pip and then reinstalled it using python3 pip.
sudo apt-get install python3-pip
sudo pip install uwsgi
Then I was able to get uwsgi running.

Related

Manually start uwsgi with python3.6 and python2 and django 2

I just started to use uWSGI and Django. I want to invoke it manually.
I'm using python36, Django 2 and if I install uWSGI (pip install uwsgi) in venv and everything is ok.
Q1. When using outside of venv I first installed uWSGI:
pip install uwsgi -> 2.0.18 version
Installed plugins: sudo apt-get install python3-setuptools
Trying to run with python36:
uwsgi --plugin-dir=/usr/lib/uwsgi/plugins --plugin python3 --master --http :5000 --home ~/my_playground/webapps/ --chdir ~/my_playground/webapps/p_tscze/ --module p_tscze.wsgi:application
Plugins in /usr/lib/uwsgi/plugins:
/usr/lib/uwsgi/plugins$ ls | grep python3
asyncio_python36_plugin.so
asyncio_python3_plugin.so
python36_plugin.so
python3_plugin.so
Result obtained -> note python 2.7:
!!! UNABLE to load uWSGI plugin: ./python36_plugin.so: undefined symbol: uwsgi_legion_scrolls !!!
*** Starting uWSGI 2.0.18 (64bit) on [Wed May 29 18:04:24 2019] ***
compiled with version: 7.4.0 on 29 May 2019 15:30:14
os: Linux-4.15.0-45-generic #48-Ubuntu SMP Tue Jan 29 16:28:13 UTC 2019
nodename: start-tehnicka
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /usr/lib/uwsgi/plugins
detected binary path: /usr/local/bin/uwsgi
chdir() to /home/anel/my_playground/webapps/p_tscze/
your processes number limit is 3618
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 http bound on :5000 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:34279 (port auto-assigned) fd 3
Python version: 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0]
Set PythonHome to /home/anel/my_playground/webapps/
ImportError: No module named site
So please can you let me know what I'm doing wrong?
Q2. When comparing the result of the admin page (./manage.py runserver) and result obtained using uwsgi frontend is not the same, why?
Thanks in advance
For future references:
wget https://projects.unbit.it/downloads/uwsgi-2.0.18.tar.gz
tar -xzvf uwsgi-2.0.18.tar.gz
cd uwsgi-2.0.18
python3 uwsgiconfig.py --build nolang #build binary with python3
python3 uwsgiconfig.py --plugin plugins/python nolang python36 # create a new binary
Run newly created binary uwsgi (we can link to this binary):
./uwsgi --plugin-dir=/home/anel/uwsgi-2.0.18 --plugin python36 --master --http :5000 --home ~/my_playground/webapps/ --chdir ~/my_playground/webapps/p_tscze/ --module p_tscze.wsgi:application

uWSGI - chdir(): No such file or directory [core/uwsgi.c line 2629]

I am unable to start a dockerized Django application using uWSGI.
Below is the configuration being used.
Dockerfile
FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN apt-get update
RUN apt-get install -y swig libssl-dev dpkg-dev netcat unixodbc-dev python-dev libldap2-dev libsasl2-dev
RUN mkdir /code
WORKDIR /code
COPY app/ /code/
RUN pip install -U pip
ENV PIP_TRUSTED_HOST="pypi.python.org pypi.org files.pythonhosted.org"
RUN apt-get install ca-certificates
RUN pip install -Ur requirements.txt
RUN chmod -R 777 /code
CMD ["/code/run.sh"]
run.sh
#!/bin/bash
./manage.py migrate
uwsgi --ini uwsgi.ini
app/uwsgi.ini
[uwsgi]
http-socket = :8000
chdir = /opt/code/
module = app.wsgi:application
master = 1
processes = 2
threads = 2
Error when starting the container
Operations to perform:
Apply all migrations: admin, api, auth, contenttypes, sessions
Running migrations:
No migrations to apply.
[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 2.0.17 (64bit) on [Wed May 30 05:35:23 2018] ***
compiled with version: 6.3.0 20170516 on 30 May 2018 05:34:47
os: Linux-4.9.12-moby #1 SMP Tue Feb 28 12:11:36 UTC 2017
nodename: 0a9f49a479c7
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 6
current working directory: /code
detected binary path: /usr/local/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
chdir() to /opt/code/
chdir(): No such file or directory [core/uwsgi.c line 2629]
Can someone help me figure out what seems to be the problem with this configuration?
The following is the project structure -
project
|--app
|--app
|--requirements.txt
|--run.sh
|--uwsgi.ini
|--manage.py
|--Dockerfile

uwsgi: unrecognized option '--module=MyProject.wsgi:application'

I followed the instructions in https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/uwsgi/ and it was working fine until a few days ago, when I killed the uwsgi processes and tried to restart again. Then it said
uwsgi: unrecognized option '--module=MyProject.wsgi:application'
I've been banging my head trying to solve that problem, ... I've checked my commit history and the script I use to start uwsgi hasn't changed :
#!/bin/bash
# https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/uwsgi/
uwsgi --chdir=/home/MyProject \
--module=MyProject.wsgi:application \
--env DJANGO_SETTINGS_MODULE=MyProject.settings \
--master --pidfile=/tmp/MyProject-masted.pid \
--socket=/home/MyProject.sock \
--processes=5 \
--harakiri=20 \
--limit-as=128 \
--max-requests=5000 \
--vacuum \
--home=/home/MyProject/env \
--daemonize=/var/log/uwsgi/MyProject.log
Obviously something must have changed but I cant see what ... I didn't run any update, script didn't change ... PlEaSe HeLp !!!
You probably need to add the --plugins option to your command line to use the system installed uwsgi. On Fedora 17, at least, this is neccesary for me:
$ uwsgi --http 127.0.0.1:8000 --module=wsgiref.simple_server:demo_app
uwsgi: unrecognized option '--module=wsgiref.simple_server:demo_app'
getopt_long() error
$
but this works:
$ uwsgi --http 127.0.0.1:8000 --plugins python --module=wsgiref.simple_server:demo_app
*** Starting uWSGI 1.2.4 (64bit) on [Thu Aug 30 14:09:57 2012] ***
[.. snip]
I ran into this recently when I tried to use the version of uWSGI in the Unbuntu 12.04 repo (1.0.3). It looks likes that version is a bit old. Just use pip to grab it (1.2.5).
pip install uwsgi
Try this
uwsgi --socket /run/uwsgi/mysite.sock --chdir /home/ubuntu/mysite/ --plugin The_OJ.wsgi --chmod-socket=666

uwsgi + python2.7 unable to import anything

I'm trying to use uwsgi + python2.7 + django + nginx on debian 6.
I installed uwsgi with the command: pip2.7 install uwsgi so it's running with python 2.7.
I'm running uwsgi in emperor mode with the command:
uwsgi --emperor /etc/uwsgi/vassals/ -d /var/log/uwsgi.log --pidfile /var/run/uwsgi.pid
The vassals folder contains only one app for the moment. Here is it's yaml file:
uwsgi:
socket: /home/uwsgi/uwsgi/uwsgi.sock
virtualenv: /opt/myproj/virt
pythonpath: /home/uwsgi/project/my_proj
pidfile: /home/uwsgi/uwsgi/uwsgi.pid
uid: uwsgi
gid: uwsgi
chmod-socket: 1
module: wsgi_app
daemonize: /home/uwsgi/uwsgi/uwsgi.log
harakiri-verbose: 1
This is the content of the Django project file:
#! /usr/bin/python
SITE_DIR = '/home/uwsgi/project/my_proj'
import site
site.addsitedir(SITE_DIR)
import os
import sys
sys.path.append(SITE_DIR)
sys.path.append('/home/uwsgi/project/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'my_proj.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Now, here is the result in the /home/uwsgi/uwsgi/uwsgi.log file when I try to launch it:
*** Starting uWSGI 1.0.4 (32bit) on [Fri Mar 2 19:00:46 2012] ***
compiled with version: 4.6.2 on 02 March 2012 18:03:07
current working directory: /etc/uwsgi/vassals
writing pidfile to /home/uwsgi/uwsgi/uwsgi.pid
detected binary path: /usr/local/bin/uwsgi
setgid() to 1001
setuid() to 1001
your memory page size is 4096 bytes
chmod() socket to 666 for lazy and brave users
uwsgi socket 0 bound to UNIX address /home/uwsgi/uwsgi/uwsgi.sock fd 3
Python version: 2.7.2+ (default, Dec 1 2011, 02:17:49) [GCC 4.6.2]
Set PythonHome to /opt/myproj/virt
ImportError: No module named site
*** Starting uWSGI 1.0.4 (32bit) on [Fri Mar 2 19:00:47 2012] ***
compiled with version: 4.6.2 on 02 March 2012 18:03:07
current working directory: /etc/uwsgi/vassals
writing pidfile to /home/uwsgi/uwsgi/uwsgi.pid
detected binary path: /usr/local/bin/uwsgi
setgid() to 1001
setuid() to 1001
your memory page size is 4096 bytes
chmod() socket to 666 for lazy and brave users
uwsgi socket 0 bound to UNIX address /home/uwsgi/uwsgi/uwsgi.sock fd 3
Python version: 2.7.2+ (default, Dec 1 2011, 02:17:49) [GCC 4.6.2]
Set PythonHome to /opt/myproj/virt
ImportError: No module named site
As you can see, uwsgi can't import the site module so uwsgi keeps trying to restart the app.
So I tried to add the no-site :1 option in the yaml file. The result is that I can't import anything in my Django project file...
I also know it's not linked to the project because if I run uwsgi with python 2.6, it just works fine... Unfortunally, I have to run it with python2.7...
Do you have any idea what happens ?
Thanks a lot!
Be sure your virtualenv is built for python2.7, otherwise it cannot be used.
It has to contains /opt/myproj/virt/lib/python2.7 directory

Run django project on cherokee + uwsgi

That have:
1) ubuntu 11.10
2) cherokee (https://launchpad.net/~cherokee-webserver/+archive/ppa) (version 1.2.101)
installed like this:
sudo apt-get install cherokee
sudo apt-get install libcherokee-mod-rrd
sudo apt-get install cherokee-doc
3) uwsgi (version 0.9.8.1-1)
installed like this:
sudo apt-get install uwsgi uwsgi-plugin-python
4) Django 1.3.1 (sudo pip install django)
Run:
1) add example.com to hosts file (example.com 127.0.0.1)
2) create uwsgi.xml
<uwsgi>
<pythonpath>/var/www/vtest/</pythonpath>
<pythonpath>/var/www/</pythonpath>
<app mountpoint="/">
<script>django_wsgi</script>
</app>
</uwsgi>
and django_wsgi.py
import os
import django.core.handlers.wsgi
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
application = django.core.handlers.wsgi.WSGIHandler()
3)
/var/www$ sudo django-admin.py startproject vtest
/var/www$ sudo chown -R www-data:www-data vtest/
Move file uwsgi.xml, django_wsgi.py to /var/www/vtest and chmod +x django_wsgi.py
4) add virtual server in cherokee-admin vservers -> add -> platforms -> uwsgi choise uwsgi.xml document root /var/www/vtest
in console:
ps -A | grep uwsgi
6352 ? 00:00:00 uwsgi
if run uwsgi command in console:
/var/www/vtest$ /usr/bin/uwsgi -s 127.0.0.1:59238 -x /var/www/vtest/uwsgi.xml
tmp = /
[uWSGI] parsing config file /var/www/vtest/uwsgi.xml
*** Starting uWSGI 0.9.8.1-debian (32bit) on [Sun Jan 15 13:28:42 2012] ***
compiled with version: 4.6.1 on 28 June 2011 10:38:32
*** WARNING: you are running uWSGI without its master process manager ***
your memory page size is 4096 bytes
uwsgi socket 0 bound to TCP address 127.0.0.1:59238 fd 3
your server socket listen backlog is limited to 100 connections
*** Operational MODE: single process ***
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 6515, cores: 1)
in browser example.com:
500 Internal Server Error
what could be the cause of the error? And this line: "no app loaded. going in full dynamic mode" in the console.
you have not loaded the python plugin with
<plugins>python</plugins>