Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Credit where it's due. I started with this: http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
- #I hate prompts in stuff I should script with a holy burning passion...
- #It's all commented pretty well, so here:
- function install_all_the_things(){
- #Install all the things...
- #Get ready... we're assuming we'll use this as a scaffold to do production deployments
- sudo apt-get install -y git
- #Install postgres
- sudo apt-get install -y postgresql postgresql-contrib
- #Install virtualenv and binary dependencies for psycopg
- sudo apt-get install -y python-virtualenv
- sudo apt-get install -y libpq-dev python-dev
- #Install supervisord
- sudo apt-get install -y supervisor
- #Install nginx
- sudo apt-get install -y nginx
- sudo service nginx start
- }
- function configure_postgres(){
- #Configure postgres
- ##Create user
- sudo su postgres -c 'createuser -DIRSw djangousera'
- ##Set password for this user
- sudo su postgres -c "psql -c \"ALTER USER djangousera PASSWORD 'insertyourpassword'\""
- ##Assign a new database to this user
- sudo su postgres -c 'createdb djangositea -O djangousera'
- }
- function create_virtualenv(){
- #Create a virtualenv
- cd /opt/webapps/
- sudo virtualenv torhiddenservice
- sudo chown -R djangouser:djangouser torhiddenservice
- cd torhiddenservice
- source bin/activate
- }
- function pip_installs(){
- #Get the database adapter
- pip install psycopg2
- #Get setproctitle so you can ps for a not "python" process
- pip install setproctitle
- #Get gunicorn
- pip install gunicorn
- }
- function get_your_stuff(){
- #Get your project
- #git clone ?
- }
- function config_db_connector(){
- #Conigure your database settings
- #TODO insert sed rules here
- settings.py
- DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.postgresql_psycopg2',
- 'NAME': 'djangositea',
- 'USER': 'djangousera',
- 'PASSWORD': 'insertyourpassword',
- 'HOST': 'localhost',
- 'PORT': '', # Set to empty string for default.
- }
- }
- }
- function gunicorn_launcher(){
- #Build a gunicorn launcher
- #TODO sed gunicorn config
- #Make script executable
- chmod u+x bin/gunicorn_start
- }
- function supervisor_prep(){
- #Create the conf file for our app
- /etc/supervisor/conf.d/hello.conf
- #Init supervisor
- $ sudo supervisorctl reread
- $ sudo supervisorctl update
- }
- function nginx_prep(){
- #Create an nginx site config /etc/nginx/sites-available/hello
- #I wonder if it's really necessary for it to be in both places...
- ln -s /etc/nginx/sites-available/hello /etc/nginx/sites-enabled/hello
- sudo service nginx restart
- }
- ###############
- install_all_the_things()
- configure_postgres()
- create_virtualenv()
- pip_installs()
- get_your_stuff()
- config_db_connector()
- #Sync up your database schema
- python manage.py syncdb
- gunicorn_launcher()
- supervisor_prep()
- nginx_prep()
- echo "Done..."
Advertisement
Add Comment
Please, Sign In to add comment