New appliance: dpaste.

This commit is contained in:
Albert Hopkins 2013-08-31 01:35:00 +00:00
parent eec5dbac8f
commit 11519edcde
11 changed files with 378 additions and 0 deletions

47
dpaste/Makefile Normal file
View File

@ -0,0 +1,47 @@
PGVER = 9.2
DPASTE_USER = dpaste
DPASTE_HOME = /opt/dpaste
PIP = $(DPASTE_HOME)/bin/pip
DPASTE_REPO = https://github.com/bartTC/dpaste
rcdefault := /etc/runlevels/default
preinstall:
postinstall: bash_profile nginx.conf dpaste.init settings.py firstboot.start
$(inroot) $(EMERGE) $(USEPKG) -1n dev-vcs/git
$(inroot) $(EMERGE) -n $(USEPKG) dev-db/postgresql-server:$(PGVER)
$(inroot) passwd -d postgres
$(inroot) eselect postgresql set $(PGVER)
$(inroot) rm -rf /var/lib/postgresql/$(PGVER)/data
yes | $(inroot) $(EMERGE) --config postgresql-server:$(PGVER)
$(inroot) ln -sf /etc/init.d/postgresql-$(PGVER) $(rcdefault)/postgresql-$(PGVER)
$(inroot) $(EMERGE) -1n $(USEPKG) dev-python/virtualenv
$(inroot) getent passwd $(DPASTE_USER) || \
$(inroot) useradd -c "Dpaste Server" -G postgres -U -d $(DPASTE_HOME) $(DPASTE_USER)
rm -rf $(CHROOT)/$(DPASTE_HOME)
mkdir -p $(CHROOT)/$(DPASTE_HOME)
mkdir -p $(CHROOT)/$(DPASTE_HOME)/media
mkdir -p $(CHROOT)/$(DPASTE_HOME)/var
$(inroot) rm -rf $(DPASTE_HOME)/dpaste
$(inroot) git clone $(DPASTE_REPO) $(DPASTE_HOME)/dpaste
sed -i 's/dpaste\.de/dpaste/g' $(CHROOT)/$(DPASTE_HOME)/dpaste/dpaste/templates/dpaste/*.html
cp bash_profile $(CHROOT)$(DPASTE_HOME)/.bash_profile
$(inroot) virtualenv -p /usr/bin/python2.7 $(DPASTE_HOME)
$(inroot) $(PIP) install -r $(DPASTE_HOME)/dpaste/requirements.txt
$(inroot) $(PIP) install psycopg2
$(inroot) $(DPASTE_HOME)/bin/django-admin.py startproject project $(DPASTE_HOME)
grep ^SECRET_KEY $(CHROOT)/$(DPASTE_HOME)/project/settings.py > $(CHROOT)/$(DPASTE_HOME)/project/keyfile.py
cp settings.py $(CHROOT)/$(DPASTE_HOME)/project/settings.py
chmod +x $(CHROOT)/$(DPASTE_HOME)/manage.py
cp nginx.conf $(CHROOT)/etc/nginx
cp dpaste.init $(CHROOT)/etc/init.d/dpaste
cp firstboot.start $(CHROOT)/etc/local.d/firstboot.start
touch $(CHROOT)/firstboot
ln -sf /etc/init.d/nginx $(CHROOT)/$(rcdefault)/nginx
$(inroot) ln -sf ../manage.py $(DPASTE_HOME)/bin/manage
$(inroot) $(EMERGE) --depclean --with-bdeps=n
clean:

3
dpaste/bash_profile Normal file
View File

@ -0,0 +1,3 @@
export DJANGO_SETTINGS_MODULE='project.settings_local'
PATH="$HOME/bin:$PATH"
. activate

37
dpaste/critical Normal file
View File

@ -0,0 +1,37 @@
app-editors/nano
net-misc/openssh
net-misc/rsync
net-misc/wget
sys-kernel/gentoo-sources
sys-kernel/linux-headers
sys-devel/gcc
sys-devel/automake
sys-devel/bison
sys-devel/make
sys-devel/flex
sys-devel/automake-wrapper
sys-devel/autoconf-wrapper
sys-devel/autoconf
sys-devel/m4
sys-devel/gcc-config
sys-devel/libtool
sys-devel/binutils
sys-devel/binutils-config
sys-devel/patch
sys-devel/gnuconfig
app-admin/python-updater
app-admin/perl-cleaner
sys-apps/man-pages
sys-apps/man
sys-apps/file
sys-apps/less
sys-apps/texinfo
sys-apps/busybox
sys-apps/debianutils
sys-apps/man-pages-posix
sys-apps/sandbox
sys-apps/which
dev-lang/perl
sys-devel/libperl
sys-apps/portage
dev-lang/python

35
dpaste/dpaste.init Executable file
View File

@ -0,0 +1,35 @@
#!/sbin/runscript
# Copyright 2013 Marduk Enterprises (marduk@python.net)
# Distributed under the terms of the GNU General Public License v2
description="GUnicorn server for the dpaste app"
depend() {
need localmount
after nginx
after postgresql-9.2
}
start() {
ebegin "Starting dpaste"
. /opt/dpaste/bin/activate
export PYTHONPATH=/opt/dpaste/dpaste
start-stop-daemon --start --exec /opt/dpaste/bin/python -- /opt/dpaste/manage.py run_gunicorn \
--user=dpaste \
--daemon \
--group=dpaste \
--workers=2 \
--error-logfile=/opt/dpaste/var/gunicorn.error.log \
--pid=/opt/dpaste/var/gunicorn.pid \
--bind=unix:///opt/dpaste/var/dpaste.sock
}
stop() {
ebegin "Stopping dpaste"
start-stop-daemon --stop \
--pidfile /opt/dpaste/var/gunicorn.pid \
--exec /opt/dpaste/bin/python
eend $? "Failed to stop dpaste"
}

19
dpaste/firstboot.start Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
set -e
[ -e /firstboot ] || exit 0
echo 'Creating dpaste database'
createuser -U postgres -D -S -R dpaste
createdb -U postgres dpaste
. /opt/dpaste/bin/activate
PYTHON=/opt/dpaste/bin/python
PYTHONPATH=/opt/dpaste/dpaste ; export PYTHONPATH
$PYTHON /opt/dpaste/manage.py syncdb --noinput
$PYTHON /opt/dpaste/manage.py migrate --all
rc-update add dpaste default
/etc/init.d/dpaste start
rm /firstboot

3
dpaste/make.conf Normal file
View File

@ -0,0 +1,3 @@
# NGINX flags
NGINX_MODULES_HTTP="auth_basic gzip proxy referer rewrite headers_more uwsgi"

68
dpaste/nginx.conf Normal file
View File

@ -0,0 +1,68 @@
user nginx nginx;
worker_processes 1;
error_log /var/log/nginx/error_log info;
events {
worker_connections 1024;
use epoll;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main
'$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
client_header_timeout 10m;
client_body_timeout 10m;
send_timeout 10m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 4 2k;
request_pool_size 4k;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;
output_buffers 1 32k;
postpone_output 1460;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 75 20;
ignore_invalid_headers on;
index index.html;
upstream dpaste {
server unix:///opt/dpaste/var/dpaste.sock;
}
server {
listen 0.0.0.0;
location /static/ {
alias /opt/dpaste/dpaste/dpaste/static/;
}
location / {
proxy_pass http://dpaste;
}
access_log /var/log/nginx/dpaste.access_log main;
error_log /var/log/nginx/dpaste.error_log info;
root /var/www/localhost/htdocs;
}
}

1
dpaste/package.keywords Normal file
View File

@ -0,0 +1 @@
sys-kernel/gentoo-sources ~amd64 ~x86

11
dpaste/package.use Normal file
View File

@ -0,0 +1,11 @@
app-editors/nano ncurses
dev-lang/python ssl threads xml
dev-libs/libpcre cxx
net-misc/dhcp client
sys-apps/kmod tools
sys-devel/gcc cxx nptl
sys-kernel/gentoo-sources symlink
sys-libs/ncurses minimal
sys-apps/portage python3 ipc
net-misc/curl ssl curl_ssl_openssl
dev-vcs/git curl

151
dpaste/settings.py Normal file
View File

@ -0,0 +1,151 @@
# Django settings for dpaste project.
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'dpaste', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'dpaste',
'PASSWORD': '',
'HOST': 'localhost', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ['*']
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'UTC'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
from keyfile import SECRET_KEY
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'dpaste.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'project.wsgi.application'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.sessions',
'django.contrib.staticfiles',
'mptt',
'south',
'gunicorn',
'dpaste',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}

3
dpaste/world Normal file
View File

@ -0,0 +1,3 @@
net-misc/dhcp
dev-lang/python:2.7
www-servers/nginx