Skip to content

Instantly share code, notes, and snippets.

@jdunck
Created July 14, 2012 01:18
Show Gist options
  • Save jdunck/3108655 to your computer and use it in GitHub Desktop.
Save jdunck/3108655 to your computer and use it in GitHub Desktop.
puppet for sentry w/ mysql
define sentry::server(
$dir,
$user = 'sentry',
$sentry_version = '3.7.1',
$sentry_domain = 'some.host.com',
$sentry_web_host = '0.0.0.0',
$sentry_web_port = '9000',
$sentry_udp_host = '0.0.0.0',
$sentry_udp_port = '9001',
$sentry_num_workers = '20',
$db_engine = 'postgresql_psycopg2', # overridden in actual use
$db_name = 'sentry',
$db_user = 'sentry',
$db_password = '',
$db_host = '',
$db_port = ''
) {
# this creates a virtual environment
upvote::virtualenv {
"sentry-$name":
dir => $dir,
user => $user,
require => Line["github-known_hosts"]; # this adds github to ssh known hosts.
}
# bump the date on the touched file if you revise the command
exec {
"sentry-$name-install": # eventlet/gevent needed for decent udp perf
environment => "HOME=/home/${user}",
command => "${dir}/bin/pip install -vv MySQL-python==1.2.3 eventlet==0.9.16 gevent==0.13.6 sentry==$sentry_version && touch $dir/sentry-$sentry_version-20120331",
user => $user,
unless => "[ -f $dir/sentry-$sentry_version-20120331 ]",
require => [
Upvote::Virtualenv["sentry-$name"],
Package['python-virtualenv'],
Package['libmysqlclient-dev'] #hacky, we don't actually use postgres as suggested by db_engine above.
];
}
# installs supervisor w/ a conf.d bootstrapper.
include supervisord
# supply conf.d scripts for startup.
file {
"$dir/sentry.conf":
mode => 0644,
content => template("sentry/sentry.conf.erb"),
owner => $user,
group => $user,
require => Exec["sentry-$name-install"];
"/etc/supervisor/conf.d/sentry-$name-udp.sh":
mode => 0755,
owner => root,
group => root,
content => "#!/bin/bash
source $dir/bin/activate
$dir/bin/sentry --config=$dir/sentry.conf upgrade --noinput
exec $dir/bin/sentry --config=$dir/sentry.conf start udp
",
require => Package['supervisor'];
"/etc/supervisor/conf.d/sentry-$name-http.sh":
mode => 0755,
owner => root,
group => root,
content => "#!/bin/bash
source $dir/bin/activate
$dir/bin/sentry --config=$dir/sentry.conf upgrade --noinput
exec $dir/bin/sentry --config=$dir/sentry.conf start http
",
require => Package['supervisor'];
}
# tells supervisor to manage sentry:
supervisord::program {
"$name-udp":
cmd => "/etc/supervisor/conf.d/sentry-$name-udp.sh",
dir => "$dir",
user => "$user",
stopwaitsecs => 600,
require => File["/etc/supervisor/conf.d/sentry-$name-udp.sh"],
subscribe => File["$dir/sentry.conf"];
"$name-http":
cmd => "/etc/supervisor/conf.d/sentry-$name-http.sh",
dir => "$dir",
user => "$user",
stopwaitsecs => 600,
require => File["/etc/supervisor/conf.d/sentry-$name-http.sh"],
subscribe => File["$dir/sentry.conf"];
}
}
import os.path
CONF_ROOT = os.path.dirname(__file__)
DATABASES = {
'default': {
# You can swap out the engine for MySQL easily by changing this value
# to ``django.db.backends.mysql`` or to PostgreSQL with
# ``django.db.backends.postgresql_psycopg2``
'ENGINE': 'django.db.backends.<%= db_engine -%>',
<% if db_engine == "sqlite3" %>
'NAME': os.path.join(CONF_ROOT, '<%= db_name %>'),
<% else %>
'NAME': '<%= db_name %>',
<% end %>
'USER': '<%= db_user -%>',
'PASSWORD': '<%= db_password -%>',
'HOST': '<%= db_host -%>',
'PORT': '<%= db_port -%>',
}
}
EMAIL_HOST = "smtp.sendgrid.com"
EMAIL_PORT = 25
EMAIL_HOST_USER = "[email protected]"
EMAIL_HOST_PASSWORD = "pwd"
EMAIL_USE_TLS = True
SERVER_EMAIL="[email protected]"
SEND_BROKEN_LINK_EMAILS = False
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
SENTRY_EMAIL_SUBJECT_PREFIX = "[example sentry]"
SENTRY_KEY = 'nopenopenope'
# Set this to false to require authentication
SENTRY_PUBLIC = False
SENTRY_URL_PREFIX = 'http://<%= sentry_domain -%>:<%= sentry_web_port -%>' # No trailing slash!
SENTRY_WEB_HOST = '<%= sentry_web_host -%>'
SENTRY_WEB_PORT = <%= sentry_web_port -%>
SENTRY_WEB_OPTIONS = {
'workers': <%= sentry_num_workers -%>, # the number of gunicorn workers
'worker_class': 'gevent',
#'keepalive': 0,
}
SENTRY_UDP_HOST = '<%= sentry_udp_host -%>'
SENTRY_UDP_PORT = <%= sentry_udp_port -%>
class supervisord {
package {
"supervisor": ensure => "3.0a8-1";
}
file {
"/etc/supervisor/":
ensure => directory,
mode => 0755,
owner => root,
group => root;
"/etc/supervisor/supervisord.conf":
content => template("supervisord/supervisord.conf.erb"),
mode => 0644,
owner => root,
group => root,
require => Package["supervisor"];
}
service {
"supervisor":
ensure => running,
enable => true,
subscribe => File["/etc/supervisor/supervisord.conf"],
hasstatus => true,
hasrestart => false,
require => Package["supervisor"],
}
}
define supervisord::program($cmd, $dir, $user, $numprocs = 1, $env = "",
$stopwaitsecs = 10) {
service {
"supervisor-program-$name":
provider => "base",
ensure => running,
enable => true,
hasstatus => true,
status => "supervisorctl restart $name | grep RUNNING",
hasrestart => true,
restart => "supervisorctl restart $name",
start => "supervisorctl start $name",
stop => "supervisorctl stop $name",
require => Package["supervisor"];
}
file {
"/etc/supervisor/conf.d/$name.conf":
content => template("supervisord/conf.d/template.conf.erb"),
mode => 0644,
owner => root,
group => root,
require => [
Package["supervisor"],
Service["supervisor"]
],
notify => Service["supervisor-program-$name"];
}
}
; =======================================
; <%= name %>
; =======================================
[program:<%= name -%>]
command=<%= cmd %>
directory=<%= dir %>
user=<%= user %>
<% if env %>environment=<%= env %><% end %>
numprocs=<%= numprocs %>
stdout_logfile=/var/log/<%= name -%>.log
stderr_logfile=/var/log/<%= name -%>.err
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=<%= stopwaitsecs %>
; supervisor config file
[unix_http_server]
file=/var/run//supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run//supervisor.sock ; use a unix:// URL for a unix socket
; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
[include]
files = /etc/supervisor/conf.d/*.conf
define upvote::virtualenv($dir, $repo='', $req_file='', $user = 'ubuntu') {
exec {
"virtualenv-${dir}":
command => "/usr/bin/virtualenv --no-site-packages '${dir}'",
creates => "${dir}",
user => $user,
require => Package["python-virtualenv"];
"virtualenv-${dir}-bootstrap":
command => "${dir}/bin/pip install distribute==0.6.10",
user => $user,
require => Exec["virtualenv-${dir}"],
returns => [0,1],
creates => "${dir}/lib/python2.6/site-packages/distribute-0.6.10-py2.6.egg-info";
}
if $repo {
upvote::repo {
"repo-${dir}/${name}":
dir => "${dir}/${name}",
repo => $repo,
user => $user,
require => Exec["virtualenv-${dir}"];
}
}
if $req_file {
exec {
"reqs-${req_file}":
# pip uses expanduser, which uses $HOME
environment => "HOME=/home/${user}",
command => "${dir}/bin/pip install -vv -r ${dir}/${name}/${req_file} && md5sum ${dir}/${name}/${req_file} > ${dir}/installed-${name}-${req_file}",
user => $user,
unless => "md5sum -c ${dir}/installed-${name}-${req_file}",
timeout => 600,
require => [
Exec["git-${dir}/${name}"],
Exec["virtualenv-${dir}-bootstrap"],
File["${user}-pip.conf"],
Package["libmysqlclient-dev"]
];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment