This repository has been archived by the owner on Sep 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Deployment Guide
Ashwin Shenoy edited this page Mar 8, 2019
·
13 revisions
- Amazon EC2 Instance - 1GB RAM / Dedicated IP
- OS: Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-1032-aws x86_64)
- Download
.pem
key to access the server.
$ ssh -i "<FILE_NAME>.pem" [email protected]
$ sudo apt-get install binutils git libpq-dev python-dev python-setuptools python-virtualenv postgresql postgresql-contrib gdal-bin nginx supervisor memcached build-essential
$ sudo git clone https://gitlab.com/amfoss/cms.git
$ sudo su - postgres
postgres@ip-xxx-xx-xx-xxx: ~ $ createuser --interactive -P
Enter name of role to add: amfoss
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
postgres@ip-xxx-xx-xx-xxx: ~ $ createdb --owner=cms amfoss
postgres@ip-xxx-xx-xx-xxx: ~ $ logout
$ sudo groupadd --system amfoss
$ sudo useradd --system --gid amfoss --shell /bin/bash --home /var/www/cms/ amfoss
Update the Database configuration in settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'cms',
'USER': 'amfoss',
'PASSWORD': '<YOUR PASSWORD HERE>',
'HOST': 'localhost',
'PORT': '', # Set to empty string for default.
}
}
$ sudo su - amfoss
amfoss@ip-xxx-xx-xx-xxx:~$ cd /var/www/cms/
amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ virtualenv -p python3 .
amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ source bin/activate
(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ pip install -r requirements.txt
Copy from sample environment configuration variables in .env.example
, or create a new .env
file,
and update/add all configuration details
(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ cp .env.example .env
(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ python manage.py migrate
(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ python manage.py makemigrations activity blog gsoc gallery pages members status
(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ python manage.py migrate
(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ python manage.py collectstatic
(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ python manage.py runserver 0.0.0.0:8000
(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ vim /var/www/cms/bin/gunicorn_start
#!/bin/bash
NAME="framework"
DJANGODIR=/var/www/cms
SOCKFILE=/var/www/cms/run/gunicorn.sock
USER=amfoss
GROUP=amfoss
NUM_WORKERS=5
DJANGO_SETTINGS_MODULE=framework.settings
DJANGO_WSGI_MODULE=framework.wsgi
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source ./bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec ./bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ /var/www/cms/bin/gunicorn_start
$ mkdir -p /var/www/cms/logs/
$ touch /var/www/cms/logs/gunicorn_supervisor.log
$ sudo supervisorctl reread
amfoss: available
$ sudo supervisorctl update
amfoss: added process group