Skip to content
This repository was archived by the owner on Jul 11, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b94c667
run adhocarcy with uwsgi instead of paster
joka Jun 19, 2013
a03f4c3
updated changelog
joka Jun 19, 2013
d293ff2
use virtualenv to create python executables, uwsgi needs this
joka Jun 19, 2013
8fda21d
improved uwsgi conf
joka Jun 19, 2013
60feb81
set LD_LIBRARY_PAT right to make PIL work
joka Jun 19, 2013
3b121e3
improved uwsgi conf
joka Jun 19, 2013
cd49610
nicer uwsgi conf
joka Jun 20, 2013
9439517
added script to open an interactive python shell with "IPDB()".
joka Jun 20, 2013
439ca1c
Merge branch 'develop' into feature_444_use_uwsgi_instead_of_paste
joka Jun 21, 2013
038bf75
Merge branch 'develop' into feature_444_use_uwsgi_instead_of_paste
joka Jun 21, 2013
b712f26
link lib and include directory instead of using virtualenv
joka Jun 24, 2013
4dc5398
cleanup
joka Jun 30, 2013
e49fd89
[build.sh] Rebuild Python if lib/ is missing
phihag Jul 1, 2013
eb4e135
Remove hardcoded path
phihag Jul 1, 2013
398038b
Fix gitignore: lib is a symlink, not a directory
phihag Jul 1, 2013
0d75019
Fix listen
phihag Jul 1, 2013
7582ed3
Fix: uwsgi process is forking off
joka Jul 2, 2013
b72920a
Cleanup linking the python binaries and lib directory
joka Jul 2, 2013
3091da4
Fix: buildout vars "etc-directory" and "var-directory" do not exists
joka Jul 2, 2013
9b16c97
Removed buildout options domains.main and ports.main
joka Jul 2, 2013
977b45e
Fix: error message when starting uwsgi
joka Jul 3, 2013
85f6388
Fix: uwsgi recompiles all the time
joka Jul 3, 2013
88d0937
compile uwsgi without xml support to remove the libxml dependency
joka Jul 3, 2013
92ad97a
updated uwsgi to 1.9.13 to enable support of
joka Jul 3, 2013
fd03c1c
Fix: uwsgi start script does not run mit 'bin/sh'
joka Jul 3, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ parts
bin
local
/src/*_theme
/lib
lib64
eggs
develop-eggs
Expand Down
13 changes: 13 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ adhocracy Changelog
1.2beta2dev
-----------

- link python lib and inclue directories, uwsgi needs this.

Upgrade manual installation:
____________________________

* cd python
* bin/buildout
* cd ..
* bin/buildout

- run adhocarcy with uwsgi instead of paster to improve performance,
for development keep with paster [joka]

- added varnish reverse proxy [joka]

- Readd bin/test to run tests (wrapper for py.test) [joka]
Expand Down
15 changes: 12 additions & 3 deletions INSTALLATION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ Check out Adhocracy:

$ git clone https://github.com/liqd/adhocracy
$ cd adhocracy

$ git submodule init
$ git submodule update

## Setup an isolated python environment to run Adhocracy

To install Adhocracy you need python (2.6|2.7) with PIL (python imaging) but
To install Adhocracy you need python (2.6|2.7) with PIL (python imaging) but
no other system-packages.

Compile python and PIL with the included python buildout::
Expand All @@ -92,7 +92,7 @@ Run buildout:

::

$ bin/python bootstrap.py
$ bin/python bootstrap.py
$ bin/buildout

Start Adhocracy and dependent servers:
Expand All @@ -109,6 +109,7 @@ have to setup the Adhocracy database manually:

$ bin/paster setup-app etc/adhocracy.ini --name=content


Run Adhocracy
-------------

Expand Down Expand Up @@ -143,6 +144,14 @@ Start the Adhocracy server in foreground mode:
$ bin/supervisorctl stop adhocracy
$ bin/paster serve etc/adhocracy.ini

To run adhocarcy with uwsgi instead of paster:

::
$ bin/uwsgi --ini-paste etc/adhocracy.ini

To run the ipdb python debuger with uwsgi use "IPDB()" instead of "ipdb.set_trace()".


Buildout configuration
----------------------

Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ if [ '!' -e python/buildout.python/src ]; then
fi

# Install local python if necessary
if [ '!' -x bin/python ]; then
if [ '!' -x bin/python ] || [ '!' -e lib ]; then
if [ '!' -f python/bin/buildout ]; then
(cd python && python bootstrap.py)
fi
Expand Down
1 change: 1 addition & 0 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extends =
buildouts/base.cfg
buildouts/lxml.cfg
buildouts/adhocracy.cfg
buildouts/uwsgi.cfg
# buildouts/adhocracy_theming.cfg
buildouts/stylesheets.cfg
buildouts/memcache.cfg
Expand Down
5 changes: 3 additions & 2 deletions buildouts/adhocracy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,19 @@ command =

# python with all required eggs
[adhocpy]
recipe = zc.recipe.egg
recipe = minitage.recipe.scripts
eggs = ${buildout:eggs}
extra-paths = ./
interpreter = adhocpy
scripts = adhocpy
env-file = ${buildout:bin-directory}/adhocpy-env

##############################################################################
# Set up supervisor to run it all
##############################################################################

[supervisor]
environment = LD_LIBRARY_PATH="${buildout:directory}/python/python-2.7/lib/"
environment = LD_LIBRARY_PATH="${buildout:directory}/lib/"
programs +=
${buildout:adhocracy_worker-supervisor}
${buildout:adhocracy-supervisor}
115 changes: 115 additions & 0 deletions buildouts/uwsgi.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
##############################################################################
# Buildout to install uwsgi https://github.com/unbit/uwsgi
#
# requires:
#
# - bin/adhocracpy-env to set the PYTHONPATH variable
#
##############################################################################

[buildout]

parts +=
uwsgi
uwsgi_bin

adhocracy-supervisor =
45 adhocracy (environment=${supervisor:environment} stopsignal=INT redirect_stderr=true stdout_logfile=var/log/adhocracy.log stderr_logfile=NONE) ${buildout:bin-directory}/uwsgi [--ini-paste ${buildout:directory}/etc/adhocracy.ini]

##############################################################################
# System settings
##############################################################################

[domains]
uwsgi = 127.0.0.1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these two entries used anywhere? It seems like we're simply using {main:port} (as we should)


[ports]
uwsgi = 5008

[urls]
uwsgi = http://projects.unbit.it/downloads/uwsgi-1.9.12.tar.gz

###############################
# Install and configure uwsgi #
###############################

# compile options
[uwsgi_build_conf]
recipe = collective.recipe.template
output = ${buildout:etc-directory}/uwsgi_buildconf.ini
input = ${buildout:etc-directory}/uwsgi_buildconf.ini.in
bin-name = ${buildout:bin-directory}/uwsgi
plugin-dir = ${buildout:var-directory}/uwsgi_plugins
main-plugin = python, gevent

[uwsgi_build_env]
UWSGI_PROFILE = ${uwsgi_build_profile:output}
PYTHONHOME = ${buildout:directory}

# compile egg
[uwsgi]
recipe = minitage.recipe.du
url = ${urls:uwsgi}
eggs =
${buildout:eggs}
uwsgi
environment = uwsgi_build_env

# uwsgi bin
[uwsgi_bin]
recipe = collective.recipe.template
output = ${buildout:bin-directory}/uwsgi
input = inline:
#!/bin/bash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be /bin/sh - the file is not dependent on bash at all, or is it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be /bin/sh - the file is not dependent on bash at all, or is it?

its not working with sh.

source ${adhocpy:env-file}
${buildout:parts-directory}/uwsgi/bin/uwsgi "$@"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we forking off uwsgi here? I'd rather not do that, since the original (bash) process doesn't serve any role.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we fork here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the line marked with this comment!? Every command you type in a shell gets forked off unless it's built-in, so bash keeps running while uwsgi is serving. If that's not intentional, we should prepend the line with exec to prevent the forking.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! I wasn't aware of the forking. Replacing the shell process is indeed better. Thanks for the explanation.

mode = 755

# configure
[uwsgi_conf]
conf =
#basics

http = ${adhocracy:host}:${ports:main}
pidfile = ${buildout:directory}/var/uwsgi.pid
master = true
chdir = ${buildout:directory}/src
home = ${buildout:directory}

# extended

# Reload if ini changes
touch-reload = true
# stop uwsgi if the wsgi app is not available
need-app = true
# allow threads
enable-threads = true
#Set close-on-exec on sockets (could be required for spawning processes in requests).
close-on-exec = true
#Automatically kill workers if master dies (can be dangerous for availability).
no-orphans = true
# Try to remove all of the generated files/sockets (UNIX sockets and pidfiles) upon exit.
vacuum = true

#performance tuning

processes = 1
worker = 20
post-buffering = 4096
max-requests = 1000
# Reload a worker if its address space usage is higher than the specified value (in megabytes).
reload-on-as = 128
#gracefull dead
harakiri = 60
harakiri-verbose = true

#logging

log-date = true
log-slow = true

# debug

# IPDB(); opens python shell
shared-import = ${buildout:directory}/scripts/interact.py
# memory-report = true
7 changes: 4 additions & 3 deletions etc/adhocracy.ini.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
##############################################################

[DEFAULT]
{% if parts.adhocracy.debug == 'True' %}debug = True {% end %}
{% if parts.adhocracy.debug != 'True' %}debug = False {% end %}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this related to uwsgi?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug flag does not work with mutliprocess WSGI-servers such as uwsgi

# Uncomment and replace with the address which should receive any error reports
email_to = ${parts.adhocracy['email.to']}
Expand All @@ -24,7 +22,10 @@ port = ${parts.ports.main}
{% if parts.adhocracy.debug != 'True' %}use_threadpool = True {% end %}
threadpool_workers = 20


{% if "uwsgi_conf" in parts %}
[uwsgi]
${parts.uwsgi_conf.conf}
{% end %}

{% if parts.adhocracy.themed == 'False' %}
###################not themed adhocracy ###################
Expand Down
50 changes: 50 additions & 0 deletions etc/uwsgi_buildconf.ini.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
; this is mainly copied from the uwsgi buildconf/default.ini
; trying to surface some of the build options to buildout
; properties.
[uwsgi]
bin_name = ${:bin-name}
plugin_dir = ${:plugin-dir}
main_plugin = ${:main-plugin}
xml = true
ini = true
yaml = true
json = auto
sqlite3 = auto
zeromq = auto
snmp = true
spooler = true
embedded = true
ssl = auto
udp = true
multicast = true
threading = true
minterpreters = true
async = true
ldap = auto
pcre = auto
routing = auto
alarm = auto
ipv6 = false
debug = false
unbit = false
xml_implementation = libxml2
yaml_implementation = auto
malloc_implementation = libc
extras =
plugins =
append_version =
embedded_plugins = %(main_plugin)s, ping, cache, nagios, rrdtool, carbon, rpc, corerouter, fastrouter, http, ugreen, signal, syslog, rsyslog, logsocket, router_uwsgi, router_redirect, router_basicauth, zergpool, redislog, mongodblog, router_rewrite, router_http, logfile, router_cache, rawrouter
as_shared_library = false

locking = auto
event = auto
timer = auto
filemonitor = auto

blacklist =
whitelist =

embed_files =

embed_config =

27 changes: 21 additions & 6 deletions python/buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,34 @@ parts =
${buildout:links-parts}

python-buildout-root = ${buildout:directory}/buildout.python/src
pil-install-args = Pillow==2.0.0
pil-install-args = Pillow==2.0


[install-links]
recipe = plone.recipe.command
prefix = ${buildout:directory}/..
command =
command =
#!/bin/sh
mkdir -p ${install-links:prefix}/bin/

# remove exiting links
rm ${:prefix}/bin/python
for i in $(ls ${:prefix}/bin/*[23].*); do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really unstable. Why do we need to remove the files in the first place? And why can't we match python* here?

rm $i;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like in Python, semi-colons are not required here or in the lines below

done
rm ${:prefix}/include;
rm ${:prefix}/lib;

#Symlink default python (2.7)
DEST=${install-links:prefix}/bin/python;
ln -vfs ${buildout:directory}/python-2.7/bin/python2.7 $DEST;
update-command = ${:command}
# Symlink include, lib directory, uwsgi needs this there
ln -s ${buildout:directory}/python-2.7/include ${:prefix}/include
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also pass in the -f and -T options here, since we're symlinking a directory. In fact, is that the rationale for the rms above? If so, just adding -fT and removing the rms will suffice.

ln -s ${buildout:directory}/python-2.7/lib ${:prefix}/lib

# Symlink python, easy_install
for i in $(ls ${buildout:directory}/python-[23].*/bin/*[23].*); do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using ls here? Can't we just remove that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2013/7/1 Philipp Hagemeister notifications@github.com

In python/buildout.cfg:

  • Symlink python, easy_install

  • for i in $(ls ${buildout:directory}/python-[23]./bin/[23].*); do

Why are we using ls here? Can't we just remove that?

somentimes I need virtualenv-2.7, pip-27, easyinstall-27 or python-2.7


Reply to this email directly or view it on GitHubhttps://github.com//pull/471/files#r4955280
.

Joscha Krutzki • IT Consulting Python Webdevelopment Hosting
Wrangelstraße 48
10997 Berlin
mobil: +4915161403689
jabber: krutzki@gmail.com
www.jokasis.de
gpg --recv-keys --keyserver hkp://subkeys.pgp.net 1BAC2541

DEST=${:prefix}/bin/`basename $i`;
ln -s $i $DEST;
done
ln -s ${:prefix}/bin/python2.7 ${:prefix}/bin/python


update-command = ${:command}
31 changes: 31 additions & 0 deletions scripts/interact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""uwsgi development helpers: open interactive python shells"""
import os
import sys
import inspect
import code


class RestoredStandardInputContext(object):

def __enter__(self):
self.backup_stdin = os.dup(sys.stdin.fileno())
os.dup2(sys.stdout.fileno(), sys.stdin.fileno())

def __exit__(self, error_type, error, traceback):
os.dup2(self.backup_stdin, sys.stdin.fileno())


def interact(locals=None, plain=False):

with RestoredStandardInputContext():
code.interact(local=locals or inspect.currentframe().f_back.f_locals)


def interact_ipdb():

with RestoredStandardInputContext():
import ipdb
ipdb.set_trace()

__builtins__['PDB'] = interact
__builtins__['IPDB'] = interact_ipdb