Skip to content

Instantly share code, notes, and snippets.

@joneskoo
Last active October 25, 2020 06:41
Show Gist options
  • Save joneskoo/b69e68d0d9a108ba520c to your computer and use it in GitHub Desktop.
Save joneskoo/b69e68d0d9a108ba520c to your computer and use it in GitHub Desktop.
Kapsi Django example project
Options -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://lakka.n.kapsi.fi:31859/$1 [L,P]
# Best practice: projects under a common directory
joneskoo@lakka:~$ mkdir ~/apps
joneskoo@lakka:~$ cd ~/apps
# Best practice: python packages installed in virtualenv
joneskoo@lakka:~/apps$ virtualenv --python=python2.7 ve
$ source ve/bin/activate
(ve)joneskoo@lakka:~/apps$ pip install django supervisor gunicorn
# Create a Django project
(ve)joneskoo@lakka:~/apps$ django-admin.py startproject example
# Set up supervisor to start and monitor server process
(ve)joneskoo@lakka:~/apps$ editor supervisord.conf
...
(ve)joneskoo@lakka:~/apps$ mkdir run log
(ve)joneskoo@lakka:~/public_html/example$ cd ~/apps/
(ve)joneskoo@lakka:~/apps$ ~/apps/ve/bin/supervisord -c ~/apps/supervisord.conf
(ve)joneskoo@lakka:~/apps$ supervisorctl status
example RUNNING pid 9653, uptime 0:00:11
# Start supervisor on reboot automatically from cron
(ve)joneskoo@lakka:~/apps$ crontab -e
# Set up proxy under web root
(ve)joneskoo@lakka:~/apps$ mkdir -p ~/public_html/example
(ve)joneskoo@lakka:~/apps$ cd ~/public_html/example
(ve)joneskoo@lakka:~/public_html/example$ editor .htaccess
...
@reboot $HOME/apps/ve/bin/supervisord -c $HOME/apps/supervisord.conf
[unix_http_server]
file=%(here)s/run/supervisor.sock ; (the path to the socket file)
chmod=0700 ; socket file mode (default 0700)
directory=%(here)s
[supervisord]
pidfile=%(here)s/run/supervisor.pid
logfile=%(here)s/log/supervisor.log
childlogdir=%(here)s/log/
logfile_maxbytes=10MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=5 ; (num of main logfile rotation backups;default 10)
nodaemon=false ; (start in foreground if true;default false)
strip_ansi=true ; (strip ansi escape codes in logs; def. false)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix://%(here)s/run/supervisor.sock ; use a unix:// URL for a unix socket
[program:example]
command=%(here)s/ve/bin/gunicorn -b lakka.n.kapsi.fi:31859 example.wsgi:application
directory=%(here)s/example
autostart=true
autorestart=true
redirect_stderr=True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment