-
Notifications
You must be signed in to change notification settings - Fork 31
Deployment
Deploying of 1327 is not as easy as eating a piece of cake, but it should be possible to handle if you stick to the following guide:
We recommend that you get Nginx as webserver. You can then follow this guide for configuring your Nginx Webserver.
In order to make Nginx load your Django code you will need a reverse proxy that is called by Nginx and executes your python code. You may use uwsgi for this or gunicorn. You can find more information on how to configure uwsgi with nginx and django by following this link.
In order to serve static files you need to make sure that you copy all your static files to the correct directory where Nginx can find them. You will also need to add the following lines to your localsettings.py
:
SENDFILE_BACKEND = 'sendfile.backends.nginx'
SENDFILE_ROOT = '<path to your static files>'
SENDFILE_URL = '/media'
1327 uses Websockets for showing live updates of Documents that are currently edited. As Django in combination with a Webserver is not capable of handling Websockets you will need some more services on your Server that handle the websocket communication.
Before you begin you should install the necessary libraries by issuing the following command: pip install -r requirements-deploy.txt
from the root folder of the project.
After you did this you should add the following line to your localsettings.py
:
CHANNEL_LAYERS = {
"default": {
"BACKEND": "asgi_ipc.IPCChannelLayer",
"ROUTING": "_1327.routing.channel_routing",
"CONFIG": {
"prefix": "<your very own choice>",
},
},
}
In order to successfully run 1327 with Websocket communication enabled you need to run the following services:
daphne _1327.asgi:channel_layer -u /tmp/daphne.sock
python manage.py runworker
The first command starts Daphne, which is a server that handles the websocket requests. The second command starts a worker thread used by Daphne to handle all requests in an asynchronous manner.
You should start these services using a Process Control System like Supervisor or Systemd. We will here focus on how to configure Supervisor but it should be quite similar to other possibilities.
After you've installed Supervisor you should add the following files *you can choose the filename the way you liketo the folder
/etc/supervsor/conf.d/`:
[program:1327_daphne]
command=<path to your python venv>/bin/daphne _1327.asgi:channel_layer -u /tmp/daphne.sock
directory=<path to your clone of 1327>
user=nobody
group=nogroup # you can also use nobody here if your system does not have the group nogroup
autostart=true
autorestart=true
stdout_logfile = <path to a log file>
stderr_logfile = <path to a log file>
[program:1327_worker]
command=<path to your python venv>/bin/python manage.py runworker
directory=<path to your clone of 1327>
user=nobody
group=nogroup # you can also use nobody here if your system does not have the group nogroup
autostart=true
autorestart=true
stdout_logfile = <path to a log file>
stderr_logfile = <path to a log file>
You may then try to start your services by issuing one of the following commands:
- if your system uses systemd:
systemctl start supervisor
- if your system uses init.d:
service supervisor start
If everything works well you should now have a service that listens on the unix socket /tmp/daphne.sock
You can also check that it works by issuing:
- systemd:
systemctl status supervisor
- init.d:
service supervisor status