wiki:Guide4Packagers

Version 3 (modified by unbit, 4 years ago) (diff)

--

Packaging the uWSGI server

Starting from version 0.9.7, the uWSGI platform is fully modular.

Packagers should try to split all the component in various packages.

The core profile in buildconf directory will build a uWSGI server without plugins.

This server will search for plugins in the current directory. This is not very practical for a distribution package, so the first step would be defining a plugin_dir in your build profile

[uwsgi]
inherit = default
plugin_dir = /usr/lib/uwsgi
embedded_plugins = null

/usr/lib/uwsgi is a good choice for most of the os/system but feel free to change it to something better. Save the file to a new profile (buildconf/package.ini for example) and build it:

python uwsgiconfig --build package

(if you have not called the file package.ini change the --build argument)

Now we have the core server. Package it in a system path directory (/usr/bin is a good choice) and eventually add your init scripts.

Building the plugins

There are a lot of plugins available, you should make a package for each one.

The most useful example is the python one.

Python has different version available, and probably you would want to allow users to load the specific version on demand.

The objective is having all of these packages available:

uwsgi-plugin-python2.4
uwsgi-plugin-python2.5
uwsgi-plugin-python2.6
uwsgi-plugin-python2.7
uwsgi-plugin-python3.1
uwsgi-plugin-python3.2

Let's build each one

python uwsgiconfig --plugin plugins/python24 package
python uwsgiconfig --plugin plugins/python25 package
python uwsgiconfig --plugin plugins/python26 package
python uwsgiconfig --plugin plugins/python27 package
python uwsgiconfig --plugin plugins/python31 package
python uwsgiconfig --plugin plugins/python32 package

Pay attention to the last arg, it is the name of the build profile used for the core

Now in /usr/lib/uwsgi we will have the plugins. Put each one in the specific distro package

Loading plugins

The standard way for loading uwsgi plugins is using the

--plugins plugin1,plugin2,...pluginN

directive (you can put it in configuration files, ldap entry or environment variables)

But there is a 'magic' way for loading plugins.

Make a series of symbolic links to the uwsgi binary

ln -s uwsgi uwsgi_python24
ln -s uwsgi uwsgi_python25
ln -s uwsgi uwsgi_python26
ln -s uwsgi uwsgi_python27
ln -s uwsgi uwsgi_python31
ln -s uwsgi uwsgi_python32

Calling one of those symbolic links will automatically load the specific plugin

Starting apps

Probably the best way for starting apps is using the Emperor. It allows you to monitor directory for the presence of uWSGI config files and to automatically pass configuration parameters to all the instances.

A debian-like startup system could be structured like this

/etc/uwsgi
/etc/uwsgi/plugins_enabled
/etc/uwsgi/apps
#!/bin/sh
UWSGI_VASSAL_PLUGINS=""
for PLUGIN in /usr/lib/uwsgi/*
do
PLUGIN=`echo $PLUGIN | awk '{ print substr( $0, 16, length($0)-15) }'`
PLUGIN=`echo $PLUGIN | awk '{ print substr( $0, 0, length($0)-9) }'`
UWSGI_VASSAL_PLUGINS="$UWSGI_VASSAL_PLUGINS,$PLUGIN"
done

export UWSGI_VASSAL_PLUGINS
/usr/bin/uwsgi --emperor /etc/uwsgi/apps