Skip to content

Instantly share code, notes, and snippets.

@jalaziz
Created August 14, 2014 02:25
Show Gist options
  • Save jalaziz/55de1a30400dadf3152b to your computer and use it in GitHub Desktop.
Save jalaziz/55de1a30400dadf3152b to your computer and use it in GitHub Desktop.
Sentry upstart and nginx configs

Setup

  1. Create a new user on the system:

    sudo adduser --system --group --shell /bin/bash --home /opt/sentry sentry
  2. Create the virualenv and install the required packages:

    sudo -u sentry virtualenv /opt/sentry
    sudo -u sentry /opt/sentry/bin/pip install sentry
  3. Place the upstart configs in /etc/init.

  4. Place the nginx config in /etc/nginx/sites-available. Then symlink to /etc/nginx/sites-enabled.

  5. Initialize sentry (run as the sentry user):

    cd /opt/sentry
    source bin/activate
    sentry init /opt/sentry/sentry.conf.py
    vi /opt/sentry/sentry.conf.py  # Edit the sentry configuration
    export SENTRY_CONF=/opt/sentry/sentry.conf.py
    sentry upgrade
    sentry createsuperuser
    sentry repair --owner=<superuser>
description "Sentry Celery"
start on started sentry
stop on stopping sentry
respawn limit 10 5
chdir /opt/sentry
setuid sentry
env VIRTUAL_ENV=/opt/sentry/
env PYTHONUNBUFFERED=True
env SENTRY_CONF=/opt/sentry/sentry.conf.py
exec $VIRTUAL_ENV/bin/sentry celery worker -B --loglevel=info >> /var/log/sentry/celery.log 2>&1
description "Sentry Web"
start on started sentry
stop on stopping sentry
respawn limit 10 5
chdir /opt/sentry
setuid sentry
env VIRTUAL_ENV=/opt/sentry/
env PYTHONUNBUFFERED=True
env SENTRY_CONF=/opt/sentry/sentry.conf.py
exec $VIRTUAL_ENV/bin/sentry start >> /var/log/sentry/web.log 2>&1
description "Sentry"
pre-start script
mkdir -p /var/log/sentry
chown -R sentry /var/log/sentry
end script
start on runlevel [2345]
stop on runlevel [016]
# we limit both on IP (single machine) as well as project ID
limit_req_zone $binary_remote_addr zone=sentry1:10m rate=3r/s;
limit_req_zone $projectid zone=sentry2:10m rate=3r/s;
server {
listen 80;
server_name sentry.example.com;
# limit_req_status requires nginx 1.3.15 or newer
limit_req_status 429;
charset utf-8;
access_log /var/log/nginx/sentry.access.log;
error_log /var/log/nginx/sentry.error.log;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
# keepalive + raven.js is a disaster
keepalive_timeout 0;
# use very aggressive timeouts
proxy_read_timeout 5s;
proxy_send_timeout 5s;
send_timeout 5s;
resolver_timeout 5s;
client_body_timeout 5s;
# buffer larger messages
client_max_body_size 150k;
client_body_buffer_size 150k;
location / {
proxy_pass http://localhost:9000;
}
location ~* /api/(?P<projectid>\d+/)?store/ {
proxy_pass http://localhost:9000;
limit_req zone=sentry1 burst=3 nodelay;
limit_req zone=sentry2 burst=10 nodelay;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment