Guest User

God I feel lazy...

a guest
Nov 9th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.08 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #Credit where it's due.  I started with this: http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
  4. #I hate prompts in stuff I should script with a holy burning passion...
  5. #It's all commented pretty well, so here:
  6.  
  7. function install_all_the_things(){
  8.     #Install all the things...
  9.     #Get ready... we're assuming we'll use this as a scaffold to do production deployments
  10.     sudo apt-get install -y git
  11.  
  12.     #Install postgres
  13.     sudo apt-get install -y postgresql postgresql-contrib
  14.  
  15.     #Install virtualenv and binary dependencies for psycopg
  16.     sudo apt-get install -y python-virtualenv
  17.     sudo apt-get install -y libpq-dev python-dev
  18.  
  19.     #Install supervisord
  20.     sudo apt-get install -y supervisor
  21.  
  22.     #Install nginx
  23.     sudo apt-get install -y nginx
  24.     sudo service nginx start
  25.  
  26.     }
  27.  
  28. function configure_postgres(){
  29.     #Configure postgres
  30.     ##Create user
  31.     sudo su postgres -c 'createuser -DIRSw djangousera'
  32.  
  33.     ##Set password for this user
  34.     sudo su postgres -c "psql -c \"ALTER USER djangousera PASSWORD 'insertyourpassword'\""
  35.  
  36.     ##Assign a new database to this user
  37.     sudo su postgres -c 'createdb djangositea -O djangousera'
  38.     }
  39.  
  40. function create_virtualenv(){
  41.     #Create a virtualenv
  42.     cd /opt/webapps/
  43.     sudo virtualenv torhiddenservice
  44.     sudo chown -R djangouser:djangouser torhiddenservice
  45.     cd torhiddenservice
  46.     source bin/activate
  47.     }
  48.  
  49. function pip_installs(){
  50.     #Get the database adapter
  51.     pip install psycopg2
  52.  
  53.     #Get setproctitle so you can ps for a not "python" process
  54.     pip install setproctitle
  55.  
  56.     #Get gunicorn
  57.     pip install gunicorn
  58.     }
  59.  
  60. function get_your_stuff(){
  61.     #Get your project
  62.     #git clone ?
  63.     }
  64.  
  65. function config_db_connector(){
  66. #Conigure your database settings
  67. #TODO insert sed rules here
  68. settings.py
  69. DATABASES = {
  70.     'default': {
  71.         'ENGINE': 'django.db.backends.postgresql_psycopg2',
  72.         'NAME': 'djangositea',
  73.         'USER': 'djangousera',
  74.         'PASSWORD': 'insertyourpassword',
  75.         'HOST': 'localhost',
  76.         'PORT': '',                      # Set to empty string for default.
  77.     }
  78. }
  79.  
  80.     }
  81.  
  82. function gunicorn_launcher(){
  83.     #Build a gunicorn launcher
  84.     #TODO sed gunicorn config
  85.  
  86.     #Make script executable
  87.     chmod u+x bin/gunicorn_start
  88.     }
  89.  
  90. function supervisor_prep(){
  91.     #Create the conf file for our app
  92.     /etc/supervisor/conf.d/hello.conf
  93.  
  94.     #Init supervisor
  95.     $ sudo supervisorctl reread
  96.     $ sudo supervisorctl update
  97.     }
  98.  
  99. function nginx_prep(){
  100. #Create an nginx site config /etc/nginx/sites-available/hello
  101.  
  102. #I wonder if it's really necessary for it to be in both places...
  103. ln -s /etc/nginx/sites-available/hello /etc/nginx/sites-enabled/hello
  104.  
  105. sudo service nginx restart    
  106. }
  107.  
  108.  
  109.  
  110. ###############
  111.  
  112. install_all_the_things()
  113. configure_postgres()
  114. create_virtualenv()
  115. pip_installs()
  116. get_your_stuff()
  117. config_db_connector()
  118.  
  119. #Sync up your database schema
  120. python manage.py syncdb
  121.  
  122. gunicorn_launcher()
  123. supervisor_prep()
  124. nginx_prep()
  125.  
  126. echo "Done..."
Advertisement
Add Comment
Please, Sign In to add comment