Deploying Django Mezzanine Using Fabric

August 25, 2016 1.5k views
Django Deployment Ubuntu 16.04

I'm trying to use a "fab all" (or "fab install", "fab deploy") to get Django Mezzanine up on Ubuntu. Even being as vanilla as I can, I get errors. At best, no errors are thrown, and I just get the nginx splash page at my IP with nothing at my example.com.

First Problem

Running "fab all" or "fab deploy" raises this error:

$ supervisorctl update gunicorn_jaredrovny_app ->

[] out: sudo password:
[] out: error: <class 'socket.error'>, [Errno 2] No such file or directory: file: /usr/lib/python2.7/socket.py line: 228

After tracking this problem to supervisorctl, I've found that a "sudo service supervisor start" on the server allows getting past the above. But the site still won't deploy, so I've included the above because I'm not sure what role it's playing in my problems...

Second Problem

After searching around, I found my "/home/usr/logs/<mezz_app>_supervisor" log shows

Error: 'gunicorn.conf.py' doesn't exist

I cannot find out why this is happening.

With a local virtualenv, mezzanine, etc., the only thing I do before "fab all" is edit my local_settings.py file to have the following:

ALLOWED_HOSTS = ["<example.com>"]


    "DEPLOY_TOOL": "git",  # Deploy with "git", "hg", or "rsync"
    "SSH_USER": "<usr>",  # VPS SSH username
    "HOSTS": ["<IP address>"],  # The IP address of your VPS
    "REQUIREMENTS_PATH": "requirements.txt",  # Project's pip requirements
    "GUNICORN_PORT": 8000, # Port gunicorn will listen on
    "LOCALE": "en_US.UTF-8",  # Should end with ".UTF-8"
    "DB_PASS": "",  # Live database password
    "ADMIN_PASS": "",  # Live admin user password
    "REPO_URL": "<github url>",

Highlighted regions are things I've changed.

(FYI, I've tried things like putting ".postgresql_psycopg2" in the DATABASES section, changing the settings.py file, and a handful of other things as well, including explicitly moving the "missing" gunicorn.conf.py file to the directory where it's being looked for-- still nothing!)

Any ideas what's going on here?

1 comment
  • Followup note:
    Problem "1" above doesn't occur on Ubuntu 14.04.5, but problem "2" ('gunicorn.conf.py' doesn't exist) persists.

2 Answers
jrov August 29, 2016
Accepted Answer

I think I've got it! With all the things I changed, I think the only important difference was including a virtual environment path in the local settings file (VIRTUALENV HOME). But below is the full process in case anyone is struggling.

Pretend my username is bob.

1 I got a fresh Ubuntu 14 (NOT 16!) Digital Ocean Server.
2 Set up the server by hand with the following steps (instead of using "fab secure". Probably doesn't matter). Summarized from a Digital Ocean article (don't remember where).

ssh root@[ip-address]
adduser bob
gpasswd -a bob sudo
su - bob
mkdir .ssh
chmod 700 .ssh
nano .ssh/authorized_keys
<insert public key from your own computer>
chmod 600 .ssh/authorized_keys
nano /etc/ssh/sshd_config
<change "allow root access" from "yes" to "no">
service ssh restart

I don't think you'll need back on the server any more.

3 I'm running OSX locally. Installed pip and virtualenv, made an environment, and got mezzanine and fabric (note, if you're running anaconda python or something, the virtualenv might get confused about your directories).

virtualenv mezzanine_env
cd mezzanine_env
source bin/activate
pip install mezzanine fabric
mezzanine-project bobs_project
cd bobs_project

At this point (still in the project directory) I set up my git repository. Plenty of tutorials out there about that, I think.

4 Edit the /bobs_project/local_settings.py file. I didn't edit any other files but this one! When I was done, it looked like this (note that I included the virtual environment path!)

    "DEPLOY_TOOL": "git",  # Deploy with "git", "hg", or "rsync"
    "SSH_USER": "bob",  # VPS SSH username
    "VIRTUALENV_HOME": "/home/bob", # Absolute remote path for virtualenvs
    "HOSTS": ["<ip-address>"],  # The IP address of your VPS
    "REQUIREMENTS_PATH": "requirements.txt",  # Project's pip requirements
    "LOCALE": "en_US.UTF-8",  # Should end with ".UTF-8"
    "DB_PASS": "default",  # Live database password
    "GUNICORN_PORT": 8000, # Port gunicorn will listen on
    "ADMIN_PASS": "default",  # Live admin user password

5 And that's it! Make sure to navigate back to the folder with your fabric.py file in it, then

fab all

and follow the prompts / provide passwords.

Hope this helped!

P.S. I think the mezzanine CMS login starts as username: admin, password: default.

Thank you for the article, however I keep on running into the same problem over and over again. fab all or fab secure keeps asking for the password of the user without doing anything else. I have done about 10 vanilla installs on both debain and ubuntu with exactly the same results. Any help would be appreciated.

Have another answer? Share your knowledge.