1
0
mirror of https://github.com/Tygs/0bin.git synced 2023-08-10 21:13:00 +03:00

Documentation is now exhaustive and zerobin is apache friendly

This commit is contained in:
sam 2012-05-18 22:18:40 +02:00
parent 97935e51d3
commit a3dcbe9c2b
40 changed files with 1100 additions and 149 deletions

Binary file not shown.

View File

@ -2,8 +2,7 @@
Apache setup Apache setup
============= =============
Apache is slower, heavier and more complicated to setup than Nginx. But it's also Apache is heavier than Nginx. But it's also much more famous:
much more famous:
- more people will be able to help you on forums; - more people will be able to help you on forums;
- your hosting will most probably support Apache; - your hosting will most probably support Apache;
@ -33,7 +32,65 @@ the setup of the Apache module mod_wsgi. If you don't know how to do this, or
if you can't do it (E.G: your hosting won't let you), you need to go for if you can't do it (E.G: your hosting won't let you), you need to go for
the CGI setup. the CGI setup.
========== First, make sure you have mod_wsgi installed and enable by running (as admin)::
This setup is considered as slow, but you will still benefit from Apache a2enmod wsgi
robustness.
This enable mod_wsgi. It it doesn't, install it first (on ubuntu, the package
is libapache2-mod-wsgi).
Then create an Apache configuration file, usually in /etc/apache/sites-available/.
Name it zerobin::
<VirtualHost *:80>
ServerName www.yourwebsite.com
WSGIDaemonProcess zerobin user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias / /path/to/zerobin/app.wsgi
<Directory /path/to/zerobin/zerobin/>
WSGIProcessGroup zerobin
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Activate the website (as admin)::
a2ensite zerobin
And reload the apache configuration (as admin)::
service apache2 reload
You'll note that we refer to a file named app.wsgi. It's a Python file
creating the application Apache is going to use to start the Python process::
import os, sys
# make sure the zerobin module is in the PYTHON PATH and importable
ZEROBIN_PARENT_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, ZEROBIN_PARENT_DIR)
# create the wsgi callable
from zerobin.routes import get_app
settings, application = get_app(compressed_static=True)
You can of course create your own, as the `get_app` function is the only
way to pass settings to 0bin with this setup. You would do this by creating
a configuration file and passing it to the function::
import os, sys
ZEROBIN_PARENT_DIR = '/path/to/zerobin/parent/dir'
sys.path.insert(0, ZEROBIN_PARENT_DIR)
from zerobin.routes import get_app
settings, application = get_app(settings_file='/path/to/settings.py')
CGI
===
You can also run 0bin using CGI, but infortunaly we didn't have time to cover
it yet. Please contact us if you ever get the need to use it.

View File

@ -51,9 +51,51 @@ installing it.
Vous must create a Nginx configuration file for 0bin. On GNU/Linux, they usually Vous must create a Nginx configuration file for 0bin. On GNU/Linux, they usually
go into /etc/nginx/conf.d/. Name it zerobin.conf. go into /etc/nginx/conf.d/. Name it zerobin.conf.
The minimal file to run the site is: The minimal configuration file to run the site is::
But you can make some adjustement to get better perfomances: server {
listen 80;
server_name www.yourwebsite.com;
location / {
proxy_pass http://127.0.0.1:8000;
}
}
`proxy_pass` just passes the external request to the Python process.
The port much match the one used by the 0bin process of course.
You can make some adjustements to get a better user experience::
server {
listen 80;
server_name www.yourwebsite.com;
location /favicon.ico {
root /path/to/zerobin/static/img;
}
location /static/ {
root /path/to/zerobin;
gzip on;
gzip_http_version 1.0;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
# Disable gzip for certain browsers.
gzip_disable ~@~\MSIE [1-6].(?!.*SV1)~@~];
expires modified +90d;
}
location / {
proxy_pass http://zerobin_cherrypy;
}
}
This make Nginx serve the favicon and static files, set the expire HTTP headers
and make sure gzip compression is used with browsers that support it.

View File

@ -1,15 +1,3 @@
--host=STR
The host on which to listen for incomming request. Usually 127.0.0.1 to
listen locally or 0.0.0.0 to listen from the outside.
Default: 127.0.0.1
Setting file : HOST
============ ============
Options Options
============ ============

View File

@ -2,9 +2,9 @@
Theming Theming
======= =======
0bin comes a complete theming support, but for now it's not well ingrated. 0bin comes with a complete theming support, but for now it's not well integrated.
If you wish to create your own theme, you'll need to create template similar If you wish to create your own theme, you'll need to create templates similar
to the ones in zerobin/view, and add the path to the director containing them to the ones in zerobin/view, and add the path to the director containing them
to the settings file. to the settings file.

View File

@ -1,3 +1,72 @@
==================== =================
Using supervisor Using supervisor
==================== =================
Supervisor is a very nice way to manage you Python processes. We won't cover
the setup (which is just apt-get install supervisor or pip install supervisor
most of the time), but here is a quick overview on how to use it.
Create a configuration file named supervisor.ini::
[unix_http_server]
file=/tmp/supervisor.sock;
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock;
[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
[supervisord]
logfile=/tmp/zerobin.log
logfile_maxbytes=50MB
logfile_backups=2
loglevel=trace
pidfile=/tmp/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200
user=zerobin
[program:zerobin]
command=/path/to/zerobin/zerobin.py --port 80 --compressed-static
directory=/path/to/zerobin/
environment=PYTHONPATH='/path/to/zerobin/'
user=zerobin
autostart=true
autorestart=true
The 4 first entries are just boiler plate to get you started, you can copy
them verbatim.
The last one define one (you can have many) process supervisor should manage.
It means it will run the command::
/path/to/zerobin/zerobin.py --port 80 --compressed-static
In the directory, with the environnement and the user you defined.
This command will be ran as a daemon, in the background.
`autostart` and `autorestart` just make it fire and forget: the site will always be
running, even it crashes temporarly or if you retart the machine.
The first time you run supervisor, pass it the configuration file::
supervisord -c /path/to/supervisor.ini
Then you can manage the process by running::
supervisorctl -c /path/to/supervisor.ini
It will start a shell from were you can start/stop/restart the service
You can read all errors that might occurs from /tmp/zerobin.log.
.. Note::
If you installed zerobin in a virtualenv, you may set the command
to run directly from it::
command=/path/to/virtualenv/bin/zerobin --port 80 --compressed-static

View File

@ -2,8 +2,7 @@
Installation avec Apache Installation avec Apache
========================= =========================
Apache est plus lent, plus lourd, et plus complexe à mettre en oeuvre que Nginx. Apache est plus lourd que Nginx mais il est aussi beaucoup plus connu:
Mais il est aussi beaucoup plus connu:
- plus de gens pourront vous aider les fora; - plus de gens pourront vous aider les fora;
- votre hébergeur propose surement Apache; - votre hébergeur propose surement Apache;
@ -34,9 +33,67 @@ l'installation du modle Apache mod_wsgi. Si vous ne savez pas comment faire,
ou si vous ne pouvez pas le faire (par exemple sur un hébergement mutualisé ou si vous ne pouvez pas le faire (par exemple sur un hébergement mutualisé
qui ne le propose pas), il vous faudra choisir l'installation CGI. qui ne le propose pas), il vous faudra choisir l'installation CGI.
Premièrement, assurez-vous d'avoir mod_wsgi installé et chargé (en tant qu'admin)::
Mod_CGI a2enmod wsgi
==========
Ceci va activer mod_wsgi. Si cela ne marche pas, il faudra l'installer d'abord (
sur ubuntu, le paquet est libapache2-mod-wsgi)
Ensuite, il faut créer un fichier de configuration Apache, généralement dans
/etc/apache/sites-available/. Nommez le zerobin::
<VirtualHost *:80>
ServerName www.votersiteweb.com
WSGIDaemonProcess zerobin user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias / /chemin/vers/zerobin/app.wsgi
<Directory /chemin/vers/zerobin/>
WSGIProcessGroup zerobin
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Activez le site web (en tant qu'admin)::
a2ensite zerobin
Et rechargez la configuration d'Apache (en tant qu'admin)::
service apache2 reload
Vous aurez noté que l'on fait référence à un fichier nommé app.wsgi. C'est un
fichier Python qui créé l'application qu'Apache va utiliser pour lancer le
processus Python::
import os, sys
# s'assurer que le module zerobin est dans le PYTHON PATH et importable
ZEROBIN_PARENT_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, ZEROBIN_PARENT_DIR)
# créer le wsgi callable
from zerobin.routes import get_app
settings, application = get_app(compressed_static=True)
Vous pouvez bien sûr créer le votre, puisque la fonction `get_app` et le seul
moyen de passer des paramètres à 0bin avec cette installation. Cela peut se
faire en créant un fichier de configuration et en le passant à la fonction::
import os, sys
ZEROBIN_PARENT_DIR = '/chemin/du/dossier/parent/de/zerobin'
sys.path.insert(0, ZEROBIN_PARENT_DIR)
from zerobin.routes import get_app
settings, application = get_app(settings_file='/path/to/settings.py')
CGI
===
Vous pouvez aussi utiliser CGI, mais nous n'avons pas encore eu le temps de
couvrir cette partie. Contactez nous si vous avez besoin de l'utiliser.
Cette installation est considérée comme relativement lente. Mais vous bénéficierez
tout de même de la robustesse d'Apache

View File

@ -55,10 +55,53 @@ nous ne couvrirons pas cette partie.
Vous devez créer une fichier de configuration Nginx pour 0bin. Sous GNU/Linux, Vous devez créer une fichier de configuration Nginx pour 0bin. Sous GNU/Linux,
on les mets en général dans /etc/nginx/conf.d/. Nommez le zerobin.conf. on les mets en général dans /etc/nginx/conf.d/. Nommez le zerobin.conf.
Le fichier minimal pour faire tourner le site est: Le fichier de configuration minimal pour faire tourner le site est::
Mais on peut apporter plusieurs améliorations de performance:
server {
listen 80;
server_name www.votresiteweb.com;
location / {
proxy_pass http://127.0.0.1:8000;
}
}
`proxy_pass` transmet les requêtes aux processus Python. Bien entendu le
port doit correspondre à celui utilisé par 0bin.
On peut apporter plusieurs améliorations à l'expérience utilisateur::
server {
listen 80;
server_name www.votresiteweb.com;
location /favicon.ico {
root /chemin/vers/zerobin/static/img;
}
location /static/ {
root /chemin/vers/zerobin;
gzip on;
gzip_http_version 1.0;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
# Disable gzip for certain browsers.
gzip_disable ~@~\MSIE [1-6].(?!.*SV1)~@~];
expires modified +90d;
}
location / {
proxy_pass http://zerobin_cherrypy;
}
}
Nginx sert maintenant le favicon ainsi que les fichiers statiques,
on a ajouté une date d'expiration dans les en-têtes HTTP
et on s'assure que la compression gzip est utilisée pour les navigateurs
qui la supporte.

View File

@ -1,3 +1,75 @@
==================== ====================
Utiliser supervisor Utiliser supervisor
==================== ====================
Supervisor est un très bon moyen de gérer des processus Python. Nous n'allons
pas couvrir son installation (qui la plupart du temps se résume à
apt-get install supervisor ou pip install supervisor), mais voici un rapide
résumé de comment l'utiliser:
Créez un fichier de configuration nommé supervisor.ini::
[unix_http_server]
file=/tmp/supervisor.sock;
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock;
[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
[supervisord]
logfile=/tmp/zerobin.log
logfile_maxbytes=50MB
logfile_backups=2
loglevel=trace
pidfile=/tmp/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200
user=zerobin
[program:zerobin]
command=/chemin/vers/zerobin/zerobin.py --port 80 --compressed-static
directory=/chemin/vers/zerobin/
environment=PYTHONPATH='/chemin/vers/zerobin/'
user=zerobin
autostart=true
autorestart=true
Les 4 premières entrées sont juste de la configuration standard et vous pouvez
les copier telles qu'elles.
La dernière entrée définie un processus (il peut y en avoir plusieurs)
que supervisor doit gérer.
Cela veut dire qu'il va lancer la commande::
/chemin/vers/zerobin/zerobin.py --port 80 --compressed-static
Et ceci dans le dossier, avec l'environnement et l'utilisateur défini, le tout
en arrière plan en tant que daemon.
`autostart` et `autorestart` permettent simplement de le lancer et de l'oublier:
supervisor redémarera le processus automatiquement en cas d'arrêt impromptu.
La première fois que vous lancez supervisor, passez lui le fichier de configuration::
supervisord -c /chemin/vers/supervisor.ini
Ensuite vous pouvez gérer les processus avec::
supervisorctl -c /chemin/vers/supervisor.ini
Cela va démarrer un shell depuis lequel vous pouvez faire un start/stop/restart
sur le service.
Toutes les erreurs seront logguées dans /tmp/zerobin.log.
.. Note::
Si vous avez installé zerobin dans un virtualenv, vous devriez définir la
commande pour qu'elle s'éxécute depuis le virtualenv::
command=/chemin/vers/le/virtualenv/bin/zerobin --port 80 --compressed-static

View File

@ -27,12 +27,5 @@
+-------------------------+--------------------------------+ +-------------------------+--------------------------------+
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
.. _Signaler un bug: https://github.com/sametmax/0bin/issues .. _Signaler un bug: https://github.com/sametmax/0bin/issues
.. _Report a bug: <https://github.com/sametmax/0bin/issues> .. _Report a bug: <https://github.com/sametmax/0bin/issues>

View File

@ -53,8 +53,7 @@
<div class="section" id="apache-setup"> <div class="section" id="apache-setup">
<h1>Apache setup<a class="headerlink" href="#apache-setup" title="Permalink to this headline"></a></h1> <h1>Apache setup<a class="headerlink" href="#apache-setup" title="Permalink to this headline"></a></h1>
<p>Apache is slower, heavier and more complicated to setup than Nginx. But it&#8217;s also <p>Apache is heavier than Nginx. But it&#8217;s also much more famous:</p>
much more famous:</p>
<ul class="simple"> <ul class="simple">
<li>more people will be able to help you on forums;</li> <li>more people will be able to help you on forums;</li>
<li>your hosting will most probably support Apache;</li> <li>your hosting will most probably support Apache;</li>
@ -79,9 +78,63 @@ interfacing: WSGI.</p>
the setup of the Apache module mod_wsgi. If you don&#8217;t know how to do this, or the setup of the Apache module mod_wsgi. If you don&#8217;t know how to do this, or
if you can&#8217;t do it (E.G: your hosting won&#8217;t let you), you need to go for if you can&#8217;t do it (E.G: your hosting won&#8217;t let you), you need to go for
the CGI setup.</p> the CGI setup.</p>
<hr class="docutils" /> <p>First, make sure you have mod_wsgi installed and enable by running (as admin):</p>
<p>This setup is considered as slow, but you will still benefit from Apache <div class="highlight-python"><pre>a2enmod wsgi</pre>
robustness.</p> </div>
<p>This enable mod_wsgi. It it doesn&#8217;t, install it first (on ubuntu, the package
is libapache2-mod-wsgi).</p>
<p>Then create an Apache configuration file, usually in /etc/apache/sites-available/.
Name it zerobin:</p>
<div class="highlight-python"><pre>&lt;VirtualHost *:80&gt;
ServerName www.yourwebsite.com
WSGIDaemonProcess zerobin user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias / /path/to/zerobin/app.wsgi
&lt;Directory /path/to/zerobin/zerobin/&gt;
WSGIProcessGroup zerobin
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
&lt;/Directory&gt;
&lt;/VirtualHost&gt;</pre>
</div>
<p>Activate the website (as admin):</p>
<div class="highlight-python"><pre>a2ensite zerobin</pre>
</div>
<p>And reload the apache configuration (as admin):</p>
<div class="highlight-python"><pre>service apache2 reload</pre>
</div>
<p>You&#8217;ll note that we refer to a file named app.wsgi. It&#8217;s a Python file
creating the application Apache is going to use to start the Python process:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">sys</span>
<span class="c"># make sure the zerobin module is in the PYTHON PATH and importable</span>
<span class="n">ZEROBIN_PARENT_DIR</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">__file__</span><span class="p">))</span>
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">ZEROBIN_PARENT_DIR</span><span class="p">)</span>
<span class="c"># create the wsgi callable</span>
<span class="kn">from</span> <span class="nn">zerobin.routes</span> <span class="kn">import</span> <span class="n">get_app</span>
<span class="n">settings</span><span class="p">,</span> <span class="n">application</span> <span class="o">=</span> <span class="n">get_app</span><span class="p">(</span><span class="n">compressed_static</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
<p>You can of course create your own, as the <cite>get_app</cite> function is the only
way to pass settings to 0bin with this setup. You would do this by creating
a configuration file and passing it to the function:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">sys</span>
<span class="n">ZEROBIN_PARENT_DIR</span> <span class="o">=</span> <span class="s">&#39;/path/to/zerobin/parent/dir&#39;</span>
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">ZEROBIN_PARENT_DIR</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">zerobin.routes</span> <span class="kn">import</span> <span class="n">get_app</span>
<span class="n">settings</span><span class="p">,</span> <span class="n">application</span> <span class="o">=</span> <span class="n">get_app</span><span class="p">(</span><span class="n">settings_file</span><span class="o">=</span><span class="s">&#39;/path/to/settings.py&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="cgi">
<h2>CGI<a class="headerlink" href="#cgi" title="Permalink to this headline"></a></h2>
<p>You can also run 0bin using CGI, but infortunaly we didn&#8217;t have time to cover
it yet. Please contact us if you ever get the need to use it.</p>
</div> </div>
</div> </div>
@ -95,6 +148,7 @@ robustness.</p>
<ul> <ul>
<li><a class="reference internal" href="#">Apache setup</a><ul> <li><a class="reference internal" href="#">Apache setup</a><ul>
<li><a class="reference internal" href="#mod-wsgi">Mod_wsgi</a></li> <li><a class="reference internal" href="#mod-wsgi">Mod_wsgi</a></li>
<li><a class="reference internal" href="#cgi">CGI</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@ -95,8 +95,48 @@ separate process let you do this without having to restart the server.</p>
installing it.</p> installing it.</p>
<p>Vous must create a Nginx configuration file for 0bin. On GNU/Linux, they usually <p>Vous must create a Nginx configuration file for 0bin. On GNU/Linux, they usually
go into /etc/nginx/conf.d/. Name it zerobin.conf.</p> go into /etc/nginx/conf.d/. Name it zerobin.conf.</p>
<p>The minimal file to run the site is:</p> <p>The minimal configuration file to run the site is:</p>
<p>But you can make some adjustement to get better perfomances:</p> <div class="highlight-python"><pre>server {
listen 80;
server_name www.yourwebsite.com;
location / {
proxy_pass http://127.0.0.1:8000;
}
}</pre>
</div>
<p><cite>proxy_pass</cite> just passes the external request to the Python process.
The port much match the one used by the 0bin process of course.</p>
<p>You can make some adjustements to get a better user experience:</p>
<div class="highlight-python"><pre>server {
listen 80;
server_name www.yourwebsite.com;
location /favicon.ico {
root /path/to/zerobin/static/img;
}
location /static/ {
root /path/to/zerobin;
gzip on;
gzip_http_version 1.0;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
# Disable gzip for certain browsers.
gzip_disable ~@~\MSIE [1-6].(?!.*SV1)~@~];
expires modified +90d;
}
location / {
proxy_pass http://zerobin_cherrypy;
}
}</pre>
</div>
<p>This make Nginx serve the favicon and static files, set the expire HTTP headers
and make sure gzip compression is used with browsers that support it.</p>
</div> </div>
</div> </div>

View File

@ -51,12 +51,7 @@
<div class="bodywrapper"> <div class="bodywrapper">
<div class="body"> <div class="body">
<p>&#8211;host=STR</p> <div class="section" id="options">
<p>The host on which to listen for incomming request. Usually 127.0.0.1 to
listen locally or 0.0.0.0 to listen from the outside.</p>
<p>Default: 127.0.0.1
Setting file : HOST</p>
<div class="section" id="options">
<h1>Options<a class="headerlink" href="#options" title="Permalink to this headline"></a></h1> <h1>Options<a class="headerlink" href="#options" title="Permalink to this headline"></a></h1>
<p>0bin&#8217;s behavior can be adjusted with options passed using a configuration <p>0bin&#8217;s behavior can be adjusted with options passed using a configuration
file or directly using the command line. Some parameters are only available file or directly using the command line. Some parameters are only available

View File

@ -53,8 +53,8 @@
<div class="section" id="theming"> <div class="section" id="theming">
<h1>Theming<a class="headerlink" href="#theming" title="Permalink to this headline"></a></h1> <h1>Theming<a class="headerlink" href="#theming" title="Permalink to this headline"></a></h1>
<p>0bin comes a complete theming support, but for now it&#8217;s not well ingrated.</p> <p>0bin comes with a complete theming support, but for now it&#8217;s not well integrated.</p>
<p>If you wish to create your own theme, you&#8217;ll need to create template similar <p>If you wish to create your own theme, you&#8217;ll need to create templates similar
to the ones in zerobin/view, and add the path to the director containing them to the ones in zerobin/view, and add the path to the director containing them
to the settings file.</p> to the settings file.</p>
<p>You&#8217;ll also need to copy static files from zerobin/static to a new direcotry <p>You&#8217;ll also need to copy static files from zerobin/static to a new direcotry

View File

@ -26,8 +26,8 @@
<script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="0bin 0.1 documentation" href="../index.html" /> <link rel="top" title="0bin 0.1 documentation" href="../index.html" />
<link rel="next" title="&lt;no title&gt;" href="theming.html" /> <link rel="next" title="Theming" href="theming.html" />
<link rel="prev" title="Installing with Nginx" href="nginx_install.html" /> <link rel="prev" title="Nginx setup" href="nginx_install.html" />
</head> </head>
<body> <body>
<div class="related"> <div class="related">
@ -37,10 +37,10 @@
<a href="../genindex.html" title="General Index" <a href="../genindex.html" title="General Index"
accesskey="I">index</a></li> accesskey="I">index</a></li>
<li class="right" > <li class="right" >
<a href="theming.html" title="&lt;no title&gt;" <a href="theming.html" title="Theming"
accesskey="N">next</a> |</li> accesskey="N">next</a> |</li>
<li class="right" > <li class="right" >
<a href="nginx_install.html" title="Installing with Nginx" <a href="nginx_install.html" title="Nginx setup"
accesskey="P">previous</a> |</li> accesskey="P">previous</a> |</li>
<li><a href="../index.html">0bin 0.1 documentation</a> &raquo;</li> <li><a href="../index.html">0bin 0.1 documentation</a> &raquo;</li>
</ul> </ul>
@ -53,6 +53,65 @@
<div class="section" id="using-supervisor"> <div class="section" id="using-supervisor">
<h1>Using supervisor<a class="headerlink" href="#using-supervisor" title="Permalink to this headline"></a></h1> <h1>Using supervisor<a class="headerlink" href="#using-supervisor" title="Permalink to this headline"></a></h1>
<p>Supervisor is a very nice way to manage you Python processes. We won&#8217;t cover
the setup (which is just apt-get install supervisor or pip install supervisor
most of the time), but here is a quick overview on how to use it.</p>
<p>Create a configuration file named supervisor.ini:</p>
<div class="highlight-python"><pre>[unix_http_server]
file=/tmp/supervisor.sock;
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock;
[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
[supervisord]
logfile=/tmp/zerobin.log
logfile_maxbytes=50MB
logfile_backups=2
loglevel=trace
pidfile=/tmp/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200
user=zerobin
[program:zerobin]
command=/path/to/zerobin/zerobin.py --port 80 --compressed-static
directory=/path/to/zerobin/
environment=PYTHONPATH='/path/to/zerobin/'
user=zerobin
autostart=true
autorestart=true</pre>
</div>
<p>The 4 first entries are just boiler plate to get you started, you can copy
them verbatim.</p>
<p>The last one define one (you can have many) process supervisor should manage.</p>
<p>It means it will run the command:</p>
<div class="highlight-python"><pre>/path/to/zerobin/zerobin.py --port 80 --compressed-static</pre>
</div>
<p>In the directory, with the environnement and the user you defined.</p>
<p>This command will be ran as a daemon, in the background.</p>
<p><cite>autostart</cite> and <cite>autorestart</cite> just make it fire and forget: the site will always be
running, even it crashes temporarly or if you retart the machine.</p>
<p>The first time you run supervisor, pass it the configuration file:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">supervisord</span> <span class="o">-</span><span class="n">c</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">supervisor</span><span class="o">.</span><span class="n">ini</span>
</pre></div>
</div>
<p>Then you can manage the process by running:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">supervisorctl</span> <span class="o">-</span><span class="n">c</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">supervisor</span><span class="o">.</span><span class="n">ini</span>
</pre></div>
</div>
<p>It will start a shell from were you can start/stop/restart the service</p>
<p>You can read all errors that might occurs from /tmp/zerobin.log.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>If you installed zerobin in a virtualenv, you may set the command
to run directly from it:</p>
<div class="last highlight-python"><pre>command=/path/to/virtualenv/bin/zerobin --port 80 --compressed-static</pre>
</div>
</div>
</div> </div>
@ -63,10 +122,10 @@
<div class="sphinxsidebarwrapper"> <div class="sphinxsidebarwrapper">
<h4>Previous topic</h4> <h4>Previous topic</h4>
<p class="topless"><a href="nginx_install.html" <p class="topless"><a href="nginx_install.html"
title="previous chapter">Installing with Nginx</a></p> title="previous chapter">Nginx setup</a></p>
<h4>Next topic</h4> <h4>Next topic</h4>
<p class="topless"><a href="theming.html" <p class="topless"><a href="theming.html"
title="next chapter">&lt;no title&gt;</a></p> title="next chapter">Theming</a></p>
<h3>This Page</h3> <h3>This Page</h3>
<ul class="this-page-menu"> <ul class="this-page-menu">
<li><a href="../_sources/en/using_supervisor.txt" <li><a href="../_sources/en/using_supervisor.txt"
@ -96,10 +155,10 @@
<a href="../genindex.html" title="General Index" <a href="../genindex.html" title="General Index"
>index</a></li> >index</a></li>
<li class="right" > <li class="right" >
<a href="theming.html" title="&lt;no title&gt;" <a href="theming.html" title="Theming"
>next</a> |</li> >next</a> |</li>
<li class="right" > <li class="right" >
<a href="nginx_install.html" title="Installing with Nginx" <a href="nginx_install.html" title="Nginx setup"
>previous</a> |</li> >previous</a> |</li>
<li><a href="../index.html">0bin 0.1 documentation</a> &raquo;</li> <li><a href="../index.html">0bin 0.1 documentation</a> &raquo;</li>
</ul> </ul>

View File

@ -53,8 +53,7 @@
<div class="section" id="installation-avec-apache"> <div class="section" id="installation-avec-apache">
<h1>Installation avec Apache<a class="headerlink" href="#installation-avec-apache" title="Permalink to this headline"></a></h1> <h1>Installation avec Apache<a class="headerlink" href="#installation-avec-apache" title="Permalink to this headline"></a></h1>
<p>Apache est plus lent, plus lourd, et plus complexe à mettre en oeuvre que Nginx. <p>Apache est plus lourd que Nginx mais il est aussi beaucoup plus connu:</p>
Mais il est aussi beaucoup plus connu:</p>
<ul class="simple"> <ul class="simple">
<li>plus de gens pourront vous aider les fora;</li> <li>plus de gens pourront vous aider les fora;</li>
<li>votre hébergeur propose surement Apache;</li> <li>votre hébergeur propose surement Apache;</li>
@ -81,11 +80,64 @@ une norme d&#8217;interfaçage: WSGI.</p>
l&#8217;installation du modle Apache mod_wsgi. Si vous ne savez pas comment faire, l&#8217;installation du modle Apache mod_wsgi. Si vous ne savez pas comment faire,
ou si vous ne pouvez pas le faire (par exemple sur un hébergement mutualisé ou si vous ne pouvez pas le faire (par exemple sur un hébergement mutualisé
qui ne le propose pas), il vous faudra choisir l&#8217;installation CGI.</p> qui ne le propose pas), il vous faudra choisir l&#8217;installation CGI.</p>
<p>Premièrement, assurez-vous d&#8217;avoir mod_wsgi installé et chargé (en tant qu&#8217;admin):</p>
<div class="highlight-python"><pre>a2enmod wsgi</pre>
</div> </div>
<div class="section" id="mod-cgi"> <p>Ceci va activer mod_wsgi. Si cela ne marche pas, il faudra l&#8217;installer d&#8217;abord (
<h2>Mod_CGI<a class="headerlink" href="#mod-cgi" title="Permalink to this headline"></a></h2> sur ubuntu, le paquet est libapache2-mod-wsgi)</p>
<p>Cette installation est considérée comme relativement lente. Mais vous bénéficierez <p>Ensuite, il faut créer un fichier de configuration Apache, généralement dans
tout de même de la robustesse d&#8217;Apache</p> /etc/apache/sites-available/. Nommez le zerobin:</p>
<div class="highlight-python"><pre>&lt;VirtualHost *:80&gt;
ServerName www.votersiteweb.com
WSGIDaemonProcess zerobin user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias / /chemin/vers/zerobin/app.wsgi
&lt;Directory /chemin/vers/zerobin/&gt;
WSGIProcessGroup zerobin
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
&lt;/Directory&gt;
&lt;/VirtualHost&gt;</pre>
</div>
<p>Activez le site web (en tant qu&#8217;admin):</p>
<div class="highlight-python"><pre>a2ensite zerobin</pre>
</div>
<p>Et rechargez la configuration d&#8217;Apache (en tant qu&#8217;admin):</p>
<div class="highlight-python"><pre>service apache2 reload</pre>
</div>
<p>Vous aurez noté que l&#8217;on fait référence à un fichier nommé app.wsgi. C&#8217;est un
fichier Python qui créé l&#8217;application qu&#8217;Apache va utiliser pour lancer le
processus Python:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">sys</span>
<span class="c"># s&#39;assurer que le module zerobin est dans le PYTHON PATH et importable</span>
<span class="n">ZEROBIN_PARENT_DIR</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">__file__</span><span class="p">))</span>
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">ZEROBIN_PARENT_DIR</span><span class="p">)</span>
<span class="c"># créer le wsgi callable</span>
<span class="kn">from</span> <span class="nn">zerobin.routes</span> <span class="kn">import</span> <span class="n">get_app</span>
<span class="n">settings</span><span class="p">,</span> <span class="n">application</span> <span class="o">=</span> <span class="n">get_app</span><span class="p">(</span><span class="n">compressed_static</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
<p>Vous pouvez bien sûr créer le votre, puisque la fonction <cite>get_app</cite> et le seul
moyen de passer des paramètres à 0bin avec cette installation. Cela peut se
faire en créant un fichier de configuration et en le passant à la fonction:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">sys</span>
<span class="n">ZEROBIN_PARENT_DIR</span> <span class="o">=</span> <span class="s">&#39;/chemin/du/dossier/parent/de/zerobin&#39;</span>
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">ZEROBIN_PARENT_DIR</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">zerobin.routes</span> <span class="kn">import</span> <span class="n">get_app</span>
<span class="n">settings</span><span class="p">,</span> <span class="n">application</span> <span class="o">=</span> <span class="n">get_app</span><span class="p">(</span><span class="n">settings_file</span><span class="o">=</span><span class="s">&#39;/path/to/settings.py&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="cgi">
<h2>CGI<a class="headerlink" href="#cgi" title="Permalink to this headline"></a></h2>
<p>Vous pouvez aussi utiliser CGI, mais nous n&#8217;avons pas encore eu le temps de
couvrir cette partie. Contactez nous si vous avez besoin de l&#8217;utiliser.</p>
</div> </div>
</div> </div>
@ -99,7 +151,7 @@ tout de même de la robustesse d&#8217;Apache</p>
<ul> <ul>
<li><a class="reference internal" href="#">Installation avec Apache</a><ul> <li><a class="reference internal" href="#">Installation avec Apache</a><ul>
<li><a class="reference internal" href="#mod-wsgi">Mod_wsgi</a></li> <li><a class="reference internal" href="#mod-wsgi">Mod_wsgi</a></li>
<li><a class="reference internal" href="#mod-cgi">Mod_CGI</a></li> <li><a class="reference internal" href="#cgi">CGI</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@ -98,8 +98,50 @@ sans avoir à redémarer le serveur.</p>
nous ne couvrirons pas cette partie.</p> nous ne couvrirons pas cette partie.</p>
<p>Vous devez créer une fichier de configuration Nginx pour 0bin. Sous GNU/Linux, <p>Vous devez créer une fichier de configuration Nginx pour 0bin. Sous GNU/Linux,
on les mets en général dans /etc/nginx/conf.d/. Nommez le zerobin.conf.</p> on les mets en général dans /etc/nginx/conf.d/. Nommez le zerobin.conf.</p>
<p>Le fichier minimal pour faire tourner le site est:</p> <p>Le fichier de configuration minimal pour faire tourner le site est:</p>
<p>Mais on peut apporter plusieurs améliorations de performance:</p> <div class="highlight-python"><pre>server {
listen 80;
server_name www.votresiteweb.com;
location / {
proxy_pass http://127.0.0.1:8000;
}
}</pre>
</div>
<p><cite>proxy_pass</cite> transmet les requêtes aux processus Python. Bien entendu le
port doit correspondre à celui utilisé par 0bin.</p>
<p>On peut apporter plusieurs améliorations à l&#8217;expérience utilisateur:</p>
<div class="highlight-python"><pre>server {
listen 80;
server_name www.votresiteweb.com;
location /favicon.ico {
root /chemin/vers/zerobin/static/img;
}
location /static/ {
root /chemin/vers/zerobin;
gzip on;
gzip_http_version 1.0;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
# Disable gzip for certain browsers.
gzip_disable ~@~\MSIE [1-6].(?!.*SV1)~@~];
expires modified +90d;
}
location / {
proxy_pass http://zerobin_cherrypy;
}
}</pre>
</div>
<p>Nginx sert maintenant le favicon ainsi que les fichiers statiques,
on a ajouté une date d&#8217;expiration dans les en-têtes HTTP
et on s&#8217;assure que la compression gzip est utilisée pour les navigateurs
qui la supporte.</p>
</div> </div>
</div> </div>

View File

@ -26,7 +26,7 @@
<script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="0bin 0.1 documentation" href="../index.html" /> <link rel="top" title="0bin 0.1 documentation" href="../index.html" />
<link rel="next" title="&lt;no title&gt;" href="theming.html" /> <link rel="next" title="Personnaliser lapparence" href="theming.html" />
<link rel="prev" title="Installation avec Nginx" href="nginx_install.html" /> <link rel="prev" title="Installation avec Nginx" href="nginx_install.html" />
</head> </head>
<body> <body>
@ -37,7 +37,7 @@
<a href="../genindex.html" title="General Index" <a href="../genindex.html" title="General Index"
accesskey="I">index</a></li> accesskey="I">index</a></li>
<li class="right" > <li class="right" >
<a href="theming.html" title="&lt;no title&gt;" <a href="theming.html" title="Personnaliser lapparence"
accesskey="N">next</a> |</li> accesskey="N">next</a> |</li>
<li class="right" > <li class="right" >
<a href="nginx_install.html" title="Installation avec Nginx" <a href="nginx_install.html" title="Installation avec Nginx"
@ -53,6 +53,68 @@
<div class="section" id="utiliser-supervisor"> <div class="section" id="utiliser-supervisor">
<h1>Utiliser supervisor<a class="headerlink" href="#utiliser-supervisor" title="Permalink to this headline"></a></h1> <h1>Utiliser supervisor<a class="headerlink" href="#utiliser-supervisor" title="Permalink to this headline"></a></h1>
<p>Supervisor est un très bon moyen de gérer des processus Python. Nous n&#8217;allons
pas couvrir son installation (qui la plupart du temps se résume à
apt-get install supervisor ou pip install supervisor), mais voici un rapide
résumé de comment l&#8217;utiliser:</p>
<p>Créez un fichier de configuration nommé supervisor.ini:</p>
<div class="highlight-python"><pre>[unix_http_server]
file=/tmp/supervisor.sock;
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock;
[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
[supervisord]
logfile=/tmp/zerobin.log
logfile_maxbytes=50MB
logfile_backups=2
loglevel=trace
pidfile=/tmp/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200
user=zerobin
[program:zerobin]
command=/chemin/vers/zerobin/zerobin.py --port 80 --compressed-static
directory=/chemin/vers/zerobin/
environment=PYTHONPATH='/chemin/vers/zerobin/'
user=zerobin
autostart=true
autorestart=true</pre>
</div>
<p>Les 4 premières entrées sont juste de la configuration standard et vous pouvez
les copier telles qu&#8217;elles.</p>
<p>La dernière entrée définie un processus (il peut y en avoir plusieurs)
que supervisor doit gérer.</p>
<p>Cela veut dire qu&#8217;il va lancer la commande:</p>
<div class="highlight-python"><pre>/chemin/vers/zerobin/zerobin.py --port 80 --compressed-static</pre>
</div>
<p>Et ceci dans le dossier, avec l&#8217;environnement et l&#8217;utilisateur défini, le tout
en arrière plan en tant que daemon.</p>
<p><cite>autostart</cite> et <cite>autorestart</cite> permettent simplement de le lancer et de l&#8217;oublier:
supervisor redémarera le processus automatiquement en cas d&#8217;arrêt impromptu.</p>
<p>La première fois que vous lancez supervisor, passez lui le fichier de configuration:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">supervisord</span> <span class="o">-</span><span class="n">c</span> <span class="o">/</span><span class="n">chemin</span><span class="o">/</span><span class="n">vers</span><span class="o">/</span><span class="n">supervisor</span><span class="o">.</span><span class="n">ini</span>
</pre></div>
</div>
<p>Ensuite vous pouvez gérer les processus avec:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">supervisorctl</span> <span class="o">-</span><span class="n">c</span> <span class="o">/</span><span class="n">chemin</span><span class="o">/</span><span class="n">vers</span><span class="o">/</span><span class="n">supervisor</span><span class="o">.</span><span class="n">ini</span>
</pre></div>
</div>
<p>Cela va démarrer un shell depuis lequel vous pouvez faire un start/stop/restart
sur le service.</p>
<p>Toutes les erreurs seront logguées dans /tmp/zerobin.log.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>Si vous avez installé zerobin dans un virtualenv, vous devriez définir la
commande pour qu&#8217;elle s&#8217;éxécute depuis le virtualenv:</p>
<div class="last highlight-python"><pre>command=/chemin/vers/le/virtualenv/bin/zerobin --port 80 --compressed-static</pre>
</div>
</div>
</div> </div>
@ -66,7 +128,7 @@
title="previous chapter">Installation avec Nginx</a></p> title="previous chapter">Installation avec Nginx</a></p>
<h4>Next topic</h4> <h4>Next topic</h4>
<p class="topless"><a href="theming.html" <p class="topless"><a href="theming.html"
title="next chapter">&lt;no title&gt;</a></p> title="next chapter">Personnaliser l&#8217;apparence</a></p>
<h3>This Page</h3> <h3>This Page</h3>
<ul class="this-page-menu"> <ul class="this-page-menu">
<li><a href="../_sources/fr/using_supervisor.txt" <li><a href="../_sources/fr/using_supervisor.txt"
@ -96,7 +158,7 @@
<a href="../genindex.html" title="General Index" <a href="../genindex.html" title="General Index"
>index</a></li> >index</a></li>
<li class="right" > <li class="right" >
<a href="theming.html" title="&lt;no title&gt;" <a href="theming.html" title="Personnaliser lapparence"
>next</a> |</li> >next</a> |</li>
<li class="right" > <li class="right" >
<a href="nginx_install.html" title="Installation avec Nginx" <a href="nginx_install.html" title="Installation avec Nginx"

View File

@ -92,14 +92,6 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div>
<div class="section" id="indices-and-tables">
<h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline"></a></h1>
<ul class="simple">
<li><a class="reference internal" href="genindex.html"><em>Index</em></a></li>
<li><a class="reference internal" href="py-modindex.html"><em>Module Index</em></a></li>
<li><a class="reference internal" href="search.html"><em>Search Page</em></a></li>
</ul>
</div> </div>
@ -108,14 +100,6 @@
</div> </div>
<div class="sphinxsidebar"> <div class="sphinxsidebar">
<div class="sphinxsidebarwrapper"> <div class="sphinxsidebarwrapper">
<h3><a href="#">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">0bin&#8217;s documentation</a><ul>
</ul>
</li>
<li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
</ul>
<h4>Next topic</h4> <h4>Next topic</h4>
<p class="topless"><a href="en/intro.html" <p class="topless"><a href="en/intro.html"
title="next chapter">Introduction</a></p> title="next chapter">Introduction</a></p>

File diff suppressed because one or more lines are too long

View File

@ -2,8 +2,7 @@
Apache setup Apache setup
============= =============
Apache is slower, heavier and more complicated to setup than Nginx. But it's also Apache is heavier than Nginx. But it's also much more famous:
much more famous:
- more people will be able to help you on forums; - more people will be able to help you on forums;
- your hosting will most probably support Apache; - your hosting will most probably support Apache;
@ -33,7 +32,65 @@ the setup of the Apache module mod_wsgi. If you don't know how to do this, or
if you can't do it (E.G: your hosting won't let you), you need to go for if you can't do it (E.G: your hosting won't let you), you need to go for
the CGI setup. the CGI setup.
========== First, make sure you have mod_wsgi installed and enable by running (as admin)::
This setup is considered as slow, but you will still benefit from Apache a2enmod wsgi
robustness.
This enable mod_wsgi. It it doesn't, install it first (on ubuntu, the package
is libapache2-mod-wsgi).
Then create an Apache configuration file, usually in /etc/apache/sites-available/.
Name it zerobin::
<VirtualHost *:80>
ServerName www.yourwebsite.com
WSGIDaemonProcess zerobin user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias / /path/to/zerobin/app.wsgi
<Directory /path/to/zerobin/zerobin/>
WSGIProcessGroup zerobin
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Activate the website (as admin)::
a2ensite zerobin
And reload the apache configuration (as admin)::
service apache2 reload
You'll note that we refer to a file named app.wsgi. It's a Python file
creating the application Apache is going to use to start the Python process::
import os, sys
# make sure the zerobin module is in the PYTHON PATH and importable
ZEROBIN_PARENT_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, ZEROBIN_PARENT_DIR)
# create the wsgi callable
from zerobin.routes import get_app
settings, application = get_app(compressed_static=True)
You can of course create your own, as the `get_app` function is the only
way to pass settings to 0bin with this setup. You would do this by creating
a configuration file and passing it to the function::
import os, sys
ZEROBIN_PARENT_DIR = '/path/to/zerobin/parent/dir'
sys.path.insert(0, ZEROBIN_PARENT_DIR)
from zerobin.routes import get_app
settings, application = get_app(settings_file='/path/to/settings.py')
CGI
===
You can also run 0bin using CGI, but infortunaly we didn't have time to cover
it yet. Please contact us if you ever get the need to use it.

View File

@ -51,9 +51,51 @@ installing it.
Vous must create a Nginx configuration file for 0bin. On GNU/Linux, they usually Vous must create a Nginx configuration file for 0bin. On GNU/Linux, they usually
go into /etc/nginx/conf.d/. Name it zerobin.conf. go into /etc/nginx/conf.d/. Name it zerobin.conf.
The minimal file to run the site is: The minimal configuration file to run the site is::
But you can make some adjustement to get better perfomances: server {
listen 80;
server_name www.yourwebsite.com;
location / {
proxy_pass http://127.0.0.1:8000;
}
}
`proxy_pass` just passes the external request to the Python process.
The port much match the one used by the 0bin process of course.
You can make some adjustements to get a better user experience::
server {
listen 80;
server_name www.yourwebsite.com;
location /favicon.ico {
root /path/to/zerobin/static/img;
}
location /static/ {
root /path/to/zerobin;
gzip on;
gzip_http_version 1.0;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
# Disable gzip for certain browsers.
gzip_disable ~@~\MSIE [1-6].(?!.*SV1)~@~];
expires modified +90d;
}
location / {
proxy_pass http://zerobin_cherrypy;
}
}
This make Nginx serve the favicon and static files, set the expire HTTP headers
and make sure gzip compression is used with browsers that support it.

View File

@ -1,15 +1,3 @@
--host=STR
The host on which to listen for incomming request. Usually 127.0.0.1 to
listen locally or 0.0.0.0 to listen from the outside.
Default: 127.0.0.1
Setting file : HOST
============ ============
Options Options
============ ============

View File

@ -2,9 +2,9 @@
Theming Theming
======= =======
0bin comes a complete theming support, but for now it's not well ingrated. 0bin comes with a complete theming support, but for now it's not well integrated.
If you wish to create your own theme, you'll need to create template similar If you wish to create your own theme, you'll need to create templates similar
to the ones in zerobin/view, and add the path to the director containing them to the ones in zerobin/view, and add the path to the director containing them
to the settings file. to the settings file.

View File

@ -1,3 +1,72 @@
==================== =================
Using supervisor Using supervisor
==================== =================
Supervisor is a very nice way to manage you Python processes. We won't cover
the setup (which is just apt-get install supervisor or pip install supervisor
most of the time), but here is a quick overview on how to use it.
Create a configuration file named supervisor.ini::
[unix_http_server]
file=/tmp/supervisor.sock;
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock;
[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
[supervisord]
logfile=/tmp/zerobin.log
logfile_maxbytes=50MB
logfile_backups=2
loglevel=trace
pidfile=/tmp/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200
user=zerobin
[program:zerobin]
command=/path/to/zerobin/zerobin.py --port 80 --compressed-static
directory=/path/to/zerobin/
environment=PYTHONPATH='/path/to/zerobin/'
user=zerobin
autostart=true
autorestart=true
The 4 first entries are just boiler plate to get you started, you can copy
them verbatim.
The last one define one (you can have many) process supervisor should manage.
It means it will run the command::
/path/to/zerobin/zerobin.py --port 80 --compressed-static
In the directory, with the environnement and the user you defined.
This command will be ran as a daemon, in the background.
`autostart` and `autorestart` just make it fire and forget: the site will always be
running, even it crashes temporarly or if you retart the machine.
The first time you run supervisor, pass it the configuration file::
supervisord -c /path/to/supervisor.ini
Then you can manage the process by running::
supervisorctl -c /path/to/supervisor.ini
It will start a shell from were you can start/stop/restart the service
You can read all errors that might occurs from /tmp/zerobin.log.
.. Note::
If you installed zerobin in a virtualenv, you may set the command
to run directly from it::
command=/path/to/virtualenv/bin/zerobin --port 80 --compressed-static

View File

@ -2,8 +2,7 @@
Installation avec Apache Installation avec Apache
========================= =========================
Apache est plus lent, plus lourd, et plus complexe à mettre en oeuvre que Nginx. Apache est plus lourd que Nginx mais il est aussi beaucoup plus connu:
Mais il est aussi beaucoup plus connu:
- plus de gens pourront vous aider les fora; - plus de gens pourront vous aider les fora;
- votre hébergeur propose surement Apache; - votre hébergeur propose surement Apache;
@ -34,9 +33,67 @@ l'installation du modle Apache mod_wsgi. Si vous ne savez pas comment faire,
ou si vous ne pouvez pas le faire (par exemple sur un hébergement mutualisé ou si vous ne pouvez pas le faire (par exemple sur un hébergement mutualisé
qui ne le propose pas), il vous faudra choisir l'installation CGI. qui ne le propose pas), il vous faudra choisir l'installation CGI.
Premièrement, assurez-vous d'avoir mod_wsgi installé et chargé (en tant qu'admin)::
Mod_CGI a2enmod wsgi
==========
Ceci va activer mod_wsgi. Si cela ne marche pas, il faudra l'installer d'abord (
sur ubuntu, le paquet est libapache2-mod-wsgi)
Ensuite, il faut créer un fichier de configuration Apache, généralement dans
/etc/apache/sites-available/. Nommez le zerobin::
<VirtualHost *:80>
ServerName www.votersiteweb.com
WSGIDaemonProcess zerobin user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias / /chemin/vers/zerobin/app.wsgi
<Directory /chemin/vers/zerobin/>
WSGIProcessGroup zerobin
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Activez le site web (en tant qu'admin)::
a2ensite zerobin
Et rechargez la configuration d'Apache (en tant qu'admin)::
service apache2 reload
Vous aurez noté que l'on fait référence à un fichier nommé app.wsgi. C'est un
fichier Python qui créé l'application qu'Apache va utiliser pour lancer le
processus Python::
import os, sys
# s'assurer que le module zerobin est dans le PYTHON PATH et importable
ZEROBIN_PARENT_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, ZEROBIN_PARENT_DIR)
# créer le wsgi callable
from zerobin.routes import get_app
settings, application = get_app(compressed_static=True)
Vous pouvez bien sûr créer le votre, puisque la fonction `get_app` et le seul
moyen de passer des paramètres à 0bin avec cette installation. Cela peut se
faire en créant un fichier de configuration et en le passant à la fonction::
import os, sys
ZEROBIN_PARENT_DIR = '/chemin/du/dossier/parent/de/zerobin'
sys.path.insert(0, ZEROBIN_PARENT_DIR)
from zerobin.routes import get_app
settings, application = get_app(settings_file='/path/to/settings.py')
CGI
===
Vous pouvez aussi utiliser CGI, mais nous n'avons pas encore eu le temps de
couvrir cette partie. Contactez nous si vous avez besoin de l'utiliser.
Cette installation est considérée comme relativement lente. Mais vous bénéficierez
tout de même de la robustesse d'Apache

View File

@ -55,10 +55,53 @@ nous ne couvrirons pas cette partie.
Vous devez créer une fichier de configuration Nginx pour 0bin. Sous GNU/Linux, Vous devez créer une fichier de configuration Nginx pour 0bin. Sous GNU/Linux,
on les mets en général dans /etc/nginx/conf.d/. Nommez le zerobin.conf. on les mets en général dans /etc/nginx/conf.d/. Nommez le zerobin.conf.
Le fichier minimal pour faire tourner le site est: Le fichier de configuration minimal pour faire tourner le site est::
Mais on peut apporter plusieurs améliorations de performance:
server {
listen 80;
server_name www.votresiteweb.com;
location / {
proxy_pass http://127.0.0.1:8000;
}
}
`proxy_pass` transmet les requêtes aux processus Python. Bien entendu le
port doit correspondre à celui utilisé par 0bin.
On peut apporter plusieurs améliorations à l'expérience utilisateur::
server {
listen 80;
server_name www.votresiteweb.com;
location /favicon.ico {
root /chemin/vers/zerobin/static/img;
}
location /static/ {
root /chemin/vers/zerobin;
gzip on;
gzip_http_version 1.0;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
# Disable gzip for certain browsers.
gzip_disable ~@~\MSIE [1-6].(?!.*SV1)~@~];
expires modified +90d;
}
location / {
proxy_pass http://zerobin_cherrypy;
}
}
Nginx sert maintenant le favicon ainsi que les fichiers statiques,
on a ajouté une date d'expiration dans les en-têtes HTTP
et on s'assure que la compression gzip est utilisée pour les navigateurs
qui la supporte.

View File

@ -1,3 +1,75 @@
==================== ====================
Utiliser supervisor Utiliser supervisor
==================== ====================
Supervisor est un très bon moyen de gérer des processus Python. Nous n'allons
pas couvrir son installation (qui la plupart du temps se résume à
apt-get install supervisor ou pip install supervisor), mais voici un rapide
résumé de comment l'utiliser:
Créez un fichier de configuration nommé supervisor.ini::
[unix_http_server]
file=/tmp/supervisor.sock;
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock;
[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
[supervisord]
logfile=/tmp/zerobin.log
logfile_maxbytes=50MB
logfile_backups=2
loglevel=trace
pidfile=/tmp/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200
user=zerobin
[program:zerobin]
command=/chemin/vers/zerobin/zerobin.py --port 80 --compressed-static
directory=/chemin/vers/zerobin/
environment=PYTHONPATH='/chemin/vers/zerobin/'
user=zerobin
autostart=true
autorestart=true
Les 4 premières entrées sont juste de la configuration standard et vous pouvez
les copier telles qu'elles.
La dernière entrée définie un processus (il peut y en avoir plusieurs)
que supervisor doit gérer.
Cela veut dire qu'il va lancer la commande::
/chemin/vers/zerobin/zerobin.py --port 80 --compressed-static
Et ceci dans le dossier, avec l'environnement et l'utilisateur défini, le tout
en arrière plan en tant que daemon.
`autostart` et `autorestart` permettent simplement de le lancer et de l'oublier:
supervisor redémarera le processus automatiquement en cas d'arrêt impromptu.
La première fois que vous lancez supervisor, passez lui le fichier de configuration::
supervisord -c /chemin/vers/supervisor.ini
Ensuite vous pouvez gérer les processus avec::
supervisorctl -c /chemin/vers/supervisor.ini
Cela va démarrer un shell depuis lequel vous pouvez faire un start/stop/restart
sur le service.
Toutes les erreurs seront logguées dans /tmp/zerobin.log.
.. Note::
Si vous avez installé zerobin dans un virtualenv, vous devriez définir la
commande pour qu'elle s'éxécute depuis le virtualenv::
command=/chemin/vers/le/virtualenv/bin/zerobin --port 80 --compressed-static

View File

@ -27,12 +27,5 @@
+-------------------------+--------------------------------+ +-------------------------+--------------------------------+
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
.. _Signaler un bug: https://github.com/sametmax/0bin/issues .. _Signaler un bug: https://github.com/sametmax/0bin/issues
.. _Report a bug: <https://github.com/sametmax/0bin/issues> .. _Report a bug: <https://github.com/sametmax/0bin/issues>

10
zerobin/app.wsgi Normal file
View File

@ -0,0 +1,10 @@
import os, sys
# make sure the zerobin module is in the PYTHON PATH and importable
ZEROBIN_PARENT_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, ZEROBIN_PARENT_DIR)
# create the wsgi callable
from zerobin.routes import get_app
settings, application = get_app(compressed_static=True)

View File

@ -111,23 +111,14 @@ def server_static(filename):
return static_file(filename, root=settings.STATIC_FILES_ROOT) return static_file(filename, root=settings.STATIC_FILES_ROOT)
@clize.clize(coerce={'debug': bool, 'compressed_static': bool}) def get_app(debug=None, settings_file='', compressed_static=None):
def runserver(host='', port='', debug=None, user='', """
group='', settings_file='', compressed_static=None, version=False): Return a tuple (settings, app) configured using passed options and
a setting file.
if version: """
print '0bin V%s' % settings.VERSION
sys.exit(0)
# merge the settings
if settings_file: if settings_file:
settings.update_with_file(os.path.abspath(settings_file)) settings.update_with_file(os.path.abspath(settings_file))
settings.HOST = host or settings.HOST
settings.PORT = port or settings.PORT
settings.USER = user or settings.USER
settings.GROUP = group or settings.GROUP
if compressed_static is not None: if compressed_static is not None:
settings.COMPRESSED_STATIC_FILES = compressed_static settings.COMPRESSED_STATIC_FILES = compressed_static
@ -138,12 +129,32 @@ def runserver(host='', port='', debug=None, user='',
for d in reversed(settings.TEMPLATE_DIRS): for d in reversed(settings.TEMPLATE_DIRS):
bottle.TEMPLATE_PATH.insert(0, d) bottle.TEMPLATE_PATH.insert(0, d)
if settings.DEBUG:
bottle.debug(True)
return settings, app
@clize.clize(coerce={'debug': bool, 'compressed_static': bool})
def runserver(host='', port='', debug=None, user='',
group='', settings_file='', compressed_static=None, version=False):
settings, app = get_app(debug, settings_file, compressed_static)
if version:
print '0bin V%s' % settings.VERSION
sys.exit(0)
settings.HOST = host or settings.HOST
settings.PORT = port or settings.PORT
settings.USER = user or settings.USER
settings.GROUP = group or settings.GROUP
thread.start_new_thread(drop_privileges, (settings.USER, settings.GROUP)) thread.start_new_thread(drop_privileges, (settings.USER, settings.GROUP))
if settings.DEBUG: if settings.DEBUG:
bottle.debug(True) run(app, host=settings.HOST, port=settings.PORT, reloader=True,
run(app, host=settings.HOST, port=settings.PORT, reloader=True, server="cherrypy") server="cherrypy")
else: else:
run(app, host=settings.HOST, port=settings.PORT, server="cherrypy") run(app, host=settings.HOST, port=settings.PORT, server="cherrypy")