Deploying Django with Virtualenv, Circus and Chaussette

3.1k Views Asked by At

I'm trying to run Django with Virtualenv, Circus and Chaussette, in a virtualhost with CentOS 7, but i keep getting this error when i run circusd circus.ini:

(djenv)[root@localhost django]# circusd circus.ini
2014-09-01 22:06:38 circus[2406] [INFO] Starting master on pid 2406
2014-09-01 22:06:38 circus[2406] [INFO] sockets started
2014-09-01 22:06:38 circus[2406] [WARNING] error in 'settings': [Errno 2] No such file or directory: '~/.virtualenv/djenv/bin/chaussette'
2014-09-01 22:06:38 circus[2406] [WARNING] error in 'settings': [Errno 2] No such file or directory: '~/.virtualenv/djenv/bin/chaussette'
2014-09-01 22:06:38 circus[2406] [WARNING] error in 'settings': [Errno 2] No such file or directory: '~/.virtualenv/djenv/bin/chaussette'
2014-09-01 22:06:38 circus[2406] [WARNING] error in 'settings': [Errno 2] No such file or directory: '~/.virtualenv/djenv/bin/chaussette'
2014-09-01 22:06:38 circus[2406] [WARNING] error in 'settings': [Errno 2] No such file or directory: '~/.virtualenv/djenv/bin/chaussette'
2014-09-01 22:06:38 circus[2406] [INFO] settings stopped
2014-09-01 22:06:38 circus[2406] [INFO] Arbiter now waiting for commands
2014-09-01 22:06:38 circus[2406] [INFO] circusd-stats started
2014-09-01 22:06:38 circus[2415] [INFO] Starting the stats streamer

# Here i close circusd with ctrl+c

2014-09-01 22:19:40 circus[2406] [INFO] Got signal SIG_INT
2014-09-01 22:19:40 circus[2406] [INFO] Arbiter exiting
2014-09-01 22:19:41 circus[2406] [INFO] circusd-stats stopped
Exception ignored in: <module 'threading' from '/usr/local/lib/python3.4/threading.py'>
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/threading.py", line 1294, in _shutdown
    t.join()
  File "/usr/local/lib/python3.4/threading.py", line 1057, in join
    raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread

The path to my django project is /opt/webapps/django/. This is the structure of that path:

(FYI: settings was the name i gave to my django project)

/django/
/django/manage.py
/django/circus.ini
/django/settings/
/django/settings/urls.py
/django/settings/wsgi.py
/django/settings/settings.py

The path to my virtualenv is: ~/.virtualenv/djenv/. This is the structure (bin) of that path:

/djenv/
/djenv/bin/
/djenv/bin/circusd
/djenv/bin/chaussette
/djenv/bin/circushttpd
/djenv/bin/python3.4
/djenv/bin/pip

The content of my circus.ini is:

[circus]
endpoint = tcp://127.0.0.1:5555
pubsub_endpoint = tcp://127.0.0.1:5556
stats_endpoint = tcp://127.0.0.1:5557

[watcher:settings]
cmd = ~/.virtualenv/djenv/bin/chaussette django:/opt/webapps/django --fd $(circus.sockets.settings)$ --django-settings settings.settings
use_sockets = True
numprocesses = 3

[socket:settings]
host = 0.0.0.0
port = 8080
2

There are 2 best solutions below

2
On BEST ANSWER

So i finally find a solution. Here is what i did.

First i changed my circus.ini to this:

[circus]
endpoint = tcp://127.0.0.1:5555
pubsub_endpoint = tcp://127.0.0.1:5556
stats_endpoint = tcp://127.0.0.1:5557

[watcher:settings]
cmd = /root/.virtualenvs/djenv/bin/chaussette settings.wsgi.application
args = --fd $(circus.sockets.settings)
use_sockets = True
numprocesses = 3
copy_env = True
virtualenv = /root/.virtualenvs/djenv/

[socket:settings]
host = 0.0.0.0
port = 8080

Because i'm running this circus in python 3.4.1 i was getting another error:

OSError: [Errno 9] Bad file descriptor

Looking for a solution to this problem i found this fix https://github.com/mozilla-services/circus/pull/800/files

Hope this helps others.

0
On

This reply is too late but maybe will be useful for other. Now working with python3.4 and django1.9

Here is my /etc/circus/circusd.ini

[circus]
check_delay = 5
include_dir = /etc/circus/conf.d
logoutput = /var/log/circus/system.log
statsd = True

[plugin:flapping]
use = circus.plugins.flapping.Flapping

And my project /etc/circus/conf.d/project.ini

[project_name]
cmd = chaussette project_name.wsgi.application --backend waitress --fd $(circus.sockets.project_name)
use_sockets = True
virtualenv = /path/to/env  # if you are using virtualenv
working_dir = /path/to/project
copy_env = True

stdout_stream.class = FileStream
stdout_stream.filename = /path/to/logs/stdout.log
stdout_stream.refresh_time = 0.3

stderr_stream.class = FileStream
stderr_stream.filename = /path/to/logs/error.log
stderr_stream.refresh_time = 0.3

[project_name]
PYTHONPATH  = /path/to/project

[socket:project_name]
host = localhost
port = 8000

Take care of permission on /path/to/logs/ and /var/log/circus/system.log. Directories should exists.