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.
Related
I am trying to deploy my very first Django applicatin on heroku. Gunicorn gives me this error: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
In this answer https://stackoverflow.com/a/55623889 command gunicorn app:application --preload -b 0.0.0.0:5000 is said to give detailed error message, but as its comments state it is not clear what words to replace with what. For instance somewhere I saw something similar called with <name of my app>.wsgi. To make matter worse name of my Django app in local is different from the one on Heroku.
Also it is not clear to me should this be called strait from terminal (within virtual env) or should I be using some sort of gunicorn CLI.
So what is the actual propper way to figure out what is failing gunicorn?
I've faced similar issues in the past. I hope this might help:
Make sure gunicorn is installed in your activated virtual environment project by running pip freeze in the terminal to verify it's installation. If it is not listed, in the activated virtual environment, run pip install gunicorn or else if you are using pipenv, run pipenv install gunicorn. Don't forget to update the requirements.txt file by running pip freeze > requirements.txt
In the Procfile which is within the project_directory type the syntax:
web: gunicorn your_django_project_name.wsgi --log-file -
N.B: There should be a space between;
The --log-file and the - next to it.
web: and the gunicorn part of the code.
Finally add, commit and push the changes to the heroku server.
On production, I am using Django 2.1 + Nginx + uWSGI. Now, I am planning to migrate to Django 3. Django 3 requires python version 3.6+, but my current python version is 3.5.
I have installed python 3.7 on my dev server from source as make altinstall so on dev server I can run it as python37 manage.py runserver, but on production server how can I define python version to 3.7 to start server?
Here is my uwsgi.ini
#mysite_uwsgi.ini
[uwsgi]
chdir = /var/www/dostavka
module = dostavka.wsgi
master = true
processes = 10
socket = /var/www/dostavka/dostavka.sock
chmod-socket = 666
vacuum = true
Then i run it using command
uwsgi --ini /var/www/dostavka/mysite_uwsgi.ini --daemonize /var/www/uwsgi.log --uid www-data --gid www-data
I am not using virtualenv at production.
So, I have solved the problem. After make altnstall python 3.7 on production server, I have re-installed uWSGI and Django by using pip3.7 install uwsgi and pip3.7 intall django. After that uWSGI start to use new python version 3.7.
Also, if you have any other applications connected to django, you need to install them using pip3.7 intall xxxx.
I have intalled gunicorn,but gunicorn command not found:
# pip3.4 install gunicorn
Requirement already satisfied (use --upgrade to upgrade): gunicorn in /usr/local/python3.4/lib/python3.4/site-packages
# gunicorn
-bash: gunicorn: command not found
what is the problem,is gunicorn install path not be recognized by system?
I faced the same issue and it turns out I had to add gunicorn binary path to Linux PATH variable. You can start by echoing $PATH to see all binary path listed on the system. Then find out where gunicorn is installed. For my case I was using python virtual environment and pyenv which helps manage several python versions and dependencies separately.
(venv3.6) dave#daverig (develop)✗ % pip show gunicorn
Name: gunicorn
Version: 19.7.1
Summary: WSGI HTTP Server for UNIX
Home-page: http://gunicorn.org
Author: Benoit Chesneau
Author-email: benoitc#e-engura.com
License: MIT
Location: /home/dave/.pyenv/versions/3.6.2/envs/venv3.6/lib/python3.6/site-packages
Notice gunicorn is installed in /home/dave/.pyenv/versions/3.6.2/envs/venv3.6/lib/python3.6/site-packages and the corresponding path for the binaries for this particular python version is at /home/dave/.pyenv/versions/3.6.2/envs/venv3.6/bin. So I had to add that to Linux path via ~/.profile file like so;
export PATH=$PATH:$HOME/.pyenv/versions/3.6.2/envs/venv3.6/bin then ofcourse you want to refresh this using source ~/.profile or restart your terminal. Once I was able to do this, gunicorn binary was now available on my console;
(venv3.6) dave#daverig (develop)✗ % gunicorn --version
gunicorn (version 19.7.1)
I had the same problem on Debian.
It turns out that on Debian the documentation advises to install gunicorn via apt:
$ sudo apt install gunicorn
i just created a file named gunicorn and type these codes below which is the same as my development server , and included it into system path,such as /usr/bin
#!/usr/local/bin/python3.4
#-*- coding: utf-8 -*-
import re
import sys
from gunicorn.app.wsgiapp import run
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$','',sys.argv[0])
sys.exit(run())
in this way, it solved my problem,but still confused me,why gunicorn command not generated and included into system path automatically?and why my development server did ,both the same OS (centos 6.5 x64)
Installing gunicorn from source saved me after 2 hours trying!
pip3 install git+https://github.com/benoitc/gunicorn.git
If you installed python3 from source compiled, you should export your python3 PATH:
export PATH=$PATH:/usr/local/python3/bin
Are you use python3.4-venv?
if true
Delete env folder
Just reinstall: python3.4-venv. Ex for ubuntu:
apt install python3.4-venv
Exec: python3.4 -m venv env
source env/bin/activate
reinstall gunicorn by : pip3 install gunicorn or install from requirements.txt by pip3 install -r requirements.txt
go to terminal and change directory to environment and then type the below command.
pip install gunicorn
#Enjoy1
I've been using apt-get install uwsgi to install uWSGI for my Django application. Today, I realized I needed a feature that's not available until uWSGI 1.1, and Ubuntu 12.04.1 doesn't have anything after 1.0.x, at least according to my apt-get install uwsgi=1.1 attempt. So, I used:
pip install http://projects.unbit.it/downloads/uwsgi-lts.tar.gz
After doing so, I get a message prescribing the use of /usr/local/bin/uwsgi to launch the program. I'm not a guru when it comes to compiling from source, but my understanding is that when you do so, nothing will be changed in the /etc/ directory. Is this correct? If not, why don't I have a /etc/uwsgi/ directory and, more specifically, a /etc/uwsgi/apps-enabled/ directory? Should I simply create the directories when installing uWSGI from source? I was hesitant to do so, considering there is no mention of this in the docs (I don't want something that accidentally works, etc.).
Sorry for this very late reply, but maybe this will help people who'll find this answer in the future:
To get /etc/uwsgi etc, you need to install the uwsgi package from Debian or Ubuntu (whatever you are using) by running aptitutde install uwsgi. However this will by default probably install an ancient version of uwsgi! The uwsgi binary is placed in /usr/bin/uwsgi when installing uwsgi this way.
To get the latest version, also install uwsgi using pip using pip install -U uwsgi, which (on my Ubuntu system at least) will put the uwsgi binary in /usr/local/bin/uwsgi then go do the following:
cd /usr/bin/
mv uwsgi uwsgi-old
ln -s /usr/local/bin/uwsgi uwsgi
Alternatively: edit the uwsgi init script and edit the DAEMON="/usr/bin/uwsgi" appropriately.
Et voila: "debianism" (full init scripts, etc) and the latest uwsgi binary!
/etc/uwsgi and friends is a 'debianism'. The uWSGI project is all about the sysadmin taste, so if you like the /etc/uwsgi approach just create the directory, drop config files in it and start the uWSGI Emperor to manage instances.
I'm trying to install gunicorn in my virtual env, but get the following:
$ pip install gunicorn
Downloading/unpacking gunicorn
Downloading gunicorn-0.14.2.tar.gz (203Kb): 203Kb downloaded
Running setup.py egg_info for package gunicorn
warning: no files found matching '*' under directory 'debian'
Installing collected packages: gunicorn Found existing installation: gunicorn 0.14.2
Uninstalling gunicorn:
Successfully uninstalled gunicorn
Running setup.py install for gunicorn
warning: no files found matching '*' under directory 'debian'
Installing gunicorn_paster script to /home/aemdy/Documents/projects/reborn/env/bin
Installing gunicorn script to /home/aemdy/Documents/projects/reborn/env/bin
Installing gunicorn_django script to /home/aemdy/Documents/projects/reborn/env/bin
Successfully installed gunicorn
Cleaning up...
And when I use python manage.py run_gunicorn for django it says that this is unknown command. I have added gunicorn to INSTALLED_APPS.
Warnings like that appear sometimes when installing apps. I believe it's related to cleanup pip tries to do, but it doesn't matter regardless. As the console output says "Successfully installed gunicorn". So no problems there.
With gunicorn installed, the only other requirement is adding gunicorn to INSTALLED_APPS. If you've done that as well, you're done. run_gunicorn will be available.
So, if it's not working, one of the following is in play:
Gunicorn isn't actually installed. However, you should get an error trying to reference in in INSTALLED_APPS in that scenario. Check your virtualenv's site-packages directory to ensure there's gunicorn folder there.
You installed Gunicorn in a different virtualenv. Again, you should be getting an error just as in #1. And, just as in #1, check to make sure it's actually in the proper virtualenv's site-packages directory
You don't have the virtualenv activated. However, same error as in #1 and #2 applies here.
You really don't have gunicorn in INSTALLED_APPS or a compiled version of settings.py is being used that doesn't have it in INSTALLED_APPS. Delete settings.pyc if it exists.
I just ran into this issue. What I did was try to run the app using runserver which led to me seeing the hostname on the server was not set(and thus can't get an IP address). Once we fixed that issue the command worked again.
It is a little misleading to see:
Unknown command: 'run_gunicorn'
Type 'manage.py help' for usage.
when the hostname is not set...confusing I know but I hope this helps someone in the future.
Did you remember to add gunicorn to your INSTALLED_APPS?