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

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

Related

mod_wsgi setup in production failed to start

I am deploying a django project in production using ubuntu, and I have been following this tutorial explaining how to setup and run mod_wsgi in production. Upon running apachectl start I get the following error
apachectl start
AH00526: Syntax error on line 53 of /etc/apache2/sites-enabled/django_project-le-ssl.conf:
SSLCertificateFile: file '/etc/letsencrypt/live/www.dimsum.dk/fullchain.pem' does not exist or is empty
Action 'start' failed.
The Apache error log may have more information.
Prior starting the apachectl I did the followings:
pip install mod_wsgi
The installation was successful and I then put mod_wsgi.server in my INSTALLED_APPS under settings.py. I then run without problem
python manage.py runmodwsgi \
--server-root/etc/wsgi-port-80 \
--user www-data --group www-data \
--port 80 --setup-only
Then I stopped my current apache2 server by
sudo service apache2 stop
Followed by
/etc/wsgi-port-80/apachectl start
and got the error
AH00526: Syntax error on line 53 of /etc/apache2/sites-enabled/django_project-le-ssl.conf:
SSLCertificateFile: file '/etc/letsencrypt/live/www.dimsum.dk/fullchain.pem' does not exist or is empty
Action 'start' failed.
The Apache error log may have more information.
When running with sudo the problem is solved.

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

Resolving Fatal status in Supervisor and Django

I am using Digital Ocean Ubuntu server to deploy my Django project and follow this guide to set it all up: A Complete Beginner's Guide to Django - Part 7
I am the process of configurig Gunicorn and Supervisor and I get the following error:
I am logged in as non-root but sudo user that I have created called betofolio. My django project is called betofolio.
Below is a screenshot of what my folders look like:
Following the steps from the tutorial:
Create a new file named gunicorn_start inside /home/betofolio:
vim gunicorn_start
I insert the following:
#!/bin/bash
NAME="betofolio"
DIR=/home/betofolio/betofolio
USER=betofolio
GROUP=betofolio
WORKERS=3
BIND=unix:/home/betofolio/run/gunicorn.sock
DJANGO_SETTINGS_MODULE=betofolio.settings
DJANGO_WSGI_MODULE=betofolio.wsgi
LOG_LEVEL=error
cd $DIR
source ../venv/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DIR:$PYTHONPATH
exec ../venv/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $WORKERS \
--user=$USER \
--group=$GROUP \
--bind=$BIND \
--log-level=$LOG_LEVEL \
--log-file=-
Then I save and exit.
Make this file executable:
chmod u+x gunicorn_start
Create two empty folders, one for the socket file and one to store the logs:
mkdir run logs
Configuring Supervisor
Create an empty log file inside the /home/betofolio/logs/ folder:
touch logs/gunicorn.log
Now create a new supervisor file:
sudo vim /etc/supervisor/conf.d/betofolio.conf
[program:betofolio]
command=/home/betofolio/gunicorn_start
user=betofolio
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/betofolio/logs/gunicorn.log
Then:
sudo supervisorctl reread
sudo supervisorctl update
Now check the status:
sudo supervisorctl status betofolio
I get:
I am new to linux and networking, so I am not sure how to resolve this
I was following the same guide, and ran into the same problem. What solved it for me was realizing I didn't have gunicorn installed in my virtual environment. I had done a pip3 install gunicorn, but you need to do pip install gunicorn. You may have to say sudo before if it says you don't have permission (sudo pip install gunicorn)
go into the logs folder, and open gunicorn.logs. This file is in /home/(user)/logs, and type less gunicorn.logs to see it. It will show you why it's failing. In my case it said it couldn't find gunicorn in the location I had specified within the gunicorn_start file.
Make sure you have the virtual environment activated The command line turns into (name of virtual env) $...
cd into /home/(user)/(venv)/bins, and type ls to see the files in the directory, and see if gunicorn is in there.
After fixing this it still wouldn't run, and I realized in the log files I had some typos in the gunicorn_start file, so that logs file is very handy to troubleshoot.

How to configure global supervisor to use pyenv and virtualenv

I am upgrading a Django installation from 1.4 to 1.7, which means I am also migrating from Python 2.6.6 to Python 2.7. The production server uses Debian 6.09, which requires python 2.6 globally, and unfortunately upgrading the OS is not a valid solution at this time.
To get around this, I installed the following stack:
pyenv with python 2.7
virtualenv
virtualenvwrapper
uwsgi
supervisor (installed from the global python 2.6, run as root)
nginx
When I run uwsgi manually from the the virtualenv, the site works great. However, when I start it with supervisor, it will only use the global python install.
As user with virtualenv:
(django1.7)user#staging:~$ echo $PATH
/home/user/.virtualenvs/django1.7/bin:/home/user/.pyenv/shims:/home/user/.pyenv/bin:/usr/local/bin:/usr/bin:/bin
My supervisor config file:
[program:app]
command = /home/user/.virtualenvs/django1.7/bin/uwsgi
--module app.wsgi
--socket 127.0.0.1:10001
--master
--harakiri 120
--max-requests 5000
--threads 6
directory=/home/user/app/
environment=PATH="/home/user/.virtualenvs/django1.7/bin:/home/user/.pyenv/shims:/home/user/.pyenv/bin:",DJANGO_SETTINGS_MODULE="app.settings",HOME="/home/user"
user=user
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
Can anyone help point out where my config is wrong?
Thanks!
uWSGI has a specific virtualenv configuration directive:
virtualenv=/home/user/.virtualenvs/django1.7
Another example:
https://github.com/miohtama/LibertyMusicStore/blob/master/conf/uwsgi.ini
More information
http://uwsgi-docs.readthedocs.org/en/latest/tutorials/dreamhost.html?highlight=virtualenv
(Looks like uWSGI documentation regarding virtualenv is bit confusing, I might need to double check this with the authors)
The configuration I posted ended up working. I was foolish and did not run supervisorctl update first to make sure it loaded in the updated configuration.

Python3 uWSGI stops instantly

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.