Database settings in Zine

written by data, on Oct 22, 2009 4:24:00 PM.

While browsing through the zine tickets looking for something to fix, I came across this ticket. Apparently, after a period of inactivity, the database connection was closed and zine did not notice. To gain some more visibility, I’ll post my comment on the bug here, too.

The error

The error reported was:

OperationalError: (OperationalError) server closed the connection
   unexpectedly
   This probably means the server terminated abnormally
   before or while processing the request.

It is not a bug

This is not a bug. This is intended behavior although maybe unexpected; as far as I know this is typical for MySQL. MySQL has a setting to close connections to the database which have been idle for a specified time. This might make sense to regain some of the resources which a buggy application might have forgotten about. But by default, SQLAlchemy does not expect this.

But it has a solution for it: pool_recycle. This setting sets a maximum time for each connection to reside in the connection pool. So with this, one can circumvent the timeout problem.

But how do we do this in zine?

Database Settings in Zine

In zine/database.py it says:

# alternative pool sizes / recycle settings and more.  These are
# interpreter wide and not from the config for the following reasons:
#
# - system administrators can set it independently from the webserver
#   configuration via SetEnv and friends.
# - this setting is deployment dependent should not affect a development
#   server for the same instance or a development shell

So the zine creators chose to not use a config option for this but rather an environment variable. Reasons see above.

So for setting database specific things, set the environment variables

  • ZINE_DATABASE_POOL_SIZE
  • ZINE_DATABASE_POOL_RECYCLE
  • ZINE_DATABASE_POOL_TIMEOUT

In the case of the problem mentioned, ZINE_DATABASE_POOL_RECYCLE is the appropriate action.

Howto get Zine up and running with Lighttpd

written by data, on Oct 21, 2009 1:04:00 AM.

First of: There is this official description on how to achieve this: Recipes on the Pocoo wiki

Goal

In this little post I will describe how to install zine, a nice wordpress like blog engine written in python. Also, we will not install the dependencies system wide but only for the user under which zine will run. Most people would probably deploy this using nginx or mod_wsgi, but as I already have lighttpd running for other things, why another program with a new syntax.

For this, we will write a small init script, although this is specific to gentoo but should not be hard on any other system.

Installing Zine

After you got zine from the zine page, unpack it to a location of your choosing.

This is straight from the INSTALL file:

Currently the installation of Zine is only possible on (mostly) posix systems like OS X, Solaris, BSD or Linux. Development of Zine works on other operating systems as well and future release may provide a deployment plan for Windows as well.

To install Zine on your system you have to configure and “make install” it:

$ ./configure –prefix=/usr && make install

Zine installs itself into `/usr/lib/zine` and `/usr/share/zine`. Please note that this does not install the dependencies.

Note to package maintainers: for staged installs use DESTDIR variable

The following example shows how to set up Zine for `mod_wsgi`.

  1. Create a new folder `/var/zine/yourblog` where `yourblog` is a name that make sense for you.
  2. Copy the `zine.fcgi` file from `/usr/share/zine/servers` into the newly created folder and open it with an editor.
  3. Modify the `INSTANCE_FOLDER` variable to point to the `yourblog` folder.

These are one to one the descriptions from the INSTALL file, except that we are copying the fcgi version, not wsgi. This is also where we start deviating. Please exchange the line

srv = WSGIServer(app)

with

srv = WSGIServer(app, bindAddress=('$socketdir/socket-zine'))

Please replace $socketdir with a directory of your choice. It needs to be accessible to lighttpd.

Now we need to create a virtualenv with all the needed software. Depending on your distribution you need to install setuptools and virtualenv, for Gentoo this is emerge -av virtualenv setuptools Go into the zine directory (the unpacked file). Execute scripts/setup-virtualenv <directory> giving a location of your choosing, in this example $env_dir. Next, create the init script:

#!/sbin/runscript
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

start() {
        echo -n "Starting Zine: "
        start-stop-daemon --start --env PYTHON_EGG_CACHE="/var/cache/python-egg" \
        --quiet --pidfile "$ZINE_PID" \
        --make-pidfile --background \
        --chuid lighttpd \
        --exec $PYTHON "$ZINE_FCGI"
        sleep 2

        if [ -f "$ZINE_PID" ] && ps h `cat "$ZINE_PID"` >/dev/null; then
                echo "success"
        else
                return 1
        fi

}

stop() {
        echo -n "Stopping Zine"
        start-stop-daemon --stop --quiet --pidfile "$ZINE_PID"
        echo "."

}

restart() {
        svc_stop
        sleep 2
        svc_start

}

As you can see, this script is fairly basic and most people should understand it, but I’ll explain a few parts: On my system, I always got the error message that the egg cache is not writable. So I chose another one as suggested by the zine recipes. The command that is executed is $PYTHON “$ZINE_FCGI”. Here it is important to choose the correct python bin, in our case this is $env_dir/bin/python. ZINE_FCGI is the zine.fcgi you copied earlier into /var/zine/yourblog. Also, I am running this in the context of lighttpd to circumvent some permission problems you might have with sockets, but it would be absolutely possible to get it running under a special user. To define the variables in gentoo one can use the “/etc/conf.d/zine” file with the following contents:

ZINE_FCGI=/var/zine/yourblog/zine.fcgi
PYTHON=$env_dir/bin/python
ZINE_PID=/var/run/zine.pid

Please replace the “$env_dir” with the location you chose.

Configuring Lighttpd

This should be the last step. In Lighttpd, all you have to do is paste the following section

$HTTP["host"] =~ "(^|[a-z]*\.)jonasfietz\.de$" {
        fastcgi.server = ("" =>
                ((
                        "socket" => "$socketdir/socket-zine",
                        "check-local" => "disable",

                ))
        )

Here, you again have to replace $socketdir correspondingly.

So now everything should work. Just remember to restart firefox. Also, in this setup zine has no automatic reloader which sometimes causes problems when changing files on the fly. If you do this, please just restart it with /etc/init.d/zine restart.

Using the Creole-Parser with Zine

written by data, on Oct 18, 2009 6:23:00 PM.

I do not know if others had the same problem, but to me it was not apparently obvious how to use the creole parser in zine to display source code.

Preconditions

To enable this, you have to activate both pygments and creole in your plugin section. Also, in current stable zine (0.1.2) you have to apply the patch I submitted in this ticket

Syntax

Looking in the help for zine tells you that the syntax is as following. As I was using a development version for which I never ran build-documentation, I found this out by reading code, but reading the help is easier. :)

<<sourcecode>> 
def hello_world():
  print('Hello World')
<</sourcecode>>

If you use <<sourcecode syntax="lang">> you get syntax highlighting for the defined language. So in this example with syntax="python"

def hello_world():
  print('Hello World')

More information on the syntax can be found: The additions in pythons creoleparser, the Creole 1.0 specification, or for reference in this (incomplete) quick cheatsheet

Switched to Zine

written by data, on Oct 18, 2009 1:43:00 AM.

I finally decided to switch blogging engines. I had my own little blogging engine written with pylons, but I got tired of reimplementing things that others had done already.

So now you are reading my first blog comment made with Zine, a blogging engine from the makers of Werkzeug. I liked what I saw, so I took the time to fit it into my "old" design and also created a little plugin to add some functionality that resembles a CMS.

I will clean up the code somewhat and then I will publish it. It is mainly a theme based on YAML plus some work to automatically show categories in the navigation and some changes to the widgets to fit into the design.

I also changed the design to allow for nested comments, so please use them.

Although I have been working on a new version of my blog, I just scrapped it, but that is what has been keeping me from really posting anything in a long time: "As soon as that feature is finished!" But I hope to better myself now.

Anyway, there is a load of features now available, such as an atom feed, tags, an overview over the latest comments and all the stuff a blog should have. Also some nicer features like feeds restricted by a tag.

But there is always more work. The finishing touches on the plugin, such as only showing months in the archive where something happened. Then the patches I have done to zine core, some of which I already submitted. And lastly some beautifications as there are still a few rough edges here and there. Suggestions are always welcome.

Political Posts

written by data, on Jun 2, 2009 2:09:00 PM.

I am a fairly political person. I read a lot of articles, trying to get background information. So why hasn’t there been a single entry about it so far? For one, I fear negative repercussions in my further life. Often, my positions change over time as I get more information.

I used to attribute that to changing moral values, and they might have had their part in it. But another point is certainly that once you find out more about a subject, positions tend to diffuse, they are not as clear as you thought before.

In this position, I found a really great article, which makes this case exactly: Perils of pop philosophy
Although Sanchez argues that with philosophy it is even harder to see that it’s not a real argument being made, because there are so many omissions, I think this is also often the case with political statements.

To take a current point: Does it make more sense to let Opel default or give Magna enough state funding to keep it up? How will it develop in the long run? I think many people can make assertions, but it is extremely hard to foresee what will come in a case like this, and thusly to make the right decision.

But slowly I am coming to the point where I think I have to speak out about some thinks. I will make some more posts about politics, where I think the case is pretty clear (to me), or rather where I feel comfortably educated. Those are especially the cases with privacy and internet background, where I often feel more educated about the subject than the ministers concerned with it. But what I will not do, although I have strong feelings about it, is argue about social politics, because I am simply missing the macro economic background. (Yet I am not promising :))

Merging PDFs

written by data, on Mar 3, 2009 5:36:00 PM.

In university, we often get the slides for our lectures. As I prefer reading large amounts of text on paper, I usually print them. But when there are a lot of files, it's quite a hassle. So to you ghostview users:

gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite 
-sOutputFile=out.pdf Input*
(This should be in one line)

Counter-Strike Source Plugin

written by data, on Jan 8, 2009 3:05:00 AM.

Finally I have managed to publish a little plugin I wrote for Counter-Strike Source. Although I have stopped playing a few years ago, I still work with Innovalan on the biggest lanparties in Germany.

There, i also administrate some CSS servers. As the other plugins for controlling the server got on my nerves (featuritis paired with blacklists for features…), I decided to write my own plugin. This was easier than I imagined. So now you can get it from my website.

While working on it, I also improved the compile script for SourceMod. See the bug (bugs.alliedmods.net) for details.

UML 64-Bit Root-FS

written by data, on Jan 3, 2009 5:41:00 PM.

I’ve lately gotten interested in the development of tux3, as you might be able to notice by the mercurial repository I have. Daniel posted a message describing how to setup a UML-environment for development, but I noticed that it did not work for 64 bit machines.

So that’s why I created my own. Get it.

Hiding channel passwords in irssi

written by data, on Dec 28, 2008 10:51:00 PM.

I love using irssi, but one thing that has bothered me for a while is the fact that it shows the password for the channels in the status line. As I was at the 25C3, which is not the best place to be too trusting with your passwords, I tried to find the right command, but only the friendly people in the #irssi channel were able to help.

In case you are having the same kind of problem, the command you are looking for is:

/set chanmode_expando_strip on

Comments with formencode, recaptcha and htmlfill

written by data, on Dec 11, 2008 5:36:00 AM.

Thanks to the automagic pylons provides, I was able to write my own custom validator for reCAPTCHA in very few lines. I might publish it later on.

I use formencode to validate the form with a simple *validate*-decorator pylons provides. For recaptcha, as said, I provided my own validator, and htmlfill refills the form fields if anything goes wrong.

But I ran into some problems deploying it to my public server. All I got from recaptcha was *verify-params-incorrect*. This was because my lighttpd is compiled with ipv6, and therefore it reports ipv4 addresses as ::ffff:xxx.xxx.xxx.xxx. This can be easily managed with

if remote_ip.begins_with("::ffff:"):
    remote_ip = remote_ip[7:]

Due to recaptcha seemingly not handling ipv6-addresses, I decided to give ipv6 users a free pass; they can post without filling out the captcha. Sadly there won't be that many as my provider does not support any ipv6-glue, but that's for another day.

Tag Cloud

Latest Posts
Archive
Latest Comments

as101: "Great article . Will definitely apply it to my blog.Thanks."

data: "If there are still people interested in this, I will work it over and publish ..."

Tobias Blaschke: "There also is a widget for Tosca Widgets that offers the functionality of ..."

Faried Nawaz: "Please consider publishing the recaptcha validator."

Jochen Kupperschmidt: "Hey :) That's why I wrote this post on how I did it, using a preprocessor. The ..."