-
Piotr Gawron authoredPiotr Gawron authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
To learn more about this project, read the wiki.
readme.md 6.33 KiB
SMart SCHeduling
Required software (on ubuntu's OS family):
sudo apt-get install libpq-dev python-dev postgresql postgresql-contrib python virtualenv python-virtualenv gcc
Postgres installation
- If you don't have postgres installed, complete step seven from https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn (remember to save all the credentials, they will be necessary to run the application).
Developer project installation
mkdir -p ~/dev/smash
cd ~/dev/smash
git clone ssh://git@git-r3lab-server.uni.lu:8022/piotr.atyjaszyk/scheduling-system.git
cd scheduling-system
-
virtualenv env
to create new virtualenv (contains clean python working environment) -
. env/bin/activate
(to start using virtualenv) -
pip install -r requirements.txt
to install project's dependencies - Create
local_settings.py
file in(./scheduling-system)/smash/smash
directory (see template below), and change your database connection data:
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'Paste long random string here' # Insert long random string
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
WSGI_APPLICATION = 'smash.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'smashdb', # Insert your database's name
'USER': 'postgresmashuser', # Insert your database's user
'PASSWORD': 'thePOSTGRESpassword', # Insert your user's password
'HOST': 'localhost',
'PORT': '' # '' === default one # Empty string is OK
# If to use sqlite
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
STATIC_ROOT = '/tmp/static' # Warning! `/tmp` directory can be flushed in any moment; use a persistent one; e.g. ~/tmp/static
MEDIA_ROOT = '/tmp/media' # Warning! `/tmp` directory can be flushed in any moment; use a persistent one, e.g. ~/tmp/media
- Update migration db scrpit from file structure (
./scheduling-system/smash/manage.py makemigrations
) - Create the database by applying migrations (
./scheduling-system/smash/manage.py migrate
) - Create the first, administrative, user- (
./scheduling-system/smash/manage.py createsuperuser
)
Development
- Remember, that before working you have to activate virtualenv, by:
devel@host ~/home/smash/scheduling-system $ . env/bin/activate
- In order to run development server, run:
devel@host ~/home/smash/scheduling-system/smash $ ./manage.py runserver
and go to127.0.0.1:8000
in browser - For reference of HTML tempalte, see https://almsaeedstudio.com/themes/AdminLTE/pages/widgets.html#
Production deployment
- git pull and other project installation should be performed in a dir where this django app should be installed, in this tutorial it's /var/www/scheduling-system/
- install nginx:
apt-get install nginx
- create gunicorn service in systemd (http://docs.gunicorn.org/en/stable/deploy.html#systemd):
/etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
PIDFile=/run/gunicorn/pid
User=www-data
Group=www-data
WorkingDirectory=/var/www/scheduling-system/smash
ExecStart=/var/www/scheduling-system/env/bin/gunicorn --pid /run/gunicorn/pid smash.wsgi
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
/etc/systemd/system/gunicorn.socket
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn/socket
ListenStream=0.0.0.0:9000
ListenStream=[::]:8000
[Install]
WantedBy=sockets.target
- modify nginx configuration
# /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
/etc/nginx/sites-enabled/default
upstream app_server {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response
# for UNIX domain socket setups
server unix:/run/gunicorn/socket fail_timeout=0;
# for a TCP configuration
# server 192.168.0.7:8000 fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name prc.parkinson.lu;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
location / {
# checks for static file, if not found proxy to app
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# enable this if and only if you use HTTPS
# proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
# we don't want nginx trying to do something clever with
# redirects, we set the Host: header above already.
proxy_redirect off;
proxy_pass http://app_server;
}
}
- extract static files and make them available via nginx:
./manage.py collectstatic
- you start application by starting gunicorn and nginx:
service gunicorn start
,service nginx start