Debian packages with a human face on the example of Zabbix 1.8

    I was forced to write this article by two things: firstly, there is a feeling that after articles such as “ we make a debian-package on our knees ”, most of the residents will be convinced that debian-packages were invented by perverts for perverts. Secondly, zabbix 1.8 was released - a wonderful monitoring system in which, judging by the news, they finally tackled the usability problems of the admin interface.

    What unites these two events is that zabbix 1.8 is not yet in the ubunt repositories, and compiling and installing something from the source on production servers is, of course, an unworthy gentleman's occupation. In general, there is reason to show how debian packages are made.

    So hehe, let's get started :)

    apt-get install dh-make devscripts cdbs libmysqlclient-dev libcurl4-gnutls-dev
    wget sunet.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/1.8/zabbix-1.8.tar.gz
    tar zxvf zabbix-1.8.tar.gz
    cd zabbix-1.8
    dh_make --createorig


    When asked by dh_make what type of package we want to create, we need to answer “b” (cdbs). As a result, a template package will be created, with a bunch of files in the debian directory for all occasions (we will delete most of it later).

    Creating packages is still a little bit of shamanism and magic. The fact is that programs that are simpler than zabbix can be finished packaging at this stage. Those. if you need to do only ./configure && make install to install the program, then everything is ready, you can assemble and install. Zabbix is ​​a slightly more complicated option, so there are a few more steps ahead:



    To begin with, open the debian / control file and specify ourselves as the creator of the package, and at the same time list the packages that should come to the server with the installation of zabbix. To do this, find the line 'Depends' and add the following to its end: “fping, adduser, apache2, php5, php5-mysql, php5-gd”.

    Usually, the configure script can be called without parameters and it will generate a viable config, but for zabbix this is not so - it needs to enable compilation of the server part and the agent with separate options. In our case, this is configured in the debian / rules file, add the following to its end:
    DEB_CONFIGURE_USER_FLAGS := --enable-server --with-mysql --with-libcurl


    The binaries will fall into the directories / usr / bin and / usr / sbin by themselves, and the php interface and config files must be set manually. The easiest and most visual way to do this is to create a debian / install file and describe everything in it something like this:
    frontends/php/* usr/share/zabbix/
    misc/conf/zabbix_server.conf etc/zabbix


    In addition, for normal operation, the zabbix also needs directories for storing log files and locks. Creating them is also simple - just list them in the debian / dirs file:
    /var/log/zabbix-server
    /var/run/zabbix-server


    Now it's up to the script. There is an init script in the zabbix sources (misc / init.d / debian / zabbix-server), but it won’t work without file processing. Therefore, it is better to replace it with a script from ubuntu ( from here ), which must be saved under the name debian / init (on the final system it will be called /etc/init.d/zabbix - magic).

    To configure logrotate, you just need to put the config in the right place:
    cat > debian/logrotate
    /var/log/zabbix-server/zabbix_server.log {
    daily
    rotate 7
    compress
    missingok
    notifempty
    create 0640 zabbix zabbix
    sharedscripts
    }
    ^D


    It is very convenient when the package with the web interface itself sets the apache config:
    mkdir misc/apache2-vhosts
    cat > misc/apache2-vhosts/zabbix

    ServerName zabbix.example.com
    ServerAdmin admin@example.com

    DocumentRoot /usr/share/zabbix

    CustomLog /var/log/apache2/zabbix_access.log combined
    ErrorLog /var/log/apache2/zabbix_error_log

    ^D
    echo "misc/apache2-vhosts/zabbix etc/apache2/sites-available" >> debian/install


    Not all. Someone has to create a zabbix user, register an init script in startup, and fix the rights. The easiest way to do this is in a postinstall script, for this you need to take its template:
    mv debian/postinst.ex debian/postinst
    vim debian/postinst


    And after the line 'configure)', but before ';;' write the following:
    # Создать пользователя
    useradd zabbix || echo "User zabbix was not added"

    # Установить права на рабочие директории
    chown zabbix:zabbix /var/log/zabbix-server /var/run/zabbix-server

    # В этой директории веб-интерфейс пытается сохранить свой конфиг-файл:
    chown www-data /usr/share/zabbix/conf
    chmod 775 /usr/share/zabbix/conf

    # Автозапуск сервера:
    update-rc.d zabbix-server defaults

    # Включить виртуалхост:
    a2ensite zabbix
    invoke-rc.d apache2 reload


    One detail remains: with the standard PHP settings, the Zabbix interface will not start, you need to edit max_execution_time and a few more parameters. If we were preparing a package for a home torrent download server, then, of course, it would be easier to fix php.ini directly. But it’s ideologically more correct to put these settings in a package too. You can do it this way:

    mkdir misc/php.conf
    cat > misc/php.conf/zabbix.ini
    post_max_size = 16M
    max_execution_time = 300
    mbstring.func_overload = 2
    ^D

    echo "misc/php.conf/zabbix.ini etc/php5/conf.d" >> debian/install


    Now you need to fix the default configs so that the paths to the logs and pid files that we need are indicated there.

    And, in general, that's all. You can build the package using the debuild command, install it using dpkg -iand apt-get install -f.

    I hope I was able to demonstrate that Debian, among other things, is a convenient and thoughtful environment for porting applications; creating a new package is quite an alternative to installing programs that are not in the repository, even if we are talking about one installation.

    If the topic is interesting, I can continue. This time, a lot was left behind the scenes - what are dehelper scripts, and CDBS, how to debug package dependencies, and why pbuilder is one of my favorite tools.

    PS If you have your own open-source project, then I can help with its packaging, please contact.

    PPS: Transfer this post to some thematic blog, please. Thanks for the karma! Moved myself :)

    UPD:: A slightly updated version of the article on my blog: alexey.sveshnikov.ru/blog/2010/03/29/zabbix-debianization .

    Also popular now: