This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""Hacks to work around API inconsistencies between Archetypes and Dexterity.""" | |
def set_image_field(obj, image, content_type): | |
"""Set image field in object on both, Archetypes and Dexterity.""" | |
from plone.namedfile.file import NamedBlobImage | |
try: | |
obj.setImage(image) # Archetypes | |
except AttributeError: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from plone import api | |
from zope.component.hooks import setSite | |
import transaction | |
def spoof_request(app): | |
from AccessControl.SecurityManagement import newSecurityManager | |
from AccessControl.SecurityManager import setSecurityPolicy | |
from Testing.makerequest import makerequest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configuration file for varnish | |
# | |
# /etc/init.d/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK | |
# to be set from this shell script fragment. | |
# | |
# This file should be symlinked to /etc/default/varnish | |
# Should we start varnishd at boot? Set to "no" to disable. | |
START=yes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# VCL configuration file for Varnish. It defines 2 backends, one for | |
# each Plone instance, and uses hash load balancing. | |
# | |
# This file must me symlinked to /etc/varnish/default.vcl | |
vcl 4.0; | |
import directors; | |
import std; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configuration file for nginx | |
# | |
# This file must me symlinked to /etc/nginx/nginx.conf | |
user www-data; | |
worker_processes auto; | |
pid /run/nginx.pid; | |
events { | |
worker_connections 4096; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configuration file for nginx | |
# | |
# This file must me symlinked to /etc/nginx/sites-enabled/default | |
upstream plone { | |
server localhost:8081; | |
server localhost:8082; | |
} | |
server { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# need to change permission access to /etc/varnish/secret | |
[restart] | |
recipe = collective.recipe.template | |
input = inline: | |
#!/bin/bash | |
for i in {1..4} | |
do | |
varnishadm backend.set_health instance$i sick | |
${buildout:bin-directory}/supervisorctl restart app:instance$i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[buildout] | |
parts += | |
supervisor | |
supervisor-cron | |
[supervisor] | |
recipe = collective.recipe.supervisor | |
plugins = superlance | |
user = admin | |
password = admin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get total requests by status code | |
awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | |
# get top requesters by IP | |
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head | awk -v OFS='\t' '{"host " $2 | getline ip; print $0, ip}' | |
# get top requesters by user agent | |
awk -F'"' '{print $6}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head | |
# get top requests by URL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextlib | |
@contextlib.contextmanager | |
def capture(): | |
"""A context manager to capture stdout and stderr. | |
http://stackoverflow.com/a/10743550/644075 | |
""" | |
import sys | |
from cStringIO import StringIO |