This site runs best with JavaScript enabled.

Setting Up Your Own Sentry Server


Short tutorial on how to set up your own self-hosted Sentry server.

Sentry

If you are hosting a Django site, Sentry will make your life easier.

After my review of various hosting companies I decided to put EnvelopeBudget.com on Webfaction. But, I was still impressed with Digital Ocean so I kept my virtual server. Why not? It's only $5 per month for full root access! Because all their servers have SSD's I'ver never seen a virtual server boot so fast. Soon will be the day when you will hear someone say, "remember when computers had moving parts?" I kept it because I figured I'd find a use for it eventually. Well, I found a use for it.

I love Sentry. We used it at SendOutCards to help us better manage our server errors. I think we were running a pre 1.0 release when it was just called django-sentry. It has come a long way. I set up an account on GetSentry.com and loved it. Since I'm bootstrapping a start-up, I decided to set up my own sentry server on my Digital Ocean account.

I documented the process I went through setting up the server.

Create Ubuntu 12.10 X32 Server droplet & ssh into it as root

1# add non-root user
2adduser sentry
3
4# add to sudoers
5adduser sentry sudo
6
7# log out of root and log in as sentry
8exit
9
10# update the local package index
11sudo apt-get update
12
13# actually upgrade all packages that can be upgraded
14sudo apt-get dist-upgrade
15
16# remove any packages that are no longer needed
17sudo apt-get autoremove
18
19# reboot the machine, which is only necessary for some updates
20sudo reboot
21
22# install python-dev
23sudo apt-get install build-essential python-dev
24
25# download distribute
26curl -O http://python-distribute.org/distribute_setup.py
27
28# install distribute
29sudo python distribute_setup.py
30
31# remove installation files
32rm distribute\*
33
34# use distribute to install pip
35sudo easy_install pip
36
37# install virtualenv and virtualenvwrapper
38sudo pip install virtualenv virtualenvwrapper
39
40# to enable virtualenvwrapper add this line to the end of the .bashrc file
41echo "" >> .bashrc
42echo "source /usr/local/bin/virtualenvwrapper.sh" >> .bashrc
43
44# exit and log back in to restart your shell
45exit
46
47# make virtualenv
48mkvirtualenv sentry_env
49
50# install sentry
51pip install sentry
52
53# create settings file (file will be located in ~/.sentry/sentry.conf.py)
54sentry init
55
56# install postgres
57sudo apt-get install postgresql postgresql-contrib libpq-dev
58
59# install postgres adminpack
60sudo -u postgres psql
61CREATE EXTENSION "adminpack";
62q
63
64# change postgres password & create database
65sudo passwd postgres
66sudo su - postgres
67psql -d template1 -c "ALTER USER postgres WITH PASSWORD '<span class="highlight">changeme</span>';"
68createdb <span class="highlight">your_sentry_db_name</span>
69createuser <span class="highlight">your_sentry_user</span> --pwprompt
70psql -d template1 -U postgres
71GRANT ALL PRIVILEGES ON DATABASE <span class="highlight">your_sentry_db_name</span> to <span class="highlight">your_sentry_user</span>;
72q
73exit
74
75# update config file to use postgres &amp; host (with vim or your editor of choice)
76sudo apt-get install vim
77vim .sentry/sentry.conf.py

The following are the contents of my sentry.conf.py file:

1DATABASES = {
2 'default': {
3 'ENGINE': 'django.db.backends.postgresql_psycopg2',
4 'NAME': '<span class="highlight">your_sentry_db_name</span>',
5 'USER': '<span class="highlight">your_sentry_user</span>',
6 'PASSWORD': '<span class="highlight">your_password</span>',
7 'HOST': 'localhost',
8 }
9}

You will also want to configure your SMTP mail account. I just used my gmail account.

1# going to need psycopg2
2workon sentry_env
3pip install psycopg2
4
5# set up databse
6sentry upgrade
7
8# let's try it out!
9sentry start
10
11# install nginx
12sudo apt-get install nginx
13
14# remove the default symbolic link
15sudo rm /etc/nginx/sites-enabled/default
16
17# create a new blank config, and make a symlink to it
18sudo touch /etc/nginx/sites-available/sentry
19cd /etc/nginx/sites-enabled
20sudo ln -s ../sites-available/sentry
21
22# edit the nginx configuration file
23sudo vim /etc/nginx/sites-available/sentry

Here are the contents of my Nginx file:

1server {
2 # listen on port 80
3 listen 80;
4
5 # for requests to these domains
6 server_name <span class="highlight">yourdomain.com www.yourdomain.com</span>;
7
8 # keep logs in these files
9 access_log /var/log/nginx/sentry.access.log;
10 error_log /var/log/nginx/sentry.error.log;
11
12 # You need this to allow users to upload large files
13 # See http://wiki.nginx.org/HttpCoreModule#client_max_body_size
14 # I'm not sure where it goes, so I put it in twice. It works.
15 client_max_body_size 0;
16
17 location / {
18 proxy_pass http://localhost:9000;
19 proxy_redirect off;
20
21 proxy_read_timeout 5m;
22
23 # make sure these HTTP headers are set properly
24 proxy_set_header Host $host;
25 proxy_set_header X-Real-IP $remote_addr;
26 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
27 }
28}

That's about it.

1# restart nginx
2sudo service nginx restart

I set up supervisor as recommend in the comments and the docs to keep sentry runny (though it has never crashed, it does make restarting easier)

1sudo apt-get install supervisor
2sudo vim /etc/supervisor/conf.d/sentry.conf

Add the following to the sentry.conf file:

1[program:sentry-web]
2directory=/home/sentry/
3command=/home/sentry/.virtualenvs/sentry_env/bin/sentry start http
4autostart=true
5autorestart=true
6redirect_stderr=true

Restart supervidord

1sudo killall supervisord
2sudo supervisord

Upgrading Sentry:

I've upgraded twice. It was a painless process...

1workon sentry_env
2pip install sentry --upgrade
3sentry upgrade
4sudo supervisorctl restart sentry-web

Discuss on TwitterEdit post on GitHub

Share article
Dustin Davis

Dustin Davis is a software engineer, people manager, hacker, and entreprenuer. He loves to develop systems and automation. He lives with his wife and five kids in Utah.

Join the Newsletter



Dustin Davis