Wednesday, August 7, 2013

Using Heroku - Common Usage

Show dynos / processes
heroku ps

Scale the number of web dynos to 1
heroku ps:scale web=1

Show heroku logs
heroku logs

Show environment variables for the app
heroku config

Add the SSL endpoint add-on
heroku addons:add ssl:endpoint

Add the SSL endpoint add-on (note, this is paid, $20/month)
heroku addons:add ssl:endpoint

Using virtualenv

$ sudo apt-get install python-pip python-dev build-essential
$ sudo pip install --upgrade pip
$ sudo pip install --upgrade virtualenv
Install pip and virtualenv (on Ubuntu)

virtualenv ~/env
Creates a virtual environment at this location

source ~/env/bin/activate
Activates the virtual environment

deactivate
Deactivates the virtual environment

Monday, August 5, 2013

export LANG=en_GB

Add

export LANG=en_GB

to .bashrc

git push heroku remote end hung up unexpectedly

I had a public key established with Heroku, but git push kept failing.
The solution was to modify the ~/.ssh/config file

This problem was messing with me for a few days.
This this might help.
1) Find out what keys you have in Heroku now.
$ heroku keys
=== 1 key for joe@example.com
ssh-dss AAAAB8NzaC...DVj3R4Ww== joe@workstation.local
2) Build a ~/.ssh/config file:
$ sudo vim ~/.ssh/config
Edit with this info
Host heroku.com
Hostname heroku.com 
Port 22 
IdentitiesOnly yes 
IdentityFile ~/.ssh/ssh-dss # location and name of your private key
TCPKeepAlive yes 
User joe@workstation.local

Django run server in background

To run the django debug server in the background in linux:

./manage.py runserver > /dev/null 2>&1 &

Sunday, July 7, 2013

How to get real IP addresses in nginx access logs from ELB

With the default setup of nginx using AWS Elastic Load Balancer, all the IPs were being logged as being from the load balancer.

To get the real IP addresses of the requests, the nginx.conf file at /etc/nginx/nginx.conf is modified to have two additional lines:


 # /etc/nginx/nginx.conf  
 ...  
 real_ip_header X-Forwarded-For;  
 set_real_ip_from 10.0.0.0/8;  
 ...  

Friday, July 5, 2013

Setting uwsgi to run at startup

Modify the /etc/rc.local file to start uwsgi at startup

 #!/bin/sh -e
 #  
 # rc.local  
 #  
 # This script is executed at the end of each multiuser runlevel.  
 # Make sure that the script will "exit 0" on success or any other  
 # value on error.  
 #  
 # In order to enable or disable this script just change the execution  
 # bits.  
 #  
 # By default this script does nothing.  
 /usr/local/bin/uwsgi --ini /home/user/app/uwsgi.ini  
 exit 0